MATLAB: How can i fix this errors while performing Optimization using fmincon.

fminconoptimization

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

lb = 0; ub = 10;

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

lb = [0, -inf(1,length(x0)-1)]; ub = [10, inf(1,length(x0)-1)];

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

clear all
close all

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.