Why do I get error, "Not enough input arguments"
7 views (last 30 days)
Show older comments
Srinivasan Rangan
on 30 Jul 2018
Answered: Srinivasan Rangan
on 31 Jul 2018
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
1 Comment
Jan
on 30 Jul 2018
I've formatted your code today. Please read http://www.mathworks.com/matlabcentral/answers/13205-tutorial-how-to-format-your-question-with-markup
Accepted Answer
More Answers (2)
Walter Roberson
on 30 Jul 2018
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 Comments
Walter Roberson
on 30 Jul 2018
You do not appear to have followed my advice about parameterizing the function?
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!