### 16.2.2 Local extrema

The extrema command attempts to find local extrema of a univariate/multivariate differentiable expression, possibly subject to equality constraints, by using analytical methods.

- extrema takes two mandatory arguments and two optional arguments:
  - expr, a differentiable expression.
  - Optionally, constr, a list of equality constraints, where each constraint is an equality or an expression assumed to be equal to zero, and the number of constraints must be strictly less than the number of variables. If there is only one constraint, it does not have to be a list.

    Additionally, the Jacobian matrix of the constraints must be full rank (i.e., denoting the kth constraint by gk(x1,x2,…,xn)=0 for k=1,2,…,m and letting g=(g1,g2,…,gm), the Jacobian matrix of g must be equal to m).

  - vars, a list of variables. A variable can be specified with bounds, x=a..b, where a or b is allowed to be -infinity or infinity. Note that extrema respects the bound constraints set to variables by the assume command.

    If there is only one variable, it does not have to be enclosed in square brackets.

    The parameter vars can also be entered as a list of values of the variables; e.g. [x1=a1,x2=a2,…,xn=an], in which case the critical point close to a=(a1,a2,…,an) is computed numerically by applying an iterative method with initial point a.

  - Optionally, opt, which can be either
    - order=n, to make n the upper bound for the order of derivatives examined in the process (so if n=1 only critical points are found, by default n=5), or
    - lagrange to specify the method of Lagrange multipliers.
- extrema(expr ⟨,constr ⟩,vars ⟨,opt ⟩) returns a list [min,max], where min is the list of local minima and max is the list of local maxima of expr. Saddle, unclassified and indeterminate points are reported in the message area. 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.
- If some critical points are left unclassified, you might consider repeating the process with larger values of the parameter order (e.g. for f(x)=x8, extrema requires n≥ 8 in order to find the minimum), although the success is not guaranteed. Indeterminate critical points are unclassifiable.

#### Examples

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

⎡ ⎢ ⎣ |
0
π
| ⎤ ⎥ ⎦

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

⎡ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎣ |
− |
10
3
| π
2
3
| π
− |
2
3
| π
10
3
| π
| ⎤ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎦

assume(a>=0):; extrema(x^2+a*x,x)

| ⎡ ⎢ ⎢ ⎣ | ⎡ ⎢ ⎢ ⎣ | − |
1
2
| a | ⎤ ⎥ ⎥ ⎦ | , | ⎡ ⎣ | ⎤ ⎦ | ⎤ ⎥ ⎥ ⎦

extrema(exp(x^2-2 x)*ln(x)*ln(1-x),x=0.5)

| ⎡ ⎣ | ⎡ ⎣ | ⎤ ⎦ | , | ⎡ ⎣ | 0.277769149124 | ⎤ ⎦ | ⎤ ⎦

extrema(x^3-2 x*y+3 y^4,[x,y])

[x=0,y=0]: saddle point

| ⎡ ⎢ ⎢ ⎢ ⎢ ⎣ |
⎡ ⎢ ⎢ ⎢ ⎢ ⎣ |
12 |
1
5
3
⎛ ⎜ ⎝ | 12 |
1
5
| ⎞ ⎟ ⎠ |
2
6
| ⎤ ⎥ ⎥ ⎥ ⎥ ⎦
| , | ⎡ ⎣ | ⎤ ⎦ | ⎤ ⎥ ⎥ ⎥ ⎥ ⎦

assume(a>0):; extrema(x/a^2+a*y^2,x+y=a,[x,y],lagrange)

| ⎡ ⎢ ⎢ ⎣ |
⎡ ⎢ ⎢ ⎣ |
2 a4−1
2 a3
1
2 a3
| ⎤ ⎥ ⎥ ⎦
| , | ⎡ ⎣ | ⎤ ⎦ | ⎤ ⎥ ⎥ ⎦

extrema(x^2+y^2,x*y=1,[x=0..inf,y=0..inf])

| ⎡ ⎣ |
⎡ ⎣ |
1 | 1
| ⎤ ⎦
| , | ⎡ ⎣ | ⎤ ⎦ | ⎤ ⎦

To find only the critical points of f(x,y,z)=x y z subject to x+y+z=1:

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

⎡ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎣ |
0 | 1 | 0
0 | 0 | 1
1 | 0 | 0
1
3
1
3
1
3
| ⎤ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎦

The Peano surface z=(2x2−y)(y−x2) was proposed by Giuseppe Peano in 1899 as a counter-example to a criterion for the existence of maxima and minima which was conjectured at the time. Indeed, it is not possible to classify its only critical point (0,0), which turns out to be a saddle, not a maximum:

extrema((2 x^2-y)*(y-x^2),[x,y])

[x=0,y=0]: indeterminate critical point

| ⎡ ⎣ | ⎡ ⎣ | ⎤ ⎦ | , | ⎡ ⎣ | ⎤ ⎦ | ⎤ ⎦