Trouble Using lsqcurvefit on experimental data

조회 수: 4 (최근 30일)
Benjamin
Benjamin 2012년 8월 29일
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);

답변 (1개)

Matt Tearle
Matt Tearle 2012년 8월 29일
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);

카테고리

Help CenterFile Exchange에서 Least Squares에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by