y=[19.0,32.3,49.0,73.3,97.8];
fun1=inline('c(1)+c(2)*x.^2','c','x');
%擬合函數
c=lsqcurvefit(fun1,[0,0],x,y)
%求擬合系數
['y=',num2str(c(1)),'+',num2str(c(2)),'x^2']%擬合函數表達式
y1=c(1)+c(2)*x.^2;
%擬合函數表達式值
plot
(x,y,'b*',
x,
y1,'r-');%繪制x,y點與擬合函數,比較擬合程度
進行結果:
fun1
=
inline
function:
fun1(c,x)
=
c(1)+c(2)*x.^2
optimization
terminated:
first-order
optimality
less
than
options.tolfun,
and
no
negative/zero
curvature
detected
in
trust
region
model.
c
=
0.972578657321613
0.0500351242188565
ans
=
y=0.97258+0.050035x^2