It helps if you read your own code. :) Yes, I know things like this are sometimes not obvious.
Here is the block that matters.
F1 = @(p1,x) (p1(1) + p1(2)*(x*x));
x0 = [0 0];
[p1,resnorm] = lsqcurvefit(F, x0, x, y);
Note that you define a function F1, but then call lsqcurvefit with F.
What are the odds that MATLAB will know that you meant differently? Yes, computers are smart, but they do tend to do what you tell them.
Ok, having said that, you should consider that your exponential model does not have a unique solution.
F = @(p,x) p(1)*exp(p(2)*(x+p(3)));
See that if you have ANY solution for [p(1),p(2),p(3)], then there are infinitely many alternative solutions that are equally good. They are all equivalent.
Your three parameter exponential model is actually over-parameterized. Effectively, this means that you will find a solution, but that solution will be completely dependent on your starting values.
So if [p(1),p(2),p(3)] is one solution, then consider that
[p(1)*exp(p(2)*p(3) , p(2) , 0]
is another solution. There are infinitely many other sets of equally good parameters you can find. We can always convert any x-translation for an exponential into a scale factor on the outside of the exponential due to this basic identity for exponentials:
So really, you can do no better than to write the model as a TWO parameter model.
F = @(p,x) p(1)*exp(p(2)*x));
Best Answer