Overview - Maple Help

Forms of Input for Optimization Package Commands

 This help page gives a brief overview of the ways in which optimization problems can be specified in the Optimization package.  More information about each form can be found in the Optimization/AlgebraicForm, Optimization/OperatorForm, and Optimization/MatrixForm help pages.

Algebraic Form

 • Algebraic form is the most commonly used form for specifying optimization problems.  The objective function and constraints are given as algebraic expressions, such as $\mathrm{sin}\left(x+y\right)$ or ${v}^{2}+{ⅇ}^{v}$.
 • Algebraic form is accepted by all the Optimization package exports.  It is the only form accepted by the Optimization[Interactive] Maplet application.
 • All computations performed by solvers in the Optimization package use floating-point Vectors and Matrices.  Problems specified in algebraic form are converted to Matrix form by the solvers. The computation performed is numeric and floating-point results are returned, even if symbols or exact data are provided.
 • For a detailed description of algebraic form, see the Optimization/AlgebraicForm help page.

Operator Form

 • Using operator form, the objective function and the constraints are provided as procedures taking one or more parameters and returning a scalar.
 • The operator form of input is accepted by the following commands: Optimization[Minimize], Optimization[Maximize], Optimization[NLPSolve], and Optimization[LSSolve].  When this form is used, the Minimize and Maximize commands automatically assume the input is nonlinear and calls the nonlinear programming solvers, even if the input represents linear functions.
 • Input in operator form is converted to Matrix form by the solver. Specifically, procedures are converted to take Vector parameters.
 • For a detailed description of operator form, see the Optimization/OperatorForm help page.

Matrix Form

 • Matrix form provides the greatest flexibility in specifying the problem and results in the most efficient performance by the solvers. However, it is also the most complex. Using Matrix form, the objective function and the constraints are specified as Vectors, Matrices, and procedures accepting and returning Vectors.
 • Matrix form is not supported by the Optimization[Minimize] and Optimization[Maximize] commands or by the Optimization[Interactive] Maplet.  It is accepted by the Optimization[LPSolve], Optimization[QPSolve], Optimization[NLPSolve] and Optimization[LSSolve] commands.
 • Matrix form input is converted to floating-point data if it is not of floating-point type.  The Optimization solvers attempt to use hardware floating-point computation when possible and appropriate.  To avoid unnecessary copying of Matrices and Vectors, create these objects with the datatype and storage recommended in the help pages of the specific Optimization commands.
 • For a detailed description of Matrix form, see the Optimization/MatrixForm help page.

Examples

 > $\mathrm{with}\left(\mathrm{Optimization}\right):$

Solve a linear programming problem specified using algebraic form. The objective function and the constraints are expressions in x and y.

 > $\mathrm{LPSolve}\left(-4x-5y,\left\{0\le x,0\le y,x+2y\le 6,5x+4y\le 20\right\}\right)$
 $\left[{-19.}{,}\left[{x}{=}{2.66666666666667}{,}{y}{=}{1.66666666666667}\right]\right]$ (1)

Solve a linear programming problem specified using Matrix form.

 > $\mathrm{LPSolve}\left(⟨4,5⟩,\left[⟨⟨-3|1⟩,⟨5|1⟩⟩,⟨\frac{1}{2},2⟩\right],\left[0,\mathrm{\infty }\right],\mathrm{maximize}\right)$
 $\left[{6.06250000000000}{,}\left[\begin{array}{c}{0.187500000000000}\\ {1.06250000000000}\end{array}\right]\right]$ (2)

Quadratic programming problems can be specified in algebraic form or in Matrix form.

 > $\mathrm{QPSolve}\left(2x+5y+3{x}^{2}+3xy+2{y}^{2},\left\{2\le x-y\right\}\right)$
 $\left[{-3.53333333333333}{,}\left[{x}{=}{0.466666666666667}{,}{y}{=}{-1.60000000000000}\right]\right]$ (3)
 > $\mathrm{QPSolve}\left(\left[⟨2,5⟩,⟨⟨6|3⟩,⟨3|4⟩⟩\right],\left[⟨⟨-1|1⟩⟩,⟨-2⟩\right],\mathrm{assume}=\mathrm{nonnegative}\right)$
 $\left[{16.}{,}\left[\begin{array}{c}{2.}\\ {0.}\end{array}\right]\right]$ (4)

Nonlinear programs can be specified in algebraic form or in Matrix form.

 > $\mathrm{NLPSolve}\left({\mathrm{sin}\left(x\right)}^{3}-\frac{1}{1+{x}^{4}},\mathrm{initialpoint}=\left\{x=2\right\}\right)$
 $\left[{-0.0107674612530566632}{,}\left[{x}{=}{3.07244485023085}\right]\right]$ (5)

You should provide the gradient of the objective function if you want to use NLPSolve in Matrix form.

 > obj := proc(v)          10*v[1]^2 - 2*v[1]*v[2]^2 + v[2]^4 + 1 - 2*v[2] + v[2]^2        end proc:
 > objgrad := proc(v, w)         w[1] := 20*v[1] - 2*v[2]^2:         w[2] := -4*v[1]*v[2] + 4*v[2]^3 - 2 + 2*v[2] end proc:
 > $\mathrm{NLPSolve}\left(2,\mathrm{obj},\mathrm{objectivegradient}=\mathrm{objgrad}\right)$
 $\left[{0.276597509679878506}{,}\left[\begin{array}{c}{0.0364560120817733}\\ {0.603788442821000}\end{array}\right]\right]$ (6)