Optimization
NLPSolve
solve a nonlinear program
Calling Sequence
Parameters
Description
Options
Notes
Examples
Compatibility
NLPSolve(obj, constr, bd, opts)
NLPSolve(opfobj, ineqcon, eqcon, opfbd, opts)
obj
-
algebraic; objective function
constr
(optional) set(relation) or list(relation); constraints
bd
(optional) sequence of name = range; bounds for one or more variables
opfobj
procedure; objective function
ineqcon
(optional) set(procedure) or list(procedure); inequality constraints
eqcon
(optional) set(procedure) or list(procedure); equality constraints
opfbd
(optional) sequence of ranges; bounds for all variables
opts
(optional) equation(s) of the form option = value where option is one of assume, evaluationlimit, feasibilitytolerance, infinitebound, initialpoint, iterationlimit, maximize, method, nodelimit, objectivetarget, optimalitytolerance, output, useunits, or variables; specify options for the NLPSolve command
The NLPSolve command solves a nonlinear program (NLP), which involves computing the minimum (or maximum) of a real-valued objective function, possibly subject to constraints. Generally, a local minimum is returned unless the problem is convex. However, global search is available in limited situations, as described in the following Notes section. Most of the algorithms used by the NLPSolve command assume that the objective function and the constraints are twice continuously differentiable. NLPSolve will sometimes succeed even if these conditions are not met.
This help page describes the use of the NLPSolve command when the NLP is specified in algebraic or operator form. Summaries of these forms are given in the Optimization/AlgebraicForm and Optimization/OperatorForm help pages. NLPSolve also recognizes the problem in Matrix form (see the NLPSolve (Matrix Form) help page). Matrix form leads to more efficient computation, but is more complex.
It is recommended that you use the Optimization[LPSolve] command for linear programs (problems with linear objective functions and linear constraints). Use the Optimization[QPSolve] command for quadratic programs (problems with quadratic objective functions and linear constraints). The Optimization[LSSolve] command is available for objective functions in least-squares form.
The first calling sequence uses the algebraic form of input. The first parameter obj is the objective function, which must be an algebraic expression.
The second parameter constr is optional and is a set or list of relations (of type `<=` or `=`) involving the problem variables. The problem variables are the indeterminates of type name found in obj and constr. They can also be specified using the variables option.
Bounds, bd, on one or more of the variables are given as additional arguments, each of the form varname=varrange where varname is a variable name and varrange is its range.
The second calling sequence uses the operator form of input. The objective function opfobj must be a procedure that accepts n floating-point parameters representing the problem variables x1, x2, ..., xn and returns a float.
Inequality and equality constraints are provided using the optional ineqcon and eqcon parameters. An inequality constraint v⁡x1,x2,...,xn≤0 is specified by a procedure v in ineqcon that has the same form as opfobj and returns the left-hand side value of the constraint. Similarly, an equality constraint w⁡x1,x2,...,xn=0 is specified by a procedure w in eqcon. Either ineqcon or eqcon may be empty.
Bounds, opfbd, on the variables are optional, but if given must be a sequence of exactly n ranges corresponding in order to x1, x2, ..., xn.
For either form of input, non-negativity of the variables is not assumed by default, but can be specified using the assume = nonnegative option. Bounds can include values having type infinity.
Maple returns the solution as a list containing the final minimum (or maximum) value and a point (the extremum). If the output = solutionmodule option is provided, then a module is returned. See the Optimization/Solution help page for more information.
The opts argument can contain one or more of the following options. These options are described in more detail in the Optimization/Options help page.
assume = nonnegative -- Assume that all variables are non-negative.
evaluationlimit = posint -- Set the maximum number of objective function evaluations performed by the algorithm. This option is only available when the method option is set to branchandbound, modifiednewton, nonlinearsimplex or quadratic.
feasibilitytolerance = realcons(positive) -- Set the maximum absolute allowable constraint violation.
infinitebound = realcons(positive) -- Set any value of a variable greater than the infinitebound value to be equivalent to infinity during the computation.
initialpoint = set(equation), list(equation), or list(numeric) -- Use the provided initial point, which is a set or list of equations varname=value (for algebraic form input) or a list of exactly n values (for operator form input). The initial point is ignored when the quadratic interpolation method is used. For more information, see the Optimization/Methods help page.
iterationlimit = posint -- Set the maximum number of iterations performed by the solver. This option is only available when the method option is set to pcg or sqp.
maximize or maximize = truefalse -- Maximize the objective function when equal to true and minimize when equal to false. The option 'maximize' is equivalent to maximize = true. The default is maximize = false.
method = branchandbound, modifiednewton, nonlinearsimplex, pcg, quadratic, or sqp -- Specify the method. See the Optimization/Methods help page for more information.
nodelimit = posint -- Set the maximum number of nodes searched in the branch-and-bound tree. This option is only available with the method = branchandbound option.
objectivetarget = realcons -- Set the target objective function value which, if reached, causes the global search to terminate. This option is only available with the method = branchandbound option.
optimalitytolerance = realcons(positive) -- Set the tolerance that determines whether an optimal point has been found.
output = solutionmodule -- Return a module as described in the Optimization/Solution help page.
useunits = true or false or a list. See Optimization/Units.
variables = list(name) or set(name) -- Specify the problem variables when the objective function is in algebraic form.
The NLPSolve command uses various methods implemented in a built-in library provided by the Numerical Algorithms Group (NAG). See the Optimization/Methods help page for more details. The solvers are iterative in nature and require an initial point. The quality of the solution can depend greatly on the point chosen, so it is recommended that you provide a point using the initialpoint option. Otherwise, a point is automatically generated.
The NLPSolve command also provides a global branch-and-bound search algorithm for univariate problems having finite bounds but no other constraints. This method, specified with the method = branchandbound option, returns a global solution on the given interval.
The computation is performed in floating-point. Therefore, all data provided must have type realcons and all returned solutions are floating-point, even if the problem is specified with exact values. Because the solver fails when a complex value is encountered, it is sometimes necessary to add additional constraints to ensure that the objective function and constraints always evaluate to real values. For more information about numeric computation in the Optimization package, see the Optimization/Computation help page.
For some methods, the computation is more efficient when derivatives of the objective function and constraints are available. NLPSolve attempts to compute these derivatives automatically, but better performance can be achieved by directly providing derivatives using the Matrix form calling sequence described in the NLPSolve (Matrix Form) help page. For information on the methods that use derivatives, see the Optimization/Methods help page.
Although the assume = nonnegative option is accepted, general assumptions are not supported by commands in the Optimization package.
An answer is returned when necessary first-order conditions for optimality have been met and the iterates have converged. If the initial point already satisfies the conditions, then a warning is issued. Generally, the result is a local extremum but it is possible for the solver to return a saddle point. It is recommended that you try different initial points with each problem to verify that the solution is indeed an extremum.
Occasionally the solver will return a solution even if the iterates have not converged, but the point satisfies the first-order conditions. Setting infolevel[Optimization] to 1 or higher will produce a message indicating this situation if it occurs.
Unlike the situation for linear programming, it is difficult to detect unboundedness in the nonlinear case and no warning is issued by NLPSolve. If the solution values seem unexpectedly large or small, it is possible that the solution is unbounded.
If NLPSolve returns an error saying that no solution could be found, it is recommended that you try a different initial point or use tolerance parameters that are less restrictive.
with⁡Optimization:
Minimize a univariate function over a given range.
NLPSolve⁡sin⁡xx,x=1..30
−0.0424796169776126,x=23.5194525023235
Use options to maximize the objective function and to provide an initial point.
NLPSolve⁡x3+2⁢x⁢y−2⁢y2,x=−10..10,y=−10..10,initialpoint=x=3,y=4,maximize
1050.,x=10.,y=5.
Solve a constrained minimization problem and assume that all the variables are non-negative.
NLPSolve⁡w3⁢v−w2+w−x−12+x−y−22+y−z−32,w+x+y+z≤5,3⁢z+2⁢v−3=0,assume=nonnegative
6.43845963876504790,v=1.50000000000000,w=1.68857375382855,x=1.93714208200858,y=1.37428416416287,z=0.
Minimize an objective involving a special function.
NLPSolve⁡sin⁡x⁢Ψ⁡x,x=1..20
−2.82089000801683,x=17.2998468225688
Define a procedure f and use the operator form of input.
f := proc(x) if x < 0 then x^2+1; else cos(x); end if; end proc:
NLPSolve⁡f,−π..2⁢π
−1.,3.14159265358733
The Optimization[NLPSolve] command was updated in Maple 2018.
The useunits option was introduced in Maple 2018.
For more information on Maple 2018 changes, see Updates in Maple 2018.
See Also
Optimization/AlgebraicForm
Optimization/Computation
Optimization/MatrixForm
Optimization/Methods
Optimization/OperatorForm
Optimization/Options
Optimization/Solution
Optimization[LPSolve]
Optimization[LSSolve]
Optimization[NLPSolve] (MatrixForm)
Optimization[QPSolve]
realcons
Download Help Document