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.
Best Answer