
Calling Sequence


NLPSolve(obj, constr, bd, opts)
NLPSolve(opfobj, ineqcon, eqcon, opfbd, opts)


Parameters


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





Description


•

The NLPSolve command solves a nonlinear program (NLP), which involves computing the minimum (or maximum) of a realvalued 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 leastsquares 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 $\mathrm{varname}=\mathrm{varrange}$ where varname is a variable name and $\mathrm{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$ floatingpoint parameters representing the problem variables $\mathrm{x1}$, $\mathrm{x2}$, ..., $\mathrm{xn}$ and returns a float.


Inequality and equality constraints are provided using the optional ineqcon and eqcon parameters. An inequality constraint $v\left(\mathrm{x1}\,\mathrm{x2}\,\mathrm{...}\,\mathrm{xn}\right)\le 0$ is specified by a procedure v in ineqcon that has the same form as opfobj and returns the lefthand side value of the constraint. Similarly, an equality constraint $w\left(\mathrm{x1}\,\mathrm{x2}\,\mathrm{...}\,\mathrm{xn}\right)=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 $\mathrm{x1}$, $\mathrm{x2}$, ..., $\mathrm{xn}$.

•

For either form of input, nonnegativity 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.



Options



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 nonnegative.

•

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 $\mathrm{varname}=\mathrm{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 branchandbound 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.

•

variables = list(name) or set(name)  Specify the problem variables when the objective function is in algebraic form.



Notes


•

The NLPSolve command uses various methods implemented in a builtin 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 branchandbound 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 floatingpoint. Therefore, all data provided must have type realcons and all returned solutions are floatingpoint, 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 firstorder 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 firstorder 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.



Examples


Minimize a univariate function over a given range.
>

NLPSolve(sin(x)/x, x=1..30);

$\left[{\mathrm{0.0424796169776126}}{\,}\left[{x}{=}{23.5194525023235}\right]\right]$
 (1) 
Use options to maximize the objective function and to provide an initial point.
>

NLPSolve(x^3+2*x*y2*y^2, x=10..10, y=10..10, initialpoint={x=3,y=4}, maximize);

$\left[{1050.}{\,}\left[{x}{=}{10.}{\,}{y}{=}{5.}\right]\right]$
 (2) 
Solve a constrained minimization problem and assume that all the variables are nonnegative.
>

NLPSolve(w^3*(vw)^2+(wx1)^2+(xy2)^2+(yz3)^2, {w+x+y+z<=5, 3*z+2*v3=0}, assume = nonnegative);

$\left[{6.43845963876504790}{\,}\left[{v}{=}{1.50000000000000}{\,}{w}{=}{1.68857375382855}{\,}{x}{=}{1.93714208200858}{\,}{y}{=}{1.37428416416287}{\,}{z}{=}{0.}\right]\right]$
 (3) 
Minimize an objective involving a special function.
>

NLPSolve(sin(x)*Psi(x), x=1..20);

$\left[{\mathrm{2.82089000801683}}{\,}\left[{x}{=}{17.2998468225688}\right]\right]$
 (4) 
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, Pi..2*Pi);

$\left[{\mathrm{1.}}{\,}\left[\begin{array}{c}{3.14159265358733}\end{array}\right]\right]$
 (5) 


Compatibility


•

The Optimization[NLPSolve] command was updated in Maple 2018.

•

The useunits option was introduced in Maple 2018.



