Nonlinear Least Squares implementation

조회 수: 3 (최근 30일)
Federico Maglione
Federico Maglione 2020년 1월 27일
댓글: Federico Maglione 2020년 1월 28일
Dear all,
I believe my problem is trivial but I do not know I to make it work. I would appreciate someone's help about it. If I define my function myLS like this
function G = myLS(x)
F = [10 30 30];
S0 = 32.2337;
r = 0;
w = 0;
t = [1 5 10];
Q0 = [0.9917 0.8226 0.8081];
fun1 = myequity(x(1), F, t, r, w, x(2)) - S0;
fun2 = myQ(x(1), F, t, r, w, x(2)) - Q0;
G = [fun1 fun2];
end
And then I use the non linear least square
[x,resnorm,res,eflag,output1] = lsqnonlin(@myLS,x0)
The programme finds correctly the values of x which solve the problem. However, I would like to have something like
function G = myLS(F, S0, r, w, t, Q0, x)
fun1 = myequity(x(1), F, t, r, w, x(2)) - S0;
fun2 = myQ(x(1), F, t, r, w, x(2)) - Q0;
G = [fun1 fun2];
end
and solve the same non linear least square problem. It does not work however and the following error appears
Not enough input arguments.
Error in myLS (line 5)
fun1 = myequity(x(1), F, t, r, w, x(2)) - S0;
Error in lsqnonlin (line 205)
initVals.F = feval(funfcn{3},xCurrent,varargin{:});
Caused by:
Failure in initial objective function evaluation. LSQNONLIN cannot continue.
What am I doing wrong?
Thank you very much for your help.
Best,
Federico

채택된 답변

Matt J
Matt J 2020년 1월 27일
편집: Matt J 2020년 1월 27일
[x,resnorm,res,eflag,output1] = lsqnonlin(@(x) myLS(F, S0, r, w, t, Q0, x) ,x0)

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by