solve a nonlinear program - Maple Help

Online Help

All Products    Maple    MapleSim

Home : Support : Online Help : Mathematics : Optimization : Optimization Package : Optimization/NLPSolve

Optimization[NLPSolve] - solve a nonlinear program

Calling Sequence

NLPSolve(obj, constr, bd, opts)

NLPSolve(opfobj, ineqcon, eqcon, opfbd, opts)




algebraic; objective function



(optional) set(relation) or list(relation); constraints



(optional) sequence of name = range; bounds for one or more variables



procedure; objective function



(optional) set(procedure) or list(procedure); inequality constraints



(optional) set(procedure) or list(procedure); equality constraints



(optional) sequence of ranges; bounds for all variables



(optional) equation(s) of the form option = value where option is one of assume, feasibilitytolerance, infinitebound, initialpoint, iterationlimit, maximize, method, optimalitytolerance, or output; 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&equals;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 vx1&comma;x2&comma;...&comma;xn0 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 wx1&comma;x2&comma;...&comma;xn&equals;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&equals;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.


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.



Minimize a univariate function over a given range.




Use options to maximize the objective function and to provide an initial point.




Solve a constrained minimization problem and assume that all the variables are non-negative.




Minimize an objective involving a special function.




Define a procedure f and use the operator form of input.

f := proc(x)
  if x < 0 then
  end if;
end proc:




See Also

Optimization, 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

Was this information helpful?

Please add your Comment (Optional)
E-mail Address (Optional)
What is ? This question helps us to combat spam