minimize attempts to find, using analytical methods, the exact smallest value of a differentiable expression on a compact domain specified by (in)equality constraints.
Variables can also be given as x=x0, y=y0 and so on, in which case the optimum is computed numerically by performing a local search from the specified point (x0,y0,…).
If the domain is not compact, the final result may be incorrect or meaningless. If the minimal value could not be found, then undef is returned. In some cases, unboundeness of the objective function can be detected.
Note that minimize respects the bound constraints set to variables by the assume command.
The maximize command takes the same parameters as minimize, but returns the global maximum of obj on the specified domain.
sin | ⎛ ⎝ | 4 | ⎞ ⎠ |
⎡ ⎢ ⎢ ⎣ | − |
| , | ⎡ ⎢ ⎢ ⎣ |
| ,− |
| ⎤ ⎥ ⎥ ⎦ | ⎤ ⎥ ⎥ ⎦ |
f(x,y)= |
|
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]); |
| , |
|
obj:=piecewise(x<=-2,x+6,x<=1,x^2,3/2-x/2); |
maximize(obj,x=-3..2) |
4 |
obj:=sqrt(x^2+y^2)-z; |
constr:=[x^2+y^2<=16,x+y+z=10]; |
minimize(obj,constr,[x,y,z]) |
−4 | √ |
| −6 |
−4 |
⎡ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎣ | 0, | ⎡ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎣ |
| ⎤ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎦ | ⎤ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎦ |
− |
|
⎡ ⎢ ⎢ ⎣ | − |
| , | ⎡ ⎢ ⎢ ⎣ |
| ⎤ ⎥ ⎥ ⎦ | ⎤ ⎥ ⎥ ⎦ |
assume(a>0); |
maximize(x^2*y^2*z^2,x^2+y^2+z^2=a^2,[x,y,z]) |
|
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)) |
|