Global extrema: minimize maximize

### 6.53.1 Global extrema: minimize maximize

minimize attempts to find the smallest value of a differentiable expression defined on a compact domain, using analytical methods.

- minimize takes two mandatory arguments and two optional arguments:
  - obj, a univariate or multivariate expression
  - Optionally, constr, list of constraints given by equalities, inequalities, and/or expressions assumed to be equal to 0. If there is only one constraint, it doesn’t have to be a list.
  - vars, list of variables. If there is only one variable, it doesn’t have to be a list. A variable can also include bounds, as in x=a..b.
  - Optionally, location, a keyword which may be coordinates, locus or point.
- minimize(obj ⟨, constr ⟩,vars ⟨,location⟩) returns the minimum value of obj on the domain specified by constraints and/or bounding variables, or (if location is specified) a list consisting of the minimum value and the list of points where the minimum is achieved.

  The domain must be closed and bounded (i.e. compact) and obj must be continuous and differentiable except in a finite number of points; otherwise the final result may be incorrect or meaningless. If the minimal value could not be obtained, then undef is returned.

The maximize command takes the same parameters as minimize, but returns the 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:

  − |
  π
  2

- Input:
  minimize(x^4-x^2,x=-3..3,locus)
  Output:

  ⎡ ⎢ ⎢ ⎣ | − |
  1
  4
  | , | ⎡ ⎢ ⎢ ⎣ |
  √ |
  2
  2
  | ,− |
  √ |
  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:

  ⎡ ⎢ ⎢ ⎣ | − | √ |
  2
  | , | ⎡ ⎢ ⎢ ⎣ |
  5
  4
  | π , |
  13
  4
  | π , |
  21
  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 | √ |
  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:

  √ |
  2
  18

- Input:
  maximize(x*y,[x+y^2<=2,x>=0,y>=0],[x,y],locus)
  Output:

  ⎡ ⎢ ⎢ ⎣ |
  4
  9
  |  | √ |
  6
  | , | ⎡ ⎢ ⎢ ⎣ |
  4
  3
  √ |
  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:

  a6
  27