MATH 251: Calculus 3, SET8

14: Partial Derivatives

14.8: Lagrange Multipliers

These problems are done with the CAS. See Hand Solutions for details.
1. [977/2a]
For values of , the parabolas are tangent to the circle at various points. These points are candidates for extreme values of the function subject to the constraint .
syms t x y; s = sqrt(3)/2;
fplot(cos(t), sin(t), [0 2*pi], 'b--', 'LineWidth', 2); grid on; hold on
fplot(x, 5/4-x^2, [-1.5 1.5], 'm', 'LineWidth', 1)
fplot(x, 1-x^2, [-1.5 1.5], 'r', 'LineWidth', 1)
fplot(x, -1-x^2, [-1.5 1.5], 'g', 'LineWidth', 1)
plot([-s 0 0 s], [1/2 -1 1 1/2], 'ko', 'MarkerFaceColor', 'k', 'MarkerSize', 10)
plot(0,0,'b+')
axis equal; axis([-1.5 1.5 -1.5 1.5])
xticks(-1:1); yticks(-1:1)
xlabel('x'); ylabel('y')
title('SET8, 977/2a')

1. [977/2b]

LAGRANGE MULTIPLIER PROCEDURE:
  1. Solve to get candidates.
  2. Compute at candidates.
  3. Identify absolute maximum and absolute minimum values of f.
CONCLUSION:
syms r t x y z lambda
f(x,y) = x^2 + y, g = x^2 + y^2 - 1 % Optimize f subject to the constraint g = 0.
f(x, y) = 
g = 
grad_f = gradient(f, [x y]), grad_g = gradient(g, [x y])
grad_f(x, y) = 
grad_g = 
eqs = [grad_f == lambda*grad_g; g == 0]
eqs(x, y) = 
s = solve(eqs, [x y lambda])
s = struct with fields:
x: [4×1 sym] y: [4×1 sym] lambda: [4×1 sym]
disp(' x y f(x,y)')
x y f(x,y)
M = [s.x s.y f(s.x,s.y)]
M = 
M_appx = double(M)
M_appx = 4×3
-0.8660 0.5000 1.2500 0.8660 0.5000 1.2500 0 -1.0000 -1.0000 0 1.0000 1.0000
%
figure
fplot3(cos(t), sin(t), sym(0), 'b--', [0 2*pi], 'LineWidth', 3); hold on
fplot3(cos(t), sin(t), f(cos(t),sin(t)), 'r', [0 2*pi], 'LineWidth', 3)
fsurf(x, y, sym(0), [-1 1 -1 1], 'y', 'MeshDensity', 10, 'EdgeColor', 'none')
fsurf(cos(t), sin(t), z, [0 2*pi, -1.5 1.5], 'g', 'MeshDensity', 16, 'EdgeColor', 'none')
fplot3(M(:,1), M(:,2), M(:,3), 'ko', 'MarkerFaceColor', 'k', 'MarkerSize', 16)
alpha 0.4
%
axis equal; axis([-1 1 -1 1 -1.5 1.5])
xlabel('x'); ylabel('y'); zlabel('z')
xticks(-1:1); yticks(-1:1); zticks(-1:1)
title('SET8, 977/2b')

2. [977/4]

Using the same procedure as in #2b, the absolute maximum is and the absolute minimum is .
syms x y lambda
f(x,y) = 3*x + y, g = x^2 + y^2 - 10 % Optimize f subject to the constraint g = 0.
f(x, y) = 
g = 
grad_f = gradient(f, [x y]), grad_g = gradient(g, [x y])
grad_f(x, y) = 
grad_g = 
eqs = [grad_f == lambda*grad_g; g == 0]
eqs(x, y) = 
s = solve(eqs, [x y lambda])
s = struct with fields:
x: [2×1 sym] y: [2×1 sym] lambda: [2×1 sym]
disp(' x y f(x,y)')
x y f(x,y)
M = [s.x s.y f(s.x,s.y)]
M = 

3. [977/16]

We use the same procedure with functions of 3 or more variables. Here there is an absolute minimum of , but no absolute maximum since .
syms c x y z lambda
f(x,y,z) = x^2 + 2*y^2 + 3*z^2, g = x + 2*y + 3*z - 10 % Optimize f subject to the constraint g = 0.
f(x, y, z) = 
g = 
grad_f = gradient(f, [x y z]), grad_g = gradient(g, [x y z])
grad_f(x, y, z) = 
grad_g = 
eqs = [grad_f == lambda*grad_g; g == 0]
eqs(x, y, z) = 
s = solve(eqs, [x y z lambda])
s = struct with fields:
x: [1×1 sym] y: [1×1 sym] z: [1×1 sym] lambda: [1×1 sym]
disp(' x y z f(x,y,z)')
x y z f(x,y,z)
M = [s.x s.y s.z f(s.x,s.y,s.z)]
M = 
M_appx = double(M)
M_appx = 1×4
1.6667 1.6667 1.6667 16.6667
h(c) = f(10,3*c,-2*c), infinity = limit(h(c), c, inf)
h(c) = 
infinity = 

4. [977/20]

Two constraints? No problem. Simply use another Lagrange multiplier and a linear combination of the constraint gradient vectors.
The absolute maximum is and the absolute minimum is .
syms x y z lambda mu real
f(x,y,z) = x^2 + y^2 + z^2, g = x - y - 1, h = y^2 - z^2 - 1
f(x, y, z) = 
g = 
h = 
% Optimize f subject to the constraints g = 0 and h = 0.
grad_f = gradient(f, [x y z]), grad_g = gradient(g, [x y z]), grad_h = gradient(h, [x y z])
grad_f(x, y, z) = 
grad_g = 
grad_h = 
eqs = [grad_f == lambda*grad_g + mu*grad_h; g == 0; h == 0]
eqs(x, y, z) = 
s = solve(eqs, [x y z lambda mu])
s = struct with fields:
x: [2×1 sym] y: [2×1 sym] z: [2×1 sym] lambda: [2×1 sym] mu: [2×1 sym]
disp(' x y z f(x,y,z)')
x y z f(x,y,z)
M = [s.x s.y s.z f(s.x,s.y,s.z)]
M = 
M_appx = double(M)
M_appx = 2×4
0 -1 0 1 2 1 0 5

5. [977/22]

Here we find extreme values of on the closed circular disk . We use the 14.7 technique (partially) on the interior of the disk and the 14.8 technique on the circular boundary of the disk. Round up points of interest on the interior and boundary, then compute function values.
CONCLUSION: The absolute minimum is on the interior and the absolute maximum is on the boundary.
An illustrative plot shows the situation at a glance.
syms r t x y lambda
f(x,y) = 2*x^2 + 3*y^2 - 4*x - 5, g = x^2 + y^2 - 16
f(x, y) = 
g = 
grad_f = gradient(f, [x y]), grad_g = gradient(g, [x y])
grad_f(x, y) = 
grad_g = 
% interior
si = solve(grad_f == [0 0], [x y])
si = struct with fields:
x: [1×1 sym] y: [1×1 sym]
Pi = [si.x si.y] % point in interior (If it were outside region, we'd toss it out!)
Pi = 
fsi = f(si.x, si.y)
fsi = 
eqs = [grad_f == lambda*grad_g; g == 0]
eqs(x, y) = 
s = solve(eqs, [x y lambda])
s = struct with fields:
x: [4×1 sym] y: [4×1 sym] lambda: [4×1 sym]
disp(' x y f(x,y)')
x y f(x,y)
M = [s.x s.y f(s.x,s.y)]
M = 
% plot
figure
fsurf(r*cos(t), r*sin(t), f(r*cos(t),r*sin(t)), [0 4 0 2*pi], 'MeshDensity', 16); hold on
fplot3(4*cos(t), 4*sin(t), f(4*cos(t),4*sin(t)), 'r', [0 2*pi], 'LineWidth', 5)
fplot3(M(:,1), M(:,2), M(:,3), 'ko', 'MarkerFaceColor', 'k', 'MarkerSize', 16)
plot3(1, 0, -7, 'ko', 'MarkerFaceColor', 'k', 'MarkerSize', 16)
alpha 0.4
%
axis([-4 4 -4 4 -10 50])
xlabel('x'); ylabel('y'); zlabel('z')
xticks(-4:2:4); yticks(-4:2:4); zticks(-10:10:50)
title('SET8, 977/22')
view(71,9)

6. [978/26]

We can estimate extreme values from a contour plot, then determine them exactly via Lagrange multipliers.
The expressions for the exact extreme values are rather complicated, so approximate values are given for brevity.
The absolute maximum is and the absolute minimum is .
% contour plot
syms t
figure
fplot(3+3*cos(t), 3+3*sin(t), [0 2*pi], 'r', 'LineWidth', 2); grid on; hold on
x = linspace(-1,7); y = linspace(-1,7);
[X,Y] = meshgrid(x,y); Z = X.^3 + Y.^3 + 3*X.*Y;
contour(X,Y,Z, [3.6731 50:50:300 347.3269 400:100:700], 'ShowText', 'on')
grid on; hold on
plot([-1 7], [0 0], 'k')
plot([0 0], [-1 7], 'k')
plot(0.8787, 0.8787, 'bo', 'MarkerFaceColor', 'b', 'MarkerSize', 14)
plot(5.1213, 5.1213, 'co', 'MarkerFaceColor', 'c', 'MarkerSize', 14)
xlabel('x'); ylabel('y')
axis equal; axis([-1 7 -1 7])
xticks(0:2:6); yticks(0:2:6)
title('SET8, 978/26: contour map of f')
% Lagrange multipliers
syms x y lambda real
f(x,y) = x^3 + y^3 + 3*x*y, g = (x-3)^2 + (y-3)^2 - 9 % Optimize f subject to the constraint g = 0.
f(x, y) = 
g = 
grad_f = gradient(f, [x y]), grad_g = gradient(g, [x y])
grad_f(x, y) = 
grad_g = 
eqs = [grad_f == lambda*grad_g; g == 0]
eqs(x, y) = 
s = solve(eqs, [x y lambda])
s = struct with fields:
x: [2×1 sym] y: [2×1 sym] lambda: [2×1 sym]
disp(' x y f(x,y)')
x y f(x,y)
M = simplify([s.x s.y f(s.x,s.y)])
M = 
M_appx = double(M)
M_appx = 2×3
0.8787 0.8787 3.6731 5.1213 5.1213 347.3269

7. [978/32]

The point on the plane closest to the point is found.
syms x y z lambda
P = [x y z], Q = [0 1 1], v = P-Q, f(x,y,z) = sum(v.^2)
P = 
Q = 1×3
0 1 1
v = 
f(x, y, z) = 
% We'll minimize the square of the distance from a point to the plane.
% Then we'll take the square root of the function value to get distance.
g = x - 2*y + 3*z - 6 % Optimize f subject to the constraint g = 0.
g = 
grad_f = gradient(f, [x y z]), grad_g = gradient(g, [x y z])
grad_f(x, y, z) = 
grad_g = 
eqs = [grad_f == lambda*grad_g; g == 0]
eqs(x, y, z) = 
s = solve(eqs, [x y z lambda])
s = struct with fields:
x: [1×1 sym] y: [1×1 sym] z: [1×1 sym] lambda: [1×1 sym]
disp(' x y z f(x,y,z)')
x y z f(x,y,z)
M = [s.x s.y s.z f(s.x,s.y,s.z)]
M = 
M_appx = double(M)
M_appx = 1×4
0.3571 0.2857 2.0714 1.7857
point = M(1:3), dist = sqrt(M(4))
point = 
dist = 
point_appx = double(point), dist_appx = double(dist) % in cm
point_appx = 1×3
0.3571 0.2857 2.0714
dist_appx = 1.3363

8. [978/38]

The dimensions of a rectangular box with volume having minimal surface area is found.
The desired box is a cube with side length and surface area .
syms x y z lambda real
f(x,y,z) = 2*(x*y + x*z + y*z), g = x*y*z - 1000 % Optimize f subject to the constraint g = 0.
f(x, y, z) = 
g = 
grad_f = gradient(f, [x y z]), grad_g = gradient(g, [x y z])
grad_f(x, y, z) = 
grad_g = 
eqs = [grad_f == lambda*grad_g; g == 0]
eqs(x, y, z) = 
s = solve(eqs, [x y z lambda])
s = struct with fields:
x: [1×1 sym] y: [1×1 sym] z: [1×1 sym] lambda: [1×1 sym]
disp(' x y z f(x,y,z)')
x y z f(x,y,z)
M = [s.x s.y s.z f(s.x,s.y,s.z)]
M = 
M_appx = double(M)
M_appx = 1×4
10 10 10 600

9. [978/40]

The dimensions of a rectangular box with surface area having largest volume is found.
The desired box is a cube with side length and volume .
syms x y z lambda positive
f(x,y,z) = x*y*z, g = 2*(x*y + x*z + y*z) - 64 % Optimize f subject to the constraint g = 0.
f(x, y, z) = 
g = 
grad_f = gradient(f, [x y z]), grad_g = gradient(g, [x y z])
grad_f(x, y, z) = 
grad_g = 
eqs = [grad_f == lambda*grad_g; g == 0]
eqs(x, y, z) = 
s = solve(eqs, [x y z lambda])
s = struct with fields:
x: [1×1 sym] y: [1×1 sym] z: [1×1 sym] lambda: [1×1 sym]
disp(' x y z f(x,y,z)')
x y z f(x,y,z)
M = [s.x s.y s.z f(s.x,s.y,s.z)]
M = 
M_appx = double(M)
M_appx = 1×4
3.2660 3.2660 3.2660 34.8372

10. [978/48]

Extreme values of a function f subject to two constraints are found.
The absolute maximum is .
The absolute minimum is .
syms x y z lambda mu
f(x,y,z) = x + y + z, g = x^2 - y^2 - z, h = x^2 + z^2 - 4
f(x, y, z) =