using lsqcurvefit with normalized error

7 views (last 30 days)
Hello,
I am using lsqcurvefit to fit a data set . However, the data points (ydata) I have has a very wide range (10^-3 to 10^3). So, when the lsqcurvefit tries to minimize the squared error, it minimizes it for the initialdata points (of higher values of ydata) and then gives a bad fit as we move ahead (to lower values of ydata). I tried using fmincon instead of lsqcurvefit and wrote a function (similar to lsqcurevfit) to minimize the error. But I modified this function by normalizing each error with the data point so that each data point gets similar weightage (be of higher or lower magnitude). This way I get a good fit but then I cannot plot the 95% confidence interval. So i am going back to lsqcurvefit. Is there a way to use lsqcurvefit that can normalize the error at each data point and give better fit? or can I plot the 95% confidence interval with fmincon?

Accepted Answer

Matt J
Matt J on 11 Sep 2019
Edited: Matt J on 11 Sep 2019
This way I get a good fit but then I cannot plot the 95% confidence interval.
fmincon doesn't return the Jacobian, but it does return the Hessian, which you can use in a similar way to compute confidence intervals.
Is there a way to use lsqcurvefit that can normalize the error at each data point and give better fit?
Yes, if F(x,xdata) is your model function, then call lsqcurvefit as,
lsqcurvefit(@(x,xdata) F(x,xdata)./ydata, x0, xdata, ones(size(ydata)) );

More Answers (0)

Community Treasure Hunt

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

Start Hunting!