Problem by star values lsqcurvefit
Mostrar comentarios más antiguos
xdata = ...
[0 0.005 0.01 0.015 0.02 0.025 0.03 0.035 0.04 0.045 0.05 0.055 0.06 0.065 0.07 0.075 0.08];
ydata = ...
[-0.7597 -1.5641 4.331 10.226 10.328 10.43 9.2075 7.9845 6.9538 5.9227 4.7857 3.6488 2.1603 0.67176 0.22867 -0.21442 -0.10787];
fun = @(x,xdata)x(1)+x(2).*sqrt(x(3)./(2.*pi.*(x(4).*(xdata+x(5))).^3)).*exp(-(x(3).*((x(4).*(xdata+x(5)))-x(6)).^2)/((xdata+x(5)).*2.*x(4).*x(6).^2));
x0 = [ -10, 20, 1, 12, 0.005, 1 ];
x = lsqcurvefit(fun,x0,xdata,ydata)
B = fminsearch(@(b)norm(ydata - fun(b,xdata)), x0)
options = optimoptions('lsqcurvefit','Algorithm','levenberg-marquardt','MaxIter', 10000);
lb = [];
ub = [];
times = linspace(xdata(1),xdata(end));
plot(xdata,ydata,'ko',times,fun(x,times),'b-')
legend('Data','Fitted exponential')
title('Data and Fitted Curve')
result is :

and with result from B = fminsearch(@(b)norm(ydata - fun(b,xdata)), x0) become i only worse result.
but by x0 = [ -10, 20, 1, 12, -0.1, 1 ] it should be already a good result, because
-10+20*sqrt(1/(2*pi*(12*(x+0.005))^3))*exp(-(1*((12*(x+0.005))-#2)^2)/((x+0.005)*24*2^2)) in Latex is already so:

why can i not use x0 = [ -10, 20, 1, 12, 0.005, 1 ] als start values, and how can i find a start values to fitting it?
Thank you very much first!
Respuesta aceptada
Más respuestas (1)
Alex Sha
el 22 de Oct. de 2019
Hi, Zuyu An, what's your exact data?
xdata = [0 0.005 0.01 0.015 0.02 0.025 0.03 0.035 0.04 0.045 0.05 0.055 0.06 0.065 0.07 0.075 0.08];
ydata = [-0.7597 -1.5641 4.331 10.226 10.328 10.43 9.2075 7.9845 6.9538 5.9227 4.7857 3.6488 2.1603 0.67176 0.22867 -0.21442 -0.10787];
or
xdata = [0.005 0.01 0.015 0.02 0.025 0.03 0.035 0.04 0.045 0.05 0.055 0.06 0.065 0.07 0.075 0.08];
ydata = [-1.5641 4.331 10.226 10.328 10.43 9.2075 7.9845 6.9538 5.9227 4.7857 3.6488 2.1603 0.67176 0.22867 -0.21442 -0.10787];
note the first one set data (0,-0.7579) is missed in the later.
Also, your function foumual below seems to be overfit, which lead to multiple solutions
fun = @(x,xdata)x(1)+x(2).*sqrt(x(3)./(2.*pi.*(x(4).*(xdata+x(5))).^3)).*exp(-(x(3).*((x(4).*(xdata+x(5)))-x(6)).^2)/((xdata+x(5)).*2.*x(4).*x(6).^2));
if the above function adjust to the follow by deleting "x(2)", there will be unique solution with same goodness of fit.
fun = @(x,xdata)x(1)+sqrt(x(3)./(2.*pi.*(x(4).*(xdata+x(5))).^3)).*exp(-(x(3).*((x(4).*(xdata+x(5)))-x(6)).^2)/((xdata+x(5)).*2.*x(4).*x(6).^2));
2 comentarios
Bjorn Gustavsson
el 22 de Oct. de 2019
This is the core of the problem. That the parameterization has the form
- that all points on the curve
have the same value often makes the optimization-functions to rumble around in the most peculiar paths in the parameter-space. The function-parameterization have another similar possible-problem:
is in my experience better to implement as
with different meaning of p(4) and p(5). Fixing the first should be the most important.
HTH
Zuyu An
el 22 de Oct. de 2019
Categorías
Más información sobre Get Started with Curve Fitting Toolbox en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

