Borrar filtros
Borrar filtros

Nonlinear Least Squares implementation

2 visualizaciones (últimos 30 días)
Federico Maglione
Federico Maglione el 27 de En. de 2020
Comentada: Federico Maglione el 28 de En. de 2020
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

Respuesta aceptada

Matt J
Matt J el 27 de En. de 2020
Editada: Matt J el 27 de En. de 2020
[x,resnorm,res,eflag,output1] = lsqnonlin(@(x) myLS(F, S0, r, w, t, Q0, x) ,x0)

Más respuestas (0)

Categorías

Más información sobre Systems of Nonlinear Equations en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by