24小时热门版块排行榜    

查看: 1721  |  回复: 4
当前只显示满足指定条件的回帖,点击这里查看本话题的所有回帖

djtaidelu

新虫 (初入文坛)

[交流] 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.
回复此楼
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

djtaidelu

新虫 (初入文坛)

引用回帖:
3楼: Originally posted by dingd at 2017-05-08 22:53:38
楼上用Matlab计算的确实只是个局部最优解。1stOpt计算结果如下:


Function Y=a+b*x+c*x^2+d*x^3+e*x^(-2);
Data;
x=;
y=;


均方差(RMSE): 0.0078330579954843
残差平方和(SSE): 0.000429497582924343
...

谢谢
4楼2017-05-10 12:07:22
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
查看全部 5 个回答

chendequan

铁虫 (小有名气)


小木虫: 金币+0.5, 给个红包,谢谢回帖
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
QQ:516477448,真心帮助解决MATLAB相关问题,提供详细资料,Word文档明确具体问题及要求,尽力而为!
2楼2017-05-08 20:48:26
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

dingd

铁杆木虫 (职业作家)


小木虫: 金币+0.5, 给个红包,谢谢回帖
楼上用Matlab计算的确实只是个局部最优解。1stOpt计算结果如下:
CODE:
Function Y=a+b*x+c*x^2+d*x^3+e*x^(-2);
Data;
x=[300 400 500 600 800 1000 1500];
y=[11.46  14.02  16.43  18.66  22.54  25.57  30.03];

均方差(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
3楼2017-05-08 22:53:38
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

djtaidelu

新虫 (初入文坛)

引用回帖:
2楼: Originally posted by chendequan at 2017-05-08 20:48:26
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 ...

谢谢
5楼2017-05-10 12:08:26
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
普通表情 高级回复 (可上传附件)
信息提示
请填处理意见