Using lsqnonlin for multi-dimensional inputs and parameter spaces

3 views (last 30 days)
Sam Butler
Sam Butler on 20 Nov 2013
Edited: Matt J on 20 Nov 2013
I am having trouble understanding how to interface with the lsqnonlin Nonlinear Least Squares solver.
I know it takes as input a function with a single parameter (which could be a vector), and produces as output a function with a single parameter (which are the optimized parameters), but it is unclear to me how this specifies the whole problem. The way I think of the problem, there are various parameters to optimize, over a range of inputs sampled from the input space, but I see no way to set the range of the input space, or specify a multidimensional input space.
In my problem, the function I am attempting to optimize spans a 4-dimensional space (not including the parameters being optimized), and the parameters I am trying to optimize may extend a variable-dimensional space, depending on the functional form I am fitting to, which is decided prior to invoking lsqnonlin...for sake of example, assume they span a 3-dimensional space.
In the documentation, it says the function should take a single parameter entry, but it is unclear to me how that solves the entire problem...
Is that parameter: * Just the fit parameter space? (ie, 3x1 vector in my example above) -- in that case, how do I specify the different function values across different inputs for the same set of parameters? * Just the space the function lives in? (ie, a 4x1 vector for the various inputs) -- in that case, where do the parameter values belong? * The inputs plus the space the function lives in? (ie, a 7x1 vector for the fit parameters and the space the function lives in) -- in that case, how do I specify what values are parameters to optimize and what values are data to be sampled over?
Please help me understand how this function is used! Thank you!

Answers (1)

Matt J
Matt J on 20 Nov 2013
Edited: Matt J on 20 Nov 2013
I'm not sure which release of the documentation you're reading. Basically, the idea is this. If there are N unknown scalars that you are trying to solve for, your objective function should have the input syntax f(x) where x is a length-N vector, composed of the unknowns. It should NOT have the input syntax
where the different unknowns are passed as separate input arguments.
LSQNONLIN knows the number of unknowns N based on the length of your initial guess vector x0.
f(x) is meant to have vector-valued output and lsqnonlin will try to minimize norm(f(x))^2.
Finally, you can put simple bounds on your search space using the lb, ub input vectors mentioned in the documentation. If you need more complicated constraints on the search, e.g. nonlinear constraints, you would need to use FMINCON.



Community Treasure Hunt

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

Start Hunting!