Nonlinear Least Squares implementation

4 vues (au cours des 30 derniers jours)
Federico Maglione
Federico Maglione le 27 Jan 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

Réponse acceptée

Matt J
Matt J le 27 Jan 2020
Modifié(e) : Matt J le 27 Jan 2020
[x,resnorm,res,eflag,output1] = lsqnonlin(@(x) myLS(F, S0, r, w, t, Q0, x) ,x0)

Plus de réponses (0)

Catégories

En savoir plus sur Systems of Nonlinear Equations dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by