搜索内容 搜索用户

7 麦片

050

4主题 0最佳答案
 fittype函数是基于最小二乘法进行数据拟合的吗？这个精度如何改进呢？我的原始数据如下： x=[1.57079632700000 1.43965228700000 1.30438927000000 1.20635412600000 1.11818009200000 1.04588855400000 0.979758029000000 0.921411672000000 0.839101944000000 0.765449050000000 0.688846549000000 0.573462832000000 0.456141800000000 0.349921062000000 0.251816104000000 0.153777470000000 0.0522726110000000 0 -0.0522726110000000 -0.153777470000000 -0.251816104000000 -0.349921062000000 -0.456141800000000 -0.573462832000000 -0.688846549000000 -0.765449050000000 -0.839101944000000 -0.921411672000000 -0.979758029000000 -1.04588855400000 -1.11818009200000 -1.20635412600000 -1.30438927000000 -1.43965228700000 -1.57079632700000]' y=[0 0.0466150000000000 0.148860000000000 0.257980000000000 0.376420000000000 0.502290000000000 0.626270000000000 0.729550000000000 0.821830000000000 0.880210000000000 0.927810000000000 0.974550000000000 0.993000000000000 0.992290000000000 0.974820000000000 0.950290000000000 0.922520000000000 0.914770000000000 0.922520000000000 0.950290000000000 0.974820000000000 0.992290000000000 0.993000000000000 0.974550000000000 0.927810000000000 0.880210000000000 0.821830000000000 0.729550000000000 0.626270000000000 0.502290000000000 0.376420000000000 0.257980000000000 0.148860000000000 0.0466150000000000 0]' 用fittype进行拟合，代码如下 syms t f=fittype('(c0+c1*t+c2*t^2+c3*t^3+c4*t^4)*cos(t)','independent','t','coefficients',{'c0','c1','c2','c3','c4'}); cfun=fit(x,y,f) %显示拟合函数，数据必须为列向量形式 xi=-pi/2:0.1*pi:pi/2; yi=cfun(xi); figure plot(xi,yi,'b-',x,y,'g*'); title('拟合函数图形'); 结果如下图所示 cfun =      General model:      cfun(t) = (c0+c1*t+c2*t^2+c3*t^3+c4*t^4)*cos(t)      Coefficients (with 95% confidence bounds):        c0 =      0.9474  (0.9274, 0.9674)        c1 =  -4.287e-09  (-0.04692, 0.04692)        c2 =      0.8196  (0.7295, 0.9098)        c3 =   3.162e-09  (-0.05159, 0.05159)        c4 =     -0.6442  (-0.713, -0.5754) 但是从图像上明显可以看到，在中间部位凹下去的地方模拟精度很差，请问按照我自定义的函数进行拟合怎样才能提高这个精度呢

7 麦片

050

4主题 0最佳答案
楼主| 发表于 2020-8-11 20:07:45 | 显示全部楼层
 有大神帮我用1stopt拟合一下吗？ //There are many test examples located in the folder: examples\ //Nonlinear regression: any No. of variables and parameters, any user-defined function Title "NLReg Demo - 1"; Parameter c0, c1, c2, c3, c4; Variable x, y; Function y=(c0+c1*x+c2*x^2+c3*x^3+c4*t^x)*cos(x); DataFile  如帖子所示

119 麦片

50500

0主题 21最佳答案
• 关注者： 5

 SSy =    4.1947 fx=b(1)*exp(-b(2)*(x-b(3)).^2)+b(1)*exp(-b(2)*(x-b(4)).^2)+b(5)*exp(-b(6)*abs(x).^b(7))+b(8); b =[0.8349690263  5.76253551  -0.7615596579  0.7615596583  0.8710482131  5.924354338  3.098565941  -0.01361906415] RSS =0.00129513627265 MSe =  4.9813e-05 R^2 = 0.99969

119 麦片

50500

0主题 21最佳答案
• 关注者： 5

 更简单些： SSy =  4.1947 fx=b(1)*exp(-b(2)*(x+b(3)).^2)+b(1)*exp(-b(2)*(x-b(3)).^2)+b(4)*exp(-b(5)*abs(x).^3)+b(6); b =[0.8450623348  5.543742266  0.7538064767  0.860487424  5.931659212  -0.01684273164] RSS = 0.00132271404221 MSe = 4.724e-05 R^2 =  0.99968

1269 麦片

5001500

0主题 270最佳答案
• 关注者： 176

 顾世梁 发表于 2020-8-12 08:24 SSy =    4.1947 fx=b(1)*exp(-b(2)*(x-b(3)).^2)+b(1)*exp(-b(2)*(x-b(4)).^2)+b(5)*exp(-b(6)*abs(x).^b( ... 下面结果更好些： Root of Mean Square Error (RMSE): 0.004428162222305 Sum of Squared Residual: 0.000686301723346721 Correlation Coef. (R): 0.999918190084617 R-Square: 0.999836386862096 Adjusted R-Square: 0.999826161040977 Determination Coef. (DC): 0.999836386862096 Parameter        Best Estimate ----------        ------------- b1        1.49055236434522 b2        2.93872451709244 b3        -0.464604839556958 b4        0.464604839562865 b5        -0.6197716572158 b6        3.77575398001888 b7        5.03111138156361 b8        -0.0418956462218434复制代码

 您需要登录后才可以回帖 登录 | 注册 本版积分规则 回帖后跳转到最后一页