Why the nonlinear least square fitted curve is not a curve?
5 ビュー (過去 30 日間)
表示 古いコメント
Hello
Can anyone please tell me why the resulting fit is not a curve, though I have defined an exponential curve?
Thanks
Data=[0.928571429, 0;
0.012118074, 1.5;
-0.450001188, 3;
-0.316739249, 4.5;
0.394139277, 6;
0.094786629, 7.5;
-0.139747215, 9;
-0.225960048, 10.5;
0.092637089, 12;
-0.018817212, 13.5;
0.057294651, 15;
0.034956239, 16.5;
0.099005863, 18;
-0.097958625, 19.5]
t = Data(:,2);
y = Data(:,1);
plot(t,y,'ro')
title('Data points')
F=@(x,t)exp(-2*abs(t)/x(1));
x0 = [1.29];
[x,resnorm,~,exitflag,output] = lsqcurvefit(F,x0,t,y)
hold on
plot(t,F(x,t))
hold off
0 件のコメント
採用された回答
Star Strider
2023 年 5 月 31 日
Just for fun, I added a periodic function and a slope to the model —
Data=[0.928571429, 0;
0.012118074, 1.5;
-0.450001188, 3;
-0.316739249, 4.5;
0.394139277, 6;
0.094786629, 7.5;
-0.139747215, 9;
-0.225960048, 10.5;
0.092637089, 12;
-0.018817212, 13.5;
0.057294651, 15;
0.034956239, 16.5;
0.099005863, 18;
-0.097958625, 19.5]
t = Data(:,2);
y = Data(:,1);
plot(t,y,'ro')
title('Data points')
F=@(x,t)exp(x(1).*t) .* sin(2*pi*x(2).*t + x(3)) + x(4).*t + x(5);
% x0 = [1.29];
x0 = randn(5,1);
[x,resnorm,~,exitflag,output] = lsqcurvefit(F,x0,t,y)
hold on
plot(t,F(x,t))
hold off
.
6 件のコメント
Star Strider
2023 年 6 月 7 日
Data=[0.928571429, 0;
0.012118074, 1.5;
-0.450001188, 3;
-0.316739249, 4.5;
0.394139277, 6;
0.094786629, 7.5;
-0.139747215, 9;
-0.225960048, 10.5;
0.092637089, 12;
-0.018817212, 13.5;
0.057294651, 15;
0.034956239, 16.5;
0.099005863, 18;
-0.097958625, 19.5];
t = Data(:,2);
y = Data(:,1);
plot(t,y,'ro')
title('Data points')
F=@(b,t)exp(b(1).*t) .* sin(2*pi*b(2).*t + b(3)) + b(4).*t + b(5);
% x0 = [1.29];
x0 = randn(5,1);
[B,resnorm,~,exitflag,output] = lsqcurvefit(F,x0,t,y);
hold on
plot(t,F(B,t))
hold off
mdl = fitnlm(t, y, F, B)
fprintf('\nThe Adjusted R² Value = %.6f\n', mdl.Rsquared.Adjusted)
.
その他の回答 (2 件)
John D'Errico
2023 年 5 月 31 日
編集済み: John D'Errico
2023 年 5 月 31 日
Data=[0.928571429, 0;
0.012118074, 1.5;
-0.450001188, 3;
-0.316739249, 4.5;
0.394139277, 6;
0.094786629, 7.5;
-0.139747215, 9;
-0.225960048, 10.5;
0.092637089, 12;
-0.018817212, 13.5;
0.057294651, 15;
0.034956239, 16.5;
0.099005863, 18;
-0.097958625, 19.5]
t = Data(:,2);
y = Data(:,1);
plot(t,y,'ro')
title('Data points')
F=@(x,t)exp(-2*abs(t)/x(1));
x0 = [1.29];
[x,resnorm,~,exitflag,output] = lsqcurvefit(F,x0,t,y)
hold on
plot(t,F(x,t))
hold off
It IS a curve. It is just a curve shape that does not please you. But, given the obscenity that is this data, what do you expect? (I'm not insulting you. Just your data.) Should lsqcurvefit be able to make a silk purse from a rat's ear?
Essentially, the signal is just barely present to be able to fit that data. So lsqurvefit chose a solution with a rate constant that makes the curve go to zero almost immediately, as the best fit it could find. Your data is noisy, and your model just barely fits the data.
Finally, you plotted only a connect the dots curve between your data. plot does not know what the shape of that curve is BETWEEN the data points. It plots using straight line segments.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Get Started with Curve Fitting Toolbox についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!