怎样用最小二乘法求y=a+bx^2

如题所述

例:x=[19,25,31,38,44];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
温馨提示:内容为网友见解,仅供参考
无其他回答
相似回答