Local extrema of a univariate or multivariate differentiable function under equality constraints can be obtained by using function extrema which takes four arguments :

- expr : differentiable expression
- constr (optional) : list of equality constraints
- vars : list of variables
- order_size=<positive integer> or lagrange (optional) : upper bound for the order of derivatives examined in the process (defaults to 5) or the specifier for the method of Lagrange multipliers

Function returns sequence of two lists of points: local minima and maxima, respectively. Saddle and unclassified points are reported in the message area. Also, information about possible (non)strict extrema is printed out. If lagrange is passed as an optional last argument, the method of Lagrange multipliers is used. Else, the problem is reduced to an unconstrained one by applying implicit differentiation.

A single constraint/variable can be specified without list delimiters. A constraint may be specified as an equality or expression which is assumed to be equal to zero.

Number of constraints must be strictly less than number of variables. Additionally, denoting k -th constraint by g_{k}(x_{1},x_{2},…,x_{n})=0 for k=1,2,…,m and letting g=(g_{1},g_{2},…,g_{m}) , Jacobian matrix of g has to be full rank (i.e. equal to m ).

Variables may be specified with bounds, e.g. x=a..b, which is interpreted as x∈(a,b) . For semi-bounded variables one can use -infinity for a or +infinity for b . Also, parameter vars may be entered as e.g. [x1=a1,x2=a2,...,xn=an], in which case the critical point close to a=(a_{1},a_{2},…,a_{n}) is computed numerically, applying an iterative method with initial point a .

If order_size=<n> is specified as the fourth argument, derivatives up to order n are inspected to find critical points and classify them. For order_size=1 the function returns a single list containing all critical points found. The default is n=5 . If some critical points are left unclassified one might consider repeating the process with larger value of n , although the success is not guaranteed.

Input :

extrema(-2*cos(x)-cos(x)

`^`

2,x)
Output :

[0],[pi]

Input :

extrema(x/2-2*sin(x/2),x=-12..12)

Output :

[2*pi/3,-10*pi/3],[10*pi/3,-2*pi/3]

Input :

assume(a>=0);extrema(x

`^`

2+a*x,x)
Output :

[-a/2],[]

Input :

extrema(exp(x

`^`

2-2x)*ln(x)*ln(1-x),x=0.5)
Output :

[],[0.277769149124]

Input :

extrema(x

`^`

3-2x*y+3y`^`

4,[x,y])
Output :

[[12

`^`

(1/5)/3,(12`^`

(1/5))`^`

2/6]],[]
Input :

assume(a>0);extrema(x/a

`^`

2+a*y`^`

2,x+y=a,[x,y])
Output :

[[(2*a

`^`

4-1)/(2*a`^`

3),1/(2*a`^`

3)]],[]
Input :

extrema(x

`^`

2+y`^`

2,x*y=1,[x=0..inf,y=0..inf])
Output :

[[1,1]],[]

Input :

extrema(x2

`^`

4-x1`^`

4-x2`^`

8+x1`^`

10,[x1,x2])
Output :

[[6250

`^`

(1/6)/5,0],[-6250`^`

(1/6)/5,0]],[]
Input :

extrema(x*y*z,x+y+z=1,[x,y,z],order_size=1)

Output :

[[1,0,0],[0,1,0],[0,0,1],[1/3,1/3,1/3]]