MATLAB: FMINCON – Failure in initial objective function evaluation. FMINCON cannot continue.

fminconfmincon line 536optimisation

I am trying to minimise a self-written objective function, called S_min, subject to simple linear inequality constraints. Since S_max is a function of 5 arguments but I only want to optimise over the first 2, I use a function handle:
fun = @(x,y) S_min(x,y,2,MU1,P_max); % MU1, P_max defined above [not shown]
And then implement the optimisation through:
fmincon(fun, [0.5,6], A ,B); % A, B defined above [not shown]
I checked that fun(0.5,6), i.e. evaluated at the starting values, gives a correct, scalar, answer; and that the vector [0.5,6] satisfies inequality constraints, i.e. A.*[0.5,6]<=B.
However, when trying to minimise as above, I get the following error message:
"Error in fmincon (line 536) [...]
Failure in initial objective function evaluation. FMINCON cannot continue."
This is surprising as the function should evaluate correctly at this point.
Is there anything I can do to fix this?

Best Answer

FMINCON expects your function handle to look like this,
fun = @(p) S_min(p(1),p(2),2,MU1,P_max);
Related Question