using lsqcurvefit with normalized error

조회 수: 8 (최근 30일)
minu pilvankar
minu pilvankar 2019년 9월 11일
댓글: minu pilvankar 2019년 9월 11일
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?

채택된 답변

Matt J
Matt J 2019년 9월 11일
편집: Matt J 2019년 9월 11일
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)) );
  댓글 수: 1
minu pilvankar
minu pilvankar 2019년 9월 11일
Thank you Matt!! This was really helpful!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

Community Treasure Hunt

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

Start Hunting!

Translated by