Why do I get error, "Not enough input arguments"

Dear Group,
I am trying to estimate parameters from a non-linear model using lsqnonlin.
My function is
function F = myfun(x,y,X)
F = (y - (1 + x(1)*(x(2)/0.0025662))*X(:,1) - (1-x(1)^2)*(x(2)/x(3))*X(:,2) - x(4)*X(:,3))
end
y = is a column vector of 18026 observation
X is a matrix with 3 columns each with 18026 observations
x is my parameter matrix (I have four parameters - x(1), x(2), x(3), and x(4), to estimate.
x0 = [-0.06,0.6,0.006,0.85] are my initial values.
My parameters have upper and lower bounds:
lb = [-1,0,0,-1]
ub = [1,2,2,2]
Because I get different estimates when I use lsqnonlin as I change starting values, I wish to the multiple starting values feature of MATLAB to get a global minimum.
I am using this URL to write the code to feed multiple starting values: https://fr.mathworks.com/help/gads/multistart-using-lsqcurvefit-or-lsqnonlin.html
When I submit
problem = createOptimProblem('lsqnonlin','objective',myfun, 'xdata',X,'ydata',y, 'x0',x0,'lb',lb,'ub',ub);
I get the following error message:
Not enough input arguments.
Error in myfun (line 2)
F = (y - (1 + x(1)*(x(2)/0.0025662))*X(:,1) - (1-x(1)^2)*(x(2)/x(3))*X(:,2) - x(4)*X(:,3))
Can you kindly point out the error in my set up. Thanks!
best, Srinivasan Rangan

 採用された回答

Jan
Jan 2018 年 7 月 30 日
編集済み: Jan 2018 年 7 月 30 日

2 投票

| This is the problem
V
problem = createOptimProblem('lsqnonlin', 'objective', @myfun, ...
'xdata',X,'ydata',y, 'x0',x0,'lb',lb,'ub',ub);
Using myfun only calls this function without input arguments, while @myfun provides the function handle.

その他の回答 (2 件)

Walter Roberson
Walter Roberson 2018 年 7 月 30 日

0 投票

Parameterize your function.
https://www.mathworks.com/help/optim/ug/passing-extra-parameters.html
Also, lsqnonlin cannot be used with problem based optimization. crrateOptimProblem is for linear optimization and mixed integer linear optimization only.

2 件のコメント

Srinivasan Rangan
Srinivasan Rangan 2018 年 7 月 30 日
Thank you Walter. I applied Jan's suggestion and it works. When I type problem, I get
problem =
struct with fields:
objective: @myfun
x0: [-0.0700 0.0600 0.0060 0.8500]
lb: [-1 0 0 -1]
ub: [1 2 2 2]
solver: 'lsqnonlin'
options: [1×1 optim.options.Lsqnonlin]
Then when I type [xmulti,errormulti] = run(ms,problem,50)
My error message is:
Not enough input arguments.
Error in myfun (line 2) F = (y - (1 + x(1)*(x(2)/0.0025662))*X(:,1) - (1-x(1)^2)*(x(2)/x(3))*X(:,2) - x(4)*X(:,3))
Error in lsqnonlin (line 206) initVals.F = feval(funfcn{3},xCurrent,varargin{:});
Error in fmultistart
Error in MultiStart/run (line 260) fmultistart(problem,startPointSets,msoptions);
Caused by: Failure in initial objective function evaluation. LSQNONLIN cannot continue. Failure in call to the local solver with supplied problem structure.
Do you know, how I can submit multiple starting values to lsqnonlin?
Walter Roberson
Walter Roberson 2018 年 7 月 30 日
You do not appear to have followed my advice about parameterizing the function?

サインインしてコメントする。

Srinivasan Rangan
Srinivasan Rangan 2018 年 7 月 31 日

0 投票

Thanks Walter. I am a newbie to matlab. Unable to figure how to parametrize the function. Will post a new question, that might make it more clear.
best, Srini

製品

リリース

R2018a

質問済み:

2018 年 7 月 30 日

回答済み:

2018 年 7 月 31 日

Community Treasure Hunt

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

Start Hunting!

Translated by