Trouble Using lsqcurvefit on experimental data
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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);
0 Kommentare
Antworten (1)
Matt Tearle
am 29 Aug. 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);
0 Kommentare
Siehe auch
Kategorien
Mehr zu Least Squares finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!