Filter löschen
Filter löschen

lsqcurvefit passing parameters to function?

4 Ansichten (letzte 30 Tage)
Sam Butler
Sam Butler am 3 Jul. 2014
Bearbeitet: Matt J am 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?

Antworten (1)

Matt J
Matt J am 3 Jul. 2014
Bearbeitet: Matt J am 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, ....)

Kategorien

Mehr zu Linear and Nonlinear Regression finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by