# Finding out what initial guesses the curve fitting toolbox made for curve fit

5 views (last 30 days)
Muhtadi Zahin on 20 Oct 2021
Commented: Muhtadi Zahin on 21 Oct 2021
Hi everyone, thank you for your time,
I am currently working on a code that inputs real-life indentation data to fit them through a curve fitting toolbox. The relevant code portion is as below:
f1 = fittype('a0+(a1-a0)*((0.491*exp(-0.908*sqrt((abs(a3)*x)/(C0^2))))+(0.509*exp(-1.679*sqrt((abs(a3)*x)/(C0^2)))))','problem','C0')
f = fit( Hx, Hy, f1, 'problem', C0, 'lower',[0,0,0])
As you can see, I have not specified starting conditions, because we work with different tissues that each have different local minima (which creates non-fits). So I am letting MatLab randomize the starting points ( coeffiecient a0,a1,a3) to get global minima.
I am currently using r2 comparison to choose the best results. What I am also interested is recording what initial values Matlab chose for a0,a1 and a3 for the better runs (higher r2) so that I can make separate codes for particular tissues with preset inital guesses.
Thank you all for your time.
##### 2 CommentsShowHide 1 older comment
Muhtadi Zahin on 20 Oct 2021
I'm working with different biological samples. My idea is that I make versions of the code with different initial values corresponding with different biological tissues, so that the results are out more quickly. Also because I do not think that one set of initial values will work for all sample results.
As for intial value and not final values, I just think that the variability in biological data makes it better if I know a valid range of "casting net" to work on. Basically, I want to have a record of the range of initial values that best "caught" a range of fit-curves, if I'm making any sense.

Matt J on 20 Oct 2021
Edited: Matt J on 21 Oct 2021
I don't think there's anyway to dig out the initial guess generated inside fit(), but why not just specify your own random start point(s)? I can't imagine there's any advantage to letting fit() do it internally.
Also, note that your problem can be reduced to a single unknown (a3) as below. You might be able to do a simple one-dimensional parameter sweep for an accurate initial guess a3_0.
fun=@(a3) mdl(a3,Hx,Hy,C0); %1D function of a3
a3=fminsearch( fun, a3_0); %a3_0 = initial guess of a3
[~,coeffs]=fun(a3);
a0=coeffs(1);
a1=sum(coeffs);
function [resnorm,coeffs]=mdl(a3,x,y,C0)
x=x(:); y=y(:);
z=((0.491*exp(-0.908*sqrt((abs(a3)*x)/(C0^2))))+(0.509*exp(-1.679*sqrt((abs(a3)*x)/(C0^2)))));
opts=optimoptions('lsqlin','Display','off');
[coeffs,resnorm]=lsqlin(z.^[0,1],y,-[1,1],0,[],[],[0,-inf],[],[],opts);
end
Muhtadi Zahin on 21 Oct 2021
Thanks much. I'll try and follow this to my understanding.

R2019a

### Community Treasure Hunt

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

Start Hunting!

Translated by