Non linear fit extremely bad : what am I doing wrong ?
9 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Nassim Mhammedi
el 14 de Mzo. de 2024
Comentada: Nassim Mhammedi
el 15 de Mzo. de 2024
Hello everybody,
I've spent my evening trying to understand why the nonlinear fit was so bad with my data and I couldn't find why.
I tried many different options, like the 'fit' function, 'fminsearsh', the fitting curve tool, etc...
For some reasons, the fit is OK only if my starting points are close from the real coeff at 0.1% ...
What am I doing wrong ? 1.1 isn't THAT far from 1. (same problem without the constant 'a')
Thank you for your help,
close all
clear all
rng('default')
t = 0:0.02:10; x = t.*sin(2*pi*1*t) + 0.1*randn(1, length(t)); % x*sin(x) with noise
x = x'; t = t';
% fitting part
x0 = [0 1.1];
fitfun = fittype( @(a,b,x) a+x.*sin(2*pi*b*x) );
[fitted_curve,gof] = fit(t,x,fitfun,'StartPoint',x0)
0 comentarios
Respuesta aceptada
Matt J
el 14 de Mzo. de 2024
Editada: Matt J
el 15 de Mzo. de 2024
There are ways to derive an accurate x0 more systematically, e.g.,
rng('default')
t = 0:0.02:10; x = t.*sin(2*pi*1*t) + 0.1*randn(1, length(t)); % x*sin(x) with noise
x = x'; t = t';
%Coarse fit
a0=mean(x);
I=t>=1;
z=(x(I)-a0)./t(I); %Ideally, z would be purely sinusoidal
cfit=fit(t(I),z,'fourier1');
% Fine fit
x0 = [a0 cfit.w/2/pi];
fitfun = fittype( @(a,b,x) a+x.*sin(2*pi*b*x) );
[cfit,gof] = fit(t,x,fitfun,'StartPoint',x0),
plot(cfit,t,x)
Más respuestas (0)
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!