### 6.55.1 Global extrema: minimize maximize

The function minimize takes four arguments :

- obj : univariate or multivariate expression
- constr (optional) : list of equality and inequality constraints
- vars : list of variables
- location (optional) : option keyword which may be coordinates, locus or point

The expression obj is minimized on the domain specified by constraints and/or bounding variables, which can be done as specifying e.g. x=a..b in vars. The domain must be closed and bounded and obj must be continuous in every point of it. Else, the final result may be incorrect or meaningless.

Constraints may be given as equalities or inequalities, but also as expressions which are assumed to be equal to zero. If there is only one constraint, the list delimiters may be dropped. The same applies to the specification of variables.

minimize returns minimal value. If it could not be obtained, it returns undef. If location is specified, the list of points where the minimum is achieved is also returned as the second member in a sequence. Keywords locus, coordinates and point all have the same effect.

The function maximize takes the same parameters as minimize. The difference is that it computes global maximum of obj on the specified domain.

#### Examples

Input :

minimize(sin(x),[x=0..4])

Output :

sin(4)

Input :

minimize(asin(x),x=-1..1)

Output :

-pi/2

Input :

minimize(x`^`4-x`^`2,x=-3..3,locus)

Output :

-1/4,[-sqrt(2)/2]

Input :

minimize(x-abs(x),x=-1..1)

Output :

-2

Input :

minimize(when(x==0,0,exp(-1/x`^`2)),x=-1..1)

Output :

0

Input :

minimize(sin(x)+cos(x),x=0..20,coordinates)

Output :

-sqrt(2),[5*pi/4,13*pi/4,21*pi/4]

Input :

minimize(x`^`2-3x+y`^`2+3y+3,[x=2..4,y=-4..-2],point)

Output :

-1,[[2,-2]]

Input :

obj:=sqrt(x`^`2+y`^`2)-z;
constr:=[x`^`2+y`^`2<=16,x+y+z=10];
minimize(obj,constr,[x,y,z])

Output :

-4*sqrt(2)-6

Input :

minimize(x`^`2*(y+1)-2y,[y<=2,sqrt(1+x`^`2)<=y],[x,y])

Output :

-4

Input :

maximize(cos(x),x=1..3)

Output :

cos(1)

Input :

obj:=piecewise(x<=-2,x+6,x<=1,x`^`2,3/2-x/2); maximize(obj,x=-3..2)

Output :

4

Input :

maximize(x*y*z,x`^`2+2*y`^`2+3*z`^`2<=1,[x,y,z])

Output :

sqrt(2)/18

Input :

maximize(x*y,[x+y`^`2<=2,x>=0,y>=0],[x,y],locus)

Output :

4*sqrt(6)/9,[[4/3,sqrt(6)/3]]

Input :

maximize(y`^`2-x`^`2*y,y<=x,[x=0..2,y=0..2])

Output :

4/27

Input :

assume(a>0);
maximize(x`^`2*y`^`2*z`^`2,x`^`2+y`^`2+z`^`2=a`^`2,[x,y,z])

Output :

a`^`6/27