Nonlinear Least Squares implementation

3 次查看(过去 30 天)
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