Absolute maxima and minima of a function on a constraint set (2 variables)
Author: Joseph Lo

In this problem, we would like to find the extreme values of \[f(x,y) = 4-\dfrac{1}{4}(x^2+y^2)\] strictly on the constraint set \[g(x,y) = (x-1)^2 + 4y^2 - 4 = 0.\] At each of the critical points shown in the graph below, the level curve of \(f(x,y)\) (the black curve) is tangent to the constraint set (the blue curve). Since \(\nabla f \) is perpendicular to the level curve of \(f\) and \(\nabla g\) is perpendicular to the constraint set, we have \(\nabla f\) parallel to \(\nabla g\) at the critical points, or simply \[\nabla f = \lambda \nabla g\] for some scalar \(\lambda\).

On the constraint set, the maximum value of \(f\) is \(\dfrac{23}{6} = 3.8333\dots\) and the minimum value of \(f\) is \(\dfrac{7}{4} = 1.75\), both attained when the level curve just touches (tangent to) the constraint set.

∇f

0.1∇g

CP

Max

Max

CP

CP

CP

Drag the blue dot below to move P.

P

CP

CP

CP

CP

Max

Max

Min

Show point P on the constraint set

Show level curve of f(x,y) at P

Show ∇f and ∇g at P

Show critical points on the constraint set

Show max/min on the constraint set

Show f(x,y) and the constraint set in 3D

f(x, y) = 4 - (x^(2) + y^(2)) / 4
Curves = Sequence(CurveCartesian[(sqrt(i / 3) * cos(t)), (sqrt(i / 3) * sin(t)), t, 0, 6.28319], i, 0, 40)
a = CurveCartesian((2 * cos(t)) + 1, sin(t), t, -3.141592653589793, 3.141592653589793)
Curve3D = CurveCartesian((2 * cos(t)) + 1, sin(t), f((2 * cos(t)) + 1, sin(t)), t, -1.5707963267948966, 4.71238898038469)
P = Point(a)
fP: f(x(P), y(P))
LevelCurve: f(x, y) = fP
fx = Derivative(f(x, y), x)
fy = Derivative(f(x, y), y)
xP: x(P)
yP: y(P)
fyP: fy(xP, yP)
fxP: fx(xP, yP)
gradf = Vector((xP, yP), (xP + fxP, yP + fyP))
g(x, y) = (x - 1)^(2) + (4 * y^(2))
Constraint: g(x, y) = 4
gx = Derivative(g(x, y), x)
gy = Derivative(g(x, y), y)
lengf = Length(gradf)
gxP: gx(xP, yP)
gyP: gy(xP, yP)
gradg = Vector((xP, yP), (xP + gxP / 10, yP + gyP / 10))
lengg = Length(gradg)
B: (xP + gxP / 10 + (0.2 * gxP / 10 / lengg), yP + gyP / 10 + (0.2 * gyP / 10 / lengg))
A: (xP + fxP + (0.2 * fxP / lengf), yP + fyP + (0.2 * fyP / lengf))
Min = (3, 0)
CP1 = (-1, 0)
Max1 = (-0.3333333333333333, 0.7453559924999299)
Max2 = (-0.3333333333333333, -0.7453559924999299)
CP2 = (3, 0)
CP3 = (-0.3333333333333333, 0.7453559924999299)
CP4 = (-0.3333333333333333, -0.7453559924999299)
poly1, b, c, d, e = Polygon((-10, 2.5), (10, 2.5), (10, 10), (-10, 10))
P3D: (xP, yP, fP)
CP3D1: (x(CP1), y(CP1), f(x(CP1), y(CP1)))
CP3D2: (x(CP2), y(CP2), f(x(CP2), y(CP2)))
CP3D3: (x(CP3), y(CP3), f(x(CP3), y(CP3)))
CP3D4: (x(CP4), y(CP4), f(x(CP4), y(CP4)))
Max3D1: (x(Max1), y(Max1), f(x(Max1), y(Max1)))
Max3D2: (x(Max2), y(Max2), f(x(Max1), y(Max1)))
Min3D: (x(Min), y(Min), f(x(Min), y(Min)))
Pcheck = true
levelcurvecheck = false
gradcheck = false
CPcheck = false
maxmincheck = false
graphcheck = false
text4_1: "At P, f(" + xP + "," + yP + ") = " + fP + ""
minlevel3d = CurveCartesian((3 * cos(t)), (3 * sin(t)), 1.75, t, 0, 6.28319)
maxlevel3d = CurveCartesian((sqrt(2 / 3) * cos(t)), (sqrt(2 / 3) * sin(t)), 3.8333333333333335, t, 0, 6.283185307179586)
temp = 4 (slider from 4 to 5, step 2)