I'm trying to fit a model to my data – I've attempted using the curve fitting tool and writing some code (see below) but both approaches are failing. The model I am trying to fit is: f(x)= a.*exp(-b./(x.^p)), where the only thing I know is that p falls between 0.25 and 0.5.
When I use the curve fitting tool, only a straight line appears at a value that is too far off to even be visible in the dispay (photo attached)
When I use the code, I get an error message popping up as below.
Can anyone explain what could be going wrong here?
t = set6a{1:end,1};
y = set6a{1:end,2};
plot(t,y,'ro')
title('Data points')
F=@(x,xdata) (x(1)*exp(-1*(x(2)./((xdata).^x(3)))));
x0 = [0.00000001 1 0.5];
[x,resnorm,~,exitflag,output] = lsqcurvefit(F,x0,t,y)
hold on
plot(t,F(x,t))
hold off
The error message I'm getting is this:
Error using snls (line 47)
Objective function is returning undefined values at initial point. lsqcurvefit cannot continue.
Error in lsqncommon (line 166)
snls(funfcn,xC,lb,ub,flags.verbosity,options,defaultopt,initVals.F,initVals.J,caller, …
Error in lsqcurvefit (line 257)
lsqncommon(funfcn,xCurrent,lb,ub,options,defaultopt,caller,…
Error in curvefittingpractice2 (line 44)
[x,resnorm,~,exitflag,output] = lsqcurvefit(F,x0,t,y)
Any thoughts on this would be really helpful!
Best Answer