matlab中fittype函数,fittype拟合函数
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)
但是從圖像上明顯可以看到,在中間部位凹下去的地方模擬精度很差,請問按照我自定義的函數進行擬合怎樣才能提高這個精度呢
unt.jpg
(23.46 KB, 下載次數: 0)
2020-8-11 18:04 上傳
總結
以上是生活随笔為你收集整理的matlab中fittype函数,fittype拟合函数的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【超详细教程】告别证书,图文并茂教你免签
- 下一篇: Traceview命令