Previous Up Next

15.2.1  Global optimization

minimize attempts to find, using analytical methods, the exact smallest value of a differentiable expression on a compact domain specified by (in)equality constraints.

The maximize command takes the same parameters as minimize, but returns the global maximum of obj on the specified domain.

Examples

Univariate minimization:

minimize(sin(x),[x=0..4])
     
sin
4
          
minimize(x^4-x^2,x=-3..3,locus)
     



1
4
,


2
2
,−
2
2






          

minimize and maximize can handle absolute values and piecewise expressions in one or more variables. For example, we find global minimum and global maximum of the function

f(x,y)=
|2+xyy2|+|2xx2+xy+y2|
1+x2+y2
 

on the square [−1,1]×[−1,1].

f(x,y):=(abs(2+x*y-y^2)+abs(2x-x^2+x*y+y^2))/(1+x^2+y^2):; minimize(f(x,y),[x=-1..1,y=-1..1]); maximize(f(x,y),[x=-1..1,y=-1..1]);
     
1
3
,
5
+3
2
          

As another example, input:

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

Each constraint can be either an equality or a non-strict inequality.

obj:=sqrt(x^2+y^2)-z:; constr:=[x^2+y^2<=16,x+y+z=10]:; minimize(obj,constr,[x,y,z])
     
−4 
2
−6
          
minimize(x^2*(y+1)-2y,[y<=2,sqrt(1+x^2)<=y],[x,y])
     
−4           

minimize and maximize are aware of implied constraints that restrict the natural domain of the objective function. In the following example, the constraint x2+y2≤ 1 is implied, and the minimum corresponds to any point on the unit circle.

minimize(sqrt(1-x^2-y^2),[x,y],point)
     












0,












y2+1
y
y2+1
y
x
x2+1
x
x2+1
























          

As another example, it is known that the natural domain of arc sine is the segment [−1,1].

minimize(asin(x),x)
     
π 
2
          

Constraints can be built from simpler ones by using logical conjunction and disjunction. The latter is suitable for specifying disconnected domains, as in the following example.

minimize(x*y,[x^2+y^2<=1,x<=-3/4 or x>=5/6],[x,y],point)
     



7
16
,



3
4
7
4






          

Symbolic constants are allowed in the objective and constraints. Note that they have to be either implied or assumed real numbers.

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

In the following example, we use minimize to obtain the formula for computing the distance d between the point P=(a,b,c) and the plane π given by the equation Ax+By+Cz+D=0. We accomplish this by finding a point (x0,y0,z0)∈π which is closest to P. Since we are going to minimize d2=(xa)2+(yb)2+(zc)2, the distance is equal to the square root of the minimum.

d:=minimize((x-a)^2+(y-b)^2+(z-c)^2,A*x+B*y+C*z+D=0,[x,y,z]):; simplify(sqrt(d))
     
|A a+B b+C c+D|
A2+B2+C2
          

Note that the coordinates x0, y0 and z0 can be obtained by passing point as the fourth argument in minimize.


Previous Up Next