matlab非线性拟合模型参数,求助大神
请教最小二乘法拟合函数参数,求大神指条门路
x=[300 400 500 600 800 1000 1500];
y=[11.46 14.02 16.43 18.66 22.54 25.57 30.03];
Y=a+b*x+c*x2+d*x3+e*x-2
我在用最小二乘发求解参数a,b,c,d,e时,出现以下问题,编的MATLAB代码如下:
函数代码:
function y=cpt(x)
t=[300 400 500 600 800 1000 1500];
c=[11.46 14.02 16.43 18.66 22.54 25.57 30.03];
y=c-x(1)-x(2)*t-x(3)*t^2-x(4)*t^3-x(5)*t^(-2)
end
运行程序
x0=[1000,1000,1000,1000,1000];
t=[300 400 500 600 800 1000 1500];
c=[11.46 14.02 16.43 18.66 22.54 25.57 30.03];
x=lsqnonlin('cpt',x0)
tt=300:100:1500;
yy=x(1)+x(2)*t+x(3)*t^2+x(4)*t^3+x(5)*t^(-2);
plot(tt,yy,t,c,'rp')
出现的错误代码:
错误使用 ^
输入必须为标量和方阵。
要按元素进行 POWER 计算,请改用 POWER (.^)。
出错 cpt (line 4)
y=c-x(1)-x(2)*t-x(3)*t^2-x(4)*t^3-x(5)*t^(-2)
出错 lsqnonlin (line 193)
initVals.F = feval(funfcn{3},xCurrent,varargin{:});
出错 shuju1 (line 4)
x=lsqnonlin('cpt',x0)
原因:
Failure in initial user-supplied objective function evaluation. LSQNONLIN cannot continue. 返回小木虫查看更多
Local minimum possible.
lsqcurvefit stopped because the final change in the sum of squares relative to
its initial value is less than the default value of the function tolerance.
<stopping criteria details>
B =
-586.1387 3.5133 -0.0021 0.0000 2.9879
resnorm =
1.7731e+03
residual =
-6.9822
15.4051
6.8571
-29.9881
21.9829
-7.5761
0.3389
exitflag =
3
楼上用Matlab计算的确实只是个局部最优解。1stOpt计算结果如下:
均方差(RMSE): 0.0078330579954843
残差平方和(SSE): 0.000429497582924343
相关系数(R): 0.999999177434812
相关系数之平方(R^2): 0.999998354870301
修正R平方(Adj. R^2): 0.999997532305451
确定系数(DC): 0.999998354870301
卡方系数(Chi-Square): 1.12485463825693E-5
F统计(F-Statistic): 303926.904726147
参数 最佳估算
---------- -------------
a 1.1102998554633
b 0.0368663600596133
c -1.38702823213528E-5
d 1.42454111101837E-9
e 45169.7890275904
====== 结果输出 ======
No. 实测值 y 计算值 y
1 11.46 11.4622316191741
2 14.02 14.0110805204198
3 16.43 16.4346560999194
4 18.66 18.669986771712
5 22.54 22.5263500616852
6 25.57 25.5760884937698
7 30.03 30.0296064333166
,
谢谢
谢谢