Having 2 vectors vec_x and vec_y, i perform a fitting with a non-linear least squares like this :
%%myfunction.m
function F = myfun(x,vec_x)
F = 10*(erfc((x(1)+x(2)*vec_x)/sqrt(2))/2);
end
%%console
options = optimoptions('lsqcurvefit','Algorithm','levenberg-marquardt');
x = lsqcurvefit(@myfun, [0 1], vec_x, vec_y,[],[],options); %here i obtain x(1) and x(2).
When i want to plot the fitting curve with the associated points(vec_x .vs vec_y), i perform it like this :
y_fit=10*erfc((x(1)+x(2)*vec_x)/sqrt(2))/2
plot(vec_x,y_fit)
The problem is that i have a weird curve not similar to the one i have automatically when i'm using the "Curv-fit App" tool of Matlab (i use the same custom function and vectors as the console).
In the Curve-fitting GUI, i got this : see the image below snapshot-curveFitting-GUI
How can i have the right plot so i can more mange the plot ?
y_fit
affect the plot? – TroyHaskinlsqcurvefit
passesvec_x
tomyfun
as the second argument. – TroyHaskinlsqcurvefit
function uses the same algorithm aslsqnonlin
.lsqcurvefit
simply provides a convenient interface for data-fitting problems." – TroyHaskin