A common way to write the objective function in matlab (including the gradient vector) is the following:
[L,G] = objfun(x)
where L
is the value of objective function, G
is the gradient vector and x
is a vector of coefficients which I want to optimize.
However, when I include another input (i.e [L,G]=objfun(x,M)
, where M
is a matrix) or when I call another function in the function objfun
, the code is not running.
How can I include any inputs and call any functions in the objfun
by keeping this format of optimization?
Note that I call the optimization as follows:
[x ,fval] = fminunc(@objfun,x,options)
where
options = optimoptions(@fminunc,'Algorithm','quasinewton',...
'Display','iter','Gradobj','on','TolFun',10^-8)