What's the default stopping criteria of of lsqcurvefit and How can I change it ?

6 views (last 30 days)
I'm trying to curvefit two sets of data (time, y1) and (time,y2) with shared parameters simultenously.
Both y1 and y2 are sum of 2 sine terms as shown below:
y1=a*sin(b*time+c)+d*sin(e*time+f)
y2=a*sin(b*time+c)+(d-1)*sin(e*time+f)
I followed this instruction (https://www.mathworks.com/matlabcentral/answers/419277-simultaneous-fitting-of-two-plots-with-two-functions) but got a problem: The curvefitting result is far from the original data. And no matter how I change the intitial condition, which is x0, the final point is always the initial point, whatever it is. Besides, I noticed that the output in the command window said "Optimization completed because the size of the gradient at the initial point
is less than the default value of the optimality tolerance." And if I click the <stopping criteria details>, it shows the first-order optimality measure is always 0 no matter what the initial condition is. So it won't help to set a smaller optimality tolerance.
Here are my questions:
  1. How the size of the gradient is calculated in my case or why it's always zero? I don't understand the equation in the Help file.
  2. How can I change the stopping criteria? Since I noticed there were some other stopping criteria, like the first examlple on this page: https://www.mathworks.com/help/optim/ug/lsqcurvefit.html#buuu2mv-1
Code:
xdata=[time(:,1) time(:,1)];
ydata=[Ipri1(:,1) Isec1(:,1)];
y = [x(1)*sin(x(2)*time+x(3))+x(4)*sin(x(5)*time+x(6)) x(1)*sin(x(2)*time+x(3))+(1-x(4))*sin(x(5)*time+x(6))];
fun=@(x,xdata)[y];
x0=[10 123800 -2.5 10 130000 3];
x = lsqcurvefit(fun,x0,xdata,ydata)
options = optimoptions('lsqcurvefit','MaxFunctionEvaluations',10000,'StepTolerance',1e-6);
plot(xdata,ydata,'o')
hold on
x = 1E5*[0.000100000000000 1.238000000000000 -0.000025000000000 -0.000010000000000 1.300000000000000 0.000030000000000];
xxdata = xdata;
yydata = [x(1)*sin(x(2)*time+x(3))+x(4)*sin(x(5)*time+x(6)) x(1)*sin(x(2)*time+x(3))+(1-x(4))*sin(x(5)*time+x(6))];
plot(xxdata,yydata,'-')
FYI, I input the curve fitting result to line10 manually after the curvefit is completed to plot curves.
Please find attached the data I used, time, Ipri1, and Isec1.
Thanks so much.

Answers (0)

Products


Release

R2017b

Community Treasure Hunt

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

Start Hunting!