lsqcurvefit does not work for very small parameter fitting
1 view (last 30 days)
Show older comments
I use lsqcurvefit to fit a very small parameter (smaller than 1e-15), but this function lsqcurvefit cannot work well, unless I give a very accurate initial (guess) value. Are there some solutions to fit a very small paremter? I put my example code in the following
clear
%% Data
xdata = [0.44;0.45;0.46;0.47;0.48;0.49;0.50;0.51;0.52;0.53;0.54;0.55;0.56;0.57;0.58;0.59;0.60;0.61;0.62;0.63];
ydata = [1.2e-09;1.7e-09;2.5e-09;3.7e-09;5.5e-09;8.1e-09;1.2e-08;1.8e-08;2.6e-08;3.8e-08;5.6e-08;8.3e-08;1.2e-07;1.8e-07;2.6e-07;3.9e-07;5.7e-07;8.4e-07;1.2e-06;1.8e-06];
x0_1 = 3e-17;
x0_2 = 5e-17;
%% Option
options = optimoptions(@lsqcurvefit, ...
'StepTolerance', 1e-150, ...
'MaxFunctionEvaluations', 2e3, ...
'MaxIterations', 2e3);
%% function
fun = @(p,xdata)p(1).*exp(xdata/0.026);
%% fit
coef1 = lsqcurvefit(fun,x0_1,xdata,ydata,0,1,options);
coef2 = lsqcurvefit(fun,x0_2,xdata,ydata,0,1,options);
%% Plot
figure
semilogy(xdata, ydata, 'o', 'DisplayName', 'data');hold on;
semilogy(xdata, fun(coef1,xdata), 'r-', 'DisplayName', 'fit with bad start');
semilogy(xdata, fun(coef2,xdata), 'b--', 'DisplayName','fit with good start');
legend('show')
![untitled.jpg](https://www.mathworks.com/matlabcentral/answers/uploaded_files/218619/untitled.jpeg)
From above plot, we can know that
- When start point x0 is good, the fitting result is good;
- however, the lsqcurvefit seems not to work, because the fiited results are always the same as initial point (coef1=x0_1,coef2=x0_2).
I have tried following solutions:
1. transform the form function to log. I would not like that, because the example function is the simplified function, the converting would be very hard; besides, I have at least 10 equations like it, if I can find a way to fit the original function, I would not like to transform them;
2. Set options of optimization, I have tried them like the above codes, but it does not help, maybe some other options to be set?
0 Comments
Answers (0)
See Also
Categories
Find more on Get Started with Curve Fitting Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!