Can I implement lsqnonlin (or equivalent) in a way that handles NaNs?
8 views (last 30 days)
Show older comments
I am trying to solve a non-linear least squares problem using Matlab's optimisation tool lsqnonlin. Specifically, I am trying to minimise the residual between my model and the data. However, my data, and hence the output of my anonymous function I use as input to lsqnonlin contains NaNs; causing lsqnonlin to fall over.
"Objective function is returning undefined values at initial point. lsqnonlin cannot continue."
Is there a way in which I can implement lsqnonlin (or equivalent) that can handle NaNs?
I have looked into giving my NaN values a zero weight, but I don't know whether this would work in this case? I have also thought about including logic such that the lsqnonlin only applies to values of my anonymous function that are non-NaN, but this seems improper, and, I suspect, very slow.
What does the community recommend?
0 Comments
Accepted Answer
Matt J
on 31 Mar 2016
Edited: Matt J
on 31 Mar 2016
Specifically, I am trying to minimise the residual between my model and the data
Since your residual is of the form F(x,xdata)-ydata, it is better to use lsqcurvefit.
Remove the NaNs from your ydata before feeding it to lsqcurvefit. Write a model function F(x,xdata) that considers only the NaN-reduced ydata.
0 Comments
More Answers (0)
See Also
Categories
Find more on Systems of Nonlinear Equations 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!