The error is straightforward:
Error using fmincon (line 635)
Supplied objective function must return a scalar value.
This is the reason fsolve works, since it is a root-finding algorithm.
In order for this to work with fmincon (and certain other optimisation functions), you would need to do something like this:
[x,fval,exitflag,output] = fmincon(@(x)norm(Obj_Fun(x)),x0,A,b,Aeq,beq,lb,ub)
That will llikely work with fmincon. Whether it produces the desired result is less certain.
.
Best Answer
The first two parts are warnings that your lb and ub variables are not empty but are also not as long as the number of variables.
This could happen if you attempted to use something like
with a vector x0, thinking that you were setting all of the lower bounds to 0, and all of the upper bounds to 10. However, instead MATLAB treats this example as
that is, it uses -inf for any lower bound you did not set and uses +inf for any upper bound that you did not set.
"Attempt to execute SCRIPT companies1 as a function:"
You named @companies1 as your objective function, so companies1.m was looked for. However it turns out that the code in companies1.m does not start with function or classdef: it starts with some other code, which makes it a "script" that cannot be called as a function. For example perhaps the first lines of companies1.m are
Those are lines that make the file a "script" rather than a function that accepts an input argument and returns the "cost" evaluated at that input argument.