Trouble Using lsqcurvefit on experimental data

4 vues (au cours des 30 derniers jours)
Benjamin
Benjamin le 29 Août 2012
I am trying to fit experimental data to a curve with a known shape, and all I get back is a curve of y=0 (traces the x-axis). I am not declaring upper and lower bounds, but my initial values are based on modeled data that should be very close to the values that the fit should return. Here is the message given in the command window when the fit function kicks out:
Optimization completed because the size of the gradient is less than the default value of the function tolerance.
Code is posted below. Thoughts?
function[] = fit_f_l_data();
%load up force length calibration data load f_l_data; length = f_l_data.max_l; force = f_l_data.max_force;
%anonymous force-length function f_l_fit_func = @(params,length)... params(5).*exp(-abs(((length./params(4)).^params(1) - 1)./params(2)).^params(3));
%initialilze formula coefficients params0 = [2.08 -2.89 -.75 10 30];
%calculate best fit coefficients paramsf = lsqcurvefit(f_l_fit_func,params0,length,force);
fit_curve = exp(-abs((length.^paramsf(1) - 1)./paramsf(2)).^paramsf(3));
plot(length,force,'g*','MarkerSize',8); hold on plot(length,fit_curve,'r--','LineWidth',2);

Réponses (1)

Matt Tearle
Matt Tearle le 29 Août 2012
You appear to be using two different definitions of the fitting function. The function you pass to lsqcurvefit is
f_l_fit_func = @(params,length) params(5).*exp(-abs(((length./params(4)).^params(1) - 1)./params(2)).^params(3));
But then you calculate your fitted curve with
fit_curve = exp(-abs((length.^paramsf(1) - 1)./paramsf(2)).^paramsf(3));
Why not use
fit_curve = f_l_fit_func(paramsf,length);

Catégories

En savoir plus sur Least Squares dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by