Matlab CFTool产生错误的系数 [英] Matlab cftool producing wrong coefficients

查看:177
本文介绍了Matlab CFTool产生错误的系数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有这个数据

x
1.0423
2.8249
3.2016
2.0851
1.0299
4.7397
0.4104
0.5285
0.7102
0.8323
3.1048
2.8685
0.2604
4.6560
3.6433
3.6892
0.3170
4.3022
4.6720
4.9220
y
    2.0529
   -3.0669
   -2.3631
   -0.7300
    1.4354
    2.0260
    0.5980
    0.5296
    1.3405
    1.7361
   -1.5876
   -2.7872
    1.0788
    1.3677
   -0.1355
   -1.5755
    0.7811
   -0.8328
   -0.0592
    2.0927

然后我尝试使用cftool将8阶多项式拟合到数据.

And I tried to fit an 8th order polynomial to the data using cftool.

这些是我得到的错误的结果

These are the results I get which are wrong

Linear model Poly8:
     f(x) = p1*x^8 + p2*x^7 + p3*x^6 + p4*x^5 + 
                    p5*x^4 + p6*x^3 + p7*x^2 + p8*x + p9
Coefficients (with 95% confidence bounds):
       p1 =    -0.05446  (-0.126, 0.01711)
       p2 =       1.088  (-0.3839, 2.561)
       p3 =      -8.762  (-21.23, 3.706)
       p4 =        36.2  (-19.89, 92.3)
       p5 =      -80.85  (-225.3, 63.62)
       p6 =       94.32  (-119.9, 308.6)
       p7 =      -52.21  (-227.5, 123.1)
       p8 =       12.21  (-59.01, 83.42)
       p9 =    -0.05814  (-10.72, 10.61)

Goodness of fit:
  SSE: 4.083
  R-square: 0.9225
  Adjusted R-square: 0.8661
  RMSE: 0.6092

这是适合的cftool图,看起来不错

This is a cftool plot of the fit which looks fine

这就是绘制系数的实际样子. >

and this is what plotting the coefficients actually looks like.

标绘系数的代码:

xx = 0:1/100:5;
yy = -0.05446*xx.^8 +1.088*xx.^7 -8.762*xx.^6 +36.2*xx.^5 -80.85*xx.^4 +94.32*xx.^3 -52.21*xx.^2 +12.21*xx -0.05814;
plot(xx,yy)

有人知道怎么回事以及如何获得cftool生成的图的正确系数吗?

Does anyone know whats going on and how to get the correct coefficients of the plot that cftool produces?

推荐答案

我怀疑通过截断系数,可以极大地改变多项式.

I suspect that by truncating the coefficients, you have changed the polynomial too much.

通过检查以下代码(当工作空间中已经有xy时),您可以自己看到效果.

You can see the effect yourself, by examining following code (when you already have x and y in your workspace).

P = polyfit(x,y,8); % fitted polynomial
P2 = [-0.05446 1.088 -8.762 36.2 -80.85 94.32 -52.21 12.21 -0.0814]; % your coefficients

toString = @(x,pat)(sprintf(pat,x));
fix = @(x,pat)(str2double(toString(x,pat)));

P3 = arrayfun(@(x)(fix(x,'%3.4f')), P); % artificially truncate the coefficients

X = linspace(min(x),max(x),100);
Y  = polyval(P ,X);
Y2 = polyval(P2,X);
Y3 = polyval(P3,X);

figure;
[x,i] = sort(x);
y = y(i);
plot(x,y ,'or'); hold on;
plot(X,Y ,'-b'); 
plot(X,Y2,'--g');
plot(X,Y3,'-c');
hold off;

我所做的是,将八阶多项式与您的数据拟合,我也人为地截断了系数(我不知道cftool的精确舍入策略,这似乎比我做的要复杂一些)

What I did, was fit the polynomial of eighth order to your data, I also truncated the coefficients artificially (I don't know the exact rounding strategy of cftool, it seems a bit more complicated than what I did).

在下图中,您可以看到结果.红点是数据,蓝线是polyfit(也可能是cftool)拟合的精确多项式.绿点虚线表示您的多项式具有截短的系数),青色线表示我的截断多项式.因此,您会发现通过截断,您对多项式的更改太大而无法使用.

In the figure below, you can see the outcome. The red dots are the data, the blue line is the exact polynomial as fitted with polyfit (and probably cftool as well). The dotted green line depicts your polynomial with truncated coefficients) and the cyan line shows my truncated polynomial. So you see that by truncating, you are changing the polynomial too much to be usable.

这篇关于Matlab CFTool产生错误的系数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆