Why the nonlinear least square fitted curve is not a curve?
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Pooneh Shah Malekpoor
el 31 de Mayo de 2023
Comentada: Star Strider
el 7 de Jun. de 2023
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 comentarios
Respuesta aceptada
Star Strider
el 31 de Mayo de 2023
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 comentarios
Star Strider
el 7 de Jun. de 2023
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)
.
Más respuestas (2)
John D'Errico
el 31 de Mayo de 2023
Editada: John D'Errico
el 31 de Mayo de 2023
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 comentarios
Ver también
Categorías
Más información sobre Interpolation en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!