Lagrange Multipliers

The following example demonstrates the method of Lagrange multipliers for minimizing a given function subject to given constraints.

PROBLEM.  Minimize  f(x,y,z) = x2+y2+z2  subject to the constraints  y+2z-12 = 0 and  x+y-6 = 0 .

SOLUTION.

> f:=x^2+y^2+z^2:
> g1:=y+2*z-12:
> g2:=x+y-6:
> h:=f-m1*g1-m2*g2:

Here,  m1 and   m2 are Lagrange multipliers.

> solve({diff(h,x)=0,diff(h,y)=0,diff(h,z)=0, diff(h,m1)=0, diff(h,m2)=0}, {x,y,z,m1,m2});

             {y=4,z=4,x=2,m2=4,m1=4}       (Maple's return)

In case Maple does not provide numerical solutions, you may want to approximate them by typing

> evalf(solve({diff(h,x)=0,diff(h,y)=0,diff(h,z)=0, diff(h,m1)=0, diff(h,m2)=0}, {x,y,z,m1,m2}));

             {y=4.,z=4.,x=2.,m2=4.,m1=4.}  (Maple's return)

Evaluate function  f(x,y,z)  at all critical points

> subs(x=2,y=4,z=4,f);

                          36               (Maple's return)