not enough input arguments error using fminunc
24 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Han Kyul Yoo
le 20 Août 2016
Commenté : Han Kyul Yoo
le 25 Août 2016
while using fminunc with a function file, I keep running into the error "not enough input arguments". I want to minimize my objective function with respect to three parameters, which I represented with the vector 'm'
my minimization code:
x0 = [0.2 1 0.01];
options = optimoptions(@fminunc,'Display','iter','Algorithm','quasi-newton');
[x,fval,exitflag,output,grad,hessian] = fminunc(@(m) myfun,x0,options)
my function file:
function logl = myfun(m);
rs = m(2)*100*(0*puse(16,1)) + m(3)*(0-euse(16,1))*eprc(16,1)/100;
(I have a bunch of code in between which includes m(1), but the above line is where the error occured)
end
To fix the error I tried fixing the minimization code to:
[x,fval,exitflag,output,grad,hessian] = fminunc(@(x) myfun,x0,options)
[x,fval,exitflag,output,grad,hessian] = fminunc(myfun,x0,options)
I also tried defining m in the minimization code:
m = [0 0 0];
x0 = [0.2 1 0.01];
options = optimoptions(@fminunc,'Display','iter','Algorithm','quasi-newton');
[x,fval,exitflag,output,grad,hessian] = fminunc(@(m) myfun,x0,options)
in the function file, I tried eliminating the input argument,
function logl = myfun;
and changing the order by which elements of 'm' appear
rs = m(1)*100*(0*puse(16,1)) + m(2)*(0-euse(16,1))*eprc(16,1)/100;
The function file itself works as it is. Before, I had defined 'm' inside the function file (like m = [1 1 1]), but I think this caused the optimization routine to stay at that point.
0 commentaires
Réponse acceptée
Alan Weiss
le 22 Août 2016
I think that instead of
fminunc(@(m) myfun,x0,options)
you should call
fminunc(@myfun,x0,options)
or
fminunc(@(m) myfun(m),x0,options)
Alan Weiss
MATLAB mathematical toolbox documentation
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Solver Outputs and Iterative Display 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!