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
Operator Form
Matrix Form
Examples
Algebraic form is the most commonly used form for specifying optimization problems. The objective function and constraints are given as algebraic expressions, such as sin⁡x+y or v2+ⅇ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.
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 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.
with⁡Optimization:
Solve a linear programming problem specified using algebraic form. The objective function and the constraints are expressions in x and y.
LPSolve⁡−4⁢x−5⁢y,0≤x,0≤y,x+2⁢y≤6,5⁢x+4⁢y≤20
−19.,x=2.66666666666667,y=1.66666666666667
Solve a linear programming problem specified using Matrix form.
LPSolve⁡4,5,−3|1,5|1,12,2,0,∞,maximize
6.06250000000000,0.1875000000000001.06250000000000
Quadratic programming problems can be specified in algebraic form or in Matrix form.
QPSolve⁡2⁢x+5⁢y+3⁢x2+3⁢x⁢y+2⁢y2,2≤x−y
−3.53333333333333,x=0.466666666666667,y=−1.60000000000000
QPSolve⁡2,5,6|3,3|4,−1|1,−2,assume=nonnegative
16.,2.0.
Nonlinear programs can be specified in algebraic form or in Matrix form.
NLPSolve⁡sin⁡x3−11+x4,initialpoint=x=2
−0.0107674612530566632,x=3.07244485023085
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:
NLPSolve⁡2,obj,objectivegradient=objgrad
0.276597509679878506,0.03645601208177330.603788442821000
See Also
Optimization
Optimization/AlgebraicForm
Optimization/MatrixForm
Optimization/OperatorForm
Optimization[Interactive]
Optimization[LPSolve]
Optimization[LSSolve]
Optimization[Maximize]
Optimization[Minimize]
Optimization[NLPSolve]
Optimization[QPSolve]
Download Help Document