To find the constrained maximum of a function using the fmincon
function in MATLAB, you need to define the objective function, the inequality constraints, and the bounds on the decision variables.
Here is an example that demonstrates how to use fmincon
to find the constrained maximum of a function:
main.m594 chars20 lines
In this example, we define a simple objective function -x1^2 - 2*x2^2 - 3*x3^2
to maximize. We also define two inequality constraints x1 + x2 + x3 <= 1
and -x1 - x2 - x3 <= -1
. The decision variables x
are bounded by lb
and ub
constraints.
The fmincon
function takes the objective function, initial guess, inequality constraints, bounds, and other optional arguments. It returns the constrained maximum fval
and the corresponding decision variables x
.
Note that the -
sign is used in the objective function to find the maximum instead of the minimum, as fmincon
is designed for minimization problems by default.
gistlibby LogSnag