필터 지우기
필터 지우기

lsqcurvefit passing parameters to function?

조회 수: 4 (최근 30일)
Sam Butler
Sam Butler 2014년 7월 3일
편집: Matt J 2014년 7월 3일
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?

답변 (1개)

Matt J
Matt J 2014년 7월 3일
편집: Matt J 2014년 7월 3일
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, ....)

카테고리

Help CenterFile Exchange에서 Linear and Nonlinear Regression에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by