Incorrect curve fitting with lsqcurvefit
Show older comments
Hello everybody,
I think I'm having a problem with lsqcurvefit. Maybe it's from me, I don't know.
So, I have a set of data [x_data,y_data] that I want to fit with a function F(A,x) where A contains six free parameters. I define the anonymous function F=@(A,x) A(3)+A(4)*(x-A(5))+(1-int_sinc(A(6)*abs(A(5)-x))).*(A(1)*sign(x-A(5))-(1-A(2))*int_sinc(A(6)*abs(A(5)-x))) where int_sinc(x) is a function that calculate the integral of sin(t)/t from 0 to x. I also define lb and ub as the lower and upper bound for my parameters and A0 the initial values of my free parameters.
I run A=lsqcurvefit(F,A0,x_data,y_data,lb,ub) and once it's done, I plot F(A,x) and y_data on the same graph. And that's where I see that my fit and my datas do not correspond ... I can see a slight likeness but that's all. Furthermore, I remarked that the fit was really "initial condition sensitive" and the first two parameters seems to stay as they are in A0 ...


So I wanted to know where the "error", if there is one, can come from or if I just didn't understand the principle of lsqcurvefit.
I wish my english is comprehensible, and I thank you if reach that point ;)
Pierre
Accepted Answer
More Answers (2)
You could try fminspleas ( Download ) which should work well for your problem since your F has a linear dependence on four out of the six A(i) parameters. Also, fminspleas doesn't strictly care if F is differentiable, see also my Comment here, although I would have more peace of mind regardless if the fit were restricted to a portion of the curve which is differentiable in "A".
shariq khan
on 18 Nov 2018
Edited: shariq khan
on 18 Nov 2018
0 votes
First and foremost
- Make sure your scale of x and y axis is same for example if your x axis is x10^-3 and y axis is x10-1, there are high possibilities that your curve does not fit
- secondly, if your curve pattern is recurring after certain time, try taking only one part of it for example in case of exponential - take either positive edge or negative edge and compute curve fit
But I think I am quite early on this discussion :P
Categories
Find more on Get Started with Curve Fitting Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!