lsqcurvefit passing parameters to function?

3 views (last 30 days)
Sam Butler
Sam Butler on 3 Jul 2014
Edited: Matt J on 3 Jul 2014
I have a question on using lsqcurvefit. I have built up a MatLab object that has (among other supporting functions) two key functions that would be used in a curve fitting routine:
(1) getValue: returns the value of a function for a given 4-dimensional vector input
(2) setParameters: sets the parameters that are to be optimized by lsqcurvefit (in the simplest case, this is a 3-dimensional vector; ie, there are 3 parameters)
Reading the documentation, it is pretty clear to me that getValue is the function handle to pass in as "F", but it is not clear to me how the next set of parameters to try are passed from lsqcurvefit to my object to have its parameters updated.
Could someone help me understand how the parameters are passed from lsqcurvefit to the function?

Answers (1)

Matt J
Matt J on 3 Jul 2014
Edited: Matt J on 3 Jul 2014
it is not clear to me how the next set of parameters to try are passed from lsqcurvefit to my object to have its parameters updated.
Your F() function is supposed to have an input syntax looking like
function value = F(x,xdata)
That means lsqcurvefit is free to call it with different parameter vector guesses x as input arguments and test their value.
If your objective function is a non-static object method with calling syntax
value = obj.getValue(x,xdata)
then once you've created an instance obj, you can wrap it in an anonymous function as follows
F=@(x,xdata) obj.getValue(x,xdata);
lsqcurvefit(F , x0, ....)

Products

Community Treasure Hunt

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

Start Hunting!