作业帮 > 综合 > 作业

matlab 最小二乘拟合问题

来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/07/14 05:53:28
matlab 最小二乘拟合问题
function f=fun(x,t);
f = x(1)*(x(3)/x(2))^(2*x(2))*(x(2)-1)^(2*x(2)-2)/205000/(2*x(2)+1)/(t^2*(426/680)^2-426^2)/t^(2*x(2)-2)
t=[819.4 795.6 788.8 782.0 776.56 763.64 748.28 724.42 717.40 711.28 707.20];
>> y=[5.3*10^4 7.8*10^4 9*10^4 9.5*10^4 10^5 1.2*10^5 1.37*10^5 2*10^5 2.06*10^5 2.2*10^5 2.45*10^5];
>> x0=[1,1,1];
>> x=lsqcurvefit(@fun,x0,t,y)
提示的错误是:
Error using ==> mpowerMatrix must be square.
Error in ==> fun at 2
f =
x(1)*(x(3)/x(2))^(2*x(2))*(x(2)-1)^(2*x(2)-2)/205000/(2*x(2)+1)/(t^2*(426/680)^2-426^2)/t^(2*x(2)-2)
Error in ==> lsqcurvefit at 209 initVals.F = feval(funfcn_x_xdata{3},xCurrent,XDATA,varargin{:});
Caused by:
Failure in initial user-supplied objective function evaluation.LSQCURVEFIT cannot continue.
原式子如下 要求根据t和y的一组数据拟合出A B C:

f = x(1)*(x(3)/x(2))^(2*x(2))*(x(2)-1)^(2*x(2)-2)/205000/(2*x(2)+1)/(t^2*(426/680)^2-426^2)/t^(2*x(2)-2)
改成
f = x(1)*(x(3)/x(2))^(2*x(2))*(x(2)-1)^(2*x(2)-2)/205000/(2*x(2)+1)./(t^2*(426/680)^2-426^2)./t^(2*x(2)-2)
注意涉及到横轴拟合数据(即你这个问题中的t)的乘、除、乘方运算都应该使用点运算.

运行结果如下:
Optimization terminated successfully: First-order optimality less than OPTIONS.TolFun, and no negative/zero curvature detected
x =
1 1 1