Mathematica Labs | Denis Shubleka

Subject: Calculus

Topic: The Lagrange Multiplier Method

Goal: Use Mathematica to optimize f(x, y) subject to a constraint g(x,y) = 0.

Task 1

Find the maximum and minimum of f(x,y)= 2x - y on the circle of radius 5, centered at the origin. 
We first define the objective function and the contraint, and then compute the two gradients:

F[x_,y_]:=2x-y
G[x_,y_]:=x^2+y^2-25
gradientf ={D[F[x,y],x],D[F[x,y],y]};
gradientg ={D[G[x,y],x],D[G[x,y],y]};
Print["Gradient of f:", gradientf]
Print["Gradient of g:",gradientg]

Next, we find solutions to the equation: ∇f(x,y) = λ∇g(x,y). The solutions are candidates for optimal points.

candidates = Solve[{gradientf == l* gradientg,G[x,y]==0},{x,y,l}]

Next, compute each pair of (x, y) coordinates and print the resulting function values:

{x, y,N[F[x,y]]}/.candidates

Where does f(x,y) the maximum attain a maximum point? A minimum?

Related Exercises/Notes:

1. A rectangular box without a lid is to be made from 12 square meters of cardboard. Find the maximum volume of such a box.

2. Find the extreme values of the function f(x,y)= (x^2)+2(y^2) on the circle (x^2)+(y^2)=1.

3. Find all the points on the  sphere (x^2)+(y^2)+(z^2)=4 that are closest to and farthest from the point (3, 1,-1).

4. Find the maximum value of the function f(x,y,z)= x + 2y + 3z 
 on the curve of intersection of the plane x - y + z =1  and the cylinder (x^2) + (y^2) = 1  . [Hint: Two Lagrange Multipliers are needed.
∇f(x,y,z) = λ∇g(x,y,z)+ ℽ∇h(x,y,z) ]

ap-calc.github.io