TITLE: Computing Extrema with Maple
# ### Problem 1

Find the shortest distance from the point (x0,y0,z0) to the
plane Ax+By+Cz+D=0.

### Solution 1

The square of the distance from the given point to an arbitrary point on the
plane is:
> z := solve(A*x+B*y+C*z+D,z); SqrDist := (x-x0)^2+(y-y0)^2+(z-z0)^2;
A x + B y + D
z := - -------------
C
2 2 / A x + B y + D \2
SqrDist := (x - x0) + (y - y0) + |- ------------- - z0|
\ C /
# this is assuming that C is not zero. We now minimize the above
expression as a function of x, and y. To do this we look first
for the point where the partials are both zero i.e.
> solve({diff(SqrDist,x), diff(SqrDist,y)},{x,y});
2 2
- x0 C + A D + A z0 C + B A y0 - B x0
{x = - ---------------------------------------,
2 2 2
A + C + B
2 2
- y0 C - A y0 + A B x0 + B D + B z0 C
y = - ---------------------------------------}
2 2 2
A + C + B
# You may want to compare this result with the
previous way
of doing it. Do both methods give the same answer?
### Problem 2

Find the global maximum and minimum values of the function f
on the closed triangular region with vertices (-1,1),(2,1)
and (-1,-2). Where,
> f := (x,y) -> x^2 + 2*x*y + 3*y^2:
#

### Solution 2

The gradient of f is,
> gf := grad(f(x,y),[x,y]);
gf := [ 2 x + 2 y, 2 x + 6 y ]
# and the only point where gf is zero is:
> solve({gf[1],gf[2]},{x,y});
{y = 0, x = 0}
# and the origin is inside the triangular region so it is
its global min. Clearly the function has no global max since
we can always increase the value of f by increasing x and or y.
>