lsqcurvefit does not follow convergence criteria in summation.

조회 수: 3 (최근 30일)
Chris Pruefert
Chris Pruefert 2023년 5월 27일
댓글: Torsten 2023년 5월 30일
I have a function that uses summation to fit an bi-exponential function. Because I have to retrieve other information from that fit, I cannot use the exp2-fit function unfortunately. As for the procedure over the 8 parts (n=8). The data is in t(xdata) and S(ydata). For each of the terms 1-8 the individual contribution (yfit_n) is calculated and then added up together to get the final results for the fit (yfit). The fucntion has 7 variables for the fitting in the vector x or x0 for the respective startin point (x(2) is not used at this stage).
FS_1=0.05;
FS_2=2.0264;
d=1E-4;
dy=1E-5;
n=1:8;
t=t_S_mathworks(:,1);
S=t_S_mathworks(:,2);
x0=rand(7,1);
fun=@(x,t) x(1)+x(3).*(FS_1+FS_2*sum(((-1.^n)./n.^2).*(1-cos(n*pi*dy/d))...
.*(x(4).*exp(-x(6)*(t).*n.^2.*pi^2./d^2)...
+x(5).*exp(-x(7)*(t).*n.^2.*pi^2./d^2)),2));
options.OptimalityTolerance = 1e-15;
[x,resnorm]=lsqcurvefit(fun,x0,t,S);
Because I got the flag that indicates that the convergence criterion is too low I wanted to change, but it was incorporated in the fit-options, I think.
After the fit has converged (but not giving a useful result) I checked for the convergence criterion and it wasn't replaced with the new one of 1E-15.
Optimization completed: The first-order optimality measure, 1.132517e-08,
is less than options.OptimalityTolerance = 1.000000e-06.
And when I check for the fit using
S_fitted =x(1)+x(3).*(FS_1+FS_2*sum(((-1.^n)./n.^2).*(1-cos(n*pi*dy/d))...
.*(x(4).*exp(-x(6)*(t).*n.^2.*pi^2./d^2)...
+x(5).*exp(-x(7)*(t).*n.^2.*pi^2./d^2)),2));
plot(t,S_fitted)
I see that only the first two data points gave a result other than the minium of data points. So it seems that the fitting itself did not happen. I inlcued the data to let you see of that error is reproducable. I hope that it is just a bening error I cannot seem locate right now.
All help is appreciated.
All the best,
Chris
  댓글 수: 3
Chris Pruefert
Chris Pruefert 2023년 5월 29일
Hi Alex,
thank you for your post. I can't seem to achieve these outputs. Are you using the code exactly as I posted it above, or did you make changes to it? I am aware of the co-dependece of the fitting values, I have to contrain a few of these to make physical sense.
What comand did you use to get the fitting parameters as you show it here?
All the best,
Chris
Torsten
Torsten 2023년 5월 30일
@Alex Sha has his own software - usually with extraordinary good results for fitting problems.

댓글을 달려면 로그인하십시오.

채택된 답변

Matt J
Matt J 2023년 5월 27일
After the fit has converged (but not giving a useful result) I checked for the convergence criterion and it wasn't replaced with the new one of 1E-15.
Because you have not passed the options variable to lsqcurvefit
options.OptimalityTolerance = 1e-15;
[x,resnorm]=lsqcurvefit(fun,x0,t,S,[],[],options);
  댓글 수: 7
Matt J
Matt J 2023년 5월 30일
편집: Matt J 2023년 5월 30일
I imagine it is because you are using a random initial guess, x0. If you initialize with Alex's solution, or values close to it, I would bet that you will get a more reasonable looking fit.
In any case, it is unrelated to your posted question. Your question was why the optimization was not obeying your options settings, and that has been solved.
Chris Pruefert
Chris Pruefert 2023년 5월 30일
That is correct. Thank you.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Get Started with Curve Fitting Toolbox에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by