BetaFree coursewareRewritten from MIT OpenCourseWareCC BY-NC-SA 4.0
Open CosmologyPhysics & cosmology, from high school to a graduate year

Problem Set 5: steepest directions, a linear estimate and a closest point by Lagrange multipliers

Three problems on the gradient and on Lagrange multipliers. You find the largest and smallest directional derivative of a function of two variables and the directions in which they occur, repeat the search numerically, follow the direction of fastest decrease to estimate the nearest point of a level surface with a linear approximation, and then find that point to four decimal places with a Lagrange multiplier.

You need this first

Full reading path (13 pages)
  1. Vectors (8.01)
  2. Vectors and the dot product (18.02)
  3. Determinants and the cross product (18.02)
  4. Planes through three points, and matrices (18.02)
  5. Equations of planes and square systems (18.02)
  6. Parametric equations of lines and the cycloid (18.02)
  7. Velocity, acceleration and Kepler's second law (18.02)
  8. Functions of two variables and partial derivatives (18.02)
  9. Tangent planes, critical points and least squares (18.02)
  10. The second derivative test (18.02)
  11. Differentials and the chain rule (18.02)
  12. The gradient and directional derivatives (18.02)
  13. Lagrange multipliers (18.02)
On this page · 5 sections
  1. How to answer
  2. Problem 1
  3. Problem 2
  4. Problem 3
  5. More practice: MIT's own solved exercises

This set practises two lessons: the gradient and directional derivatives and Lagrange multipliers. It follows MIT's Problem Set 5, in our own words.

MIT's set has two parts. Part B holds MIT's three longer problems (19 points), for which OpenCourseWare has no solutions. All three are written out below, with hints and solutions of our own. Part A is a list of short exercises, most of them from MIT's own Supplementary Notes, which also hold their solutions. Those are not rewritten here: the last section of this page lists them and links to MIT's exercises and solutions.

MIT's sheet numbers the lectures by its Fall 2007 calendar, which counts the day of the first exam. Its "Lecture 13" (gradient, directional derivative, tangent plane) is Lecture 12 on this site and in MIT's lecture summaries, and its "Lecture 14" (Lagrange multipliers) is Lecture 13 here. Problems 1 and 2 belong to the gradient lesson and Problem 3 to the lesson on Lagrange multipliers.

How to answer#

Work each problem on paper first. Then type your result in the answer box and press Check. A number box wants a decimal number, not a fraction or a square root, and its question says how exact your value must be: keep all the digits your calculator shows while you work. Unless a box asks for more digits, give 3 significant figures in the box; an answer with only 2 significant figures may or may not be accepted. Angles are asked in degrees. A formula box takes plain typing, for example 2/(1 - lam), and accepts every correct way of writing the answer. Type lam for the multiplier λ\lambda. The points, and their split over the parts of a problem, are MIT's. If you are stuck, open the hints one at a time. Each part ends with its full solution. Try before you open it: an answer given after its solution was opened earns no points. Parts that ask you to explain something have a box for only a piece of them: compare the rest of your work with the solution and mark it yourself. Your score is kept in this browser only.

Two parts need a tool that calculates: part (d) of Problem 1 and part (b) of Problem 3. MIT used an applet of its own and MATLAB. Any tool will do here: a spreadsheet, a graphing calculator, a few lines of Python, or an online solver for polynomials.

Problem 1#

Problem

The largest and smallest directional derivative

8 points

The function of this problem is the one MIT also used in Problem 3 of its Problem Set 3 (Problem 3 of our Problem Set 3):

The function of Problem 1
f(x,y)=x3−xy2−4x2+3x+x2yf(x, y) = x^3 - x y^2 - 4x^2 + 3x + x^2 y
In words

f(x, y) equals x cubed minus x y squared minus 4 x squared plus 3 x plus x squared y

Source: MIT 18.02 Problem Set 5, Part B, Problem 1, p. 1

The point is P=(1/2,1)P = (1/2, 1). A direction in the plane is given by a unit vector u^\hat u, and the directional derivative of ff at PP in that direction is written (dfds)u^\left(\frac{df}{ds}\right)_{\hat u}, as in the lesson.

(a)2 points

Find the largest and the smallest value that the directional derivative of ff at PP takes as u^\hat u runs through all directions. Give both as decimals, to four decimal places.

Hint

The lesson writes the directional derivative as a dot product of two vectors, and then with the angle between them. Only one of the two vectors changes when u^\hat u turns.

Hint

Find the two partial derivatives of ff and put in x=1/2x = 1/2, y=1y = 1. The largest value is the length of the gradient.

Solution

The idea. The directional derivative is the component of the gradient along u^\hat u:

Directional derivative and the gradient
(dfds)u^=∇f⋅u^=∣∇f∣cos⁡θ\left(\frac{df}{ds}\right)_{\hat u} = \nabla f \cdot \hat u = |\nabla f|\cos\theta
In words

( d f over d s ) sub u hat equals del f times u hat equals the absolute value of del f cos theta

Source: 18.02 lecture summaries, Week 5 (Prof. Auroux), Lecture 12, pp. 1–2, and Lecture 13, pp. 2–3, Lecture 12, p. 2

where θ\theta is the angle between ∇f\nabla f and u^\hat u. The cosine runs from −1-1 to 11, so the values run from −∣∇f∣-|\nabla f| to ∣∇f∣|\nabla f|.

The partial derivatives

Partial derivatives of f
fx=3x2−y2−8x+3+2xy,fy=−2xy+x2f_x = 3x^2 - y^2 - 8x + 3 + 2xy, \qquad f_y = -2xy + x^2
In words

f sub x equals 3 x squared minus y squared minus 8 x plus 3 plus 2 x y, f sub y equals minus 2 x y plus x squared

Source: MIT 18.02 Problem Set 5, Part B, Problem 1(a) (our own solution)

The gradient at P

At x=1/2x = 1/2, y=1y = 1: fx=34−1−4+3+1=−14f_x = \tfrac34 - 1 - 4 + 3 + 1 = -\tfrac14 and fy=−1+14=−34f_y = -1 + \tfrac14 = -\tfrac34.

Gradient of f at P
∇f=⟨−14,−34⟩,∣∇f∣=116+916=104=0.7906\nabla f = \left\langle -\tfrac14, -\tfrac34 \right\rangle, \qquad |\nabla f| = \sqrt{\tfrac{1}{16} + \tfrac{9}{16}} = \frac{\sqrt{10}}{4} = 0.7906
In words

del f equals the average of minus one quarter, minus three quarters, the absolute value of del f equals the square root of 1 over 16 plus 9 over 16, end of root, equals the square root of 10 over 4 equals 0.7906

Source: MIT 18.02 Problem Set 5, Part B, Problem 1(a) (our own solution)

Largest and smallest

The largest value of the directional derivative is 10/4=0.7906\sqrt{10}/4 = 0.7906 and the smallest is −10/4=−0.7906-\sqrt{10}/4 = -0.7906.

Check the result

Try two simple directions. Along −j^-\hat j the directional derivative is −fy=0.75-f_y = 0.75, and along −i^-\hat i it is −fx=0.25-f_x = 0.25. Both lie between −0.7906-0.7906 and 0.79060.7906, and 0.750.75 is close to the largest value, which fits: the gradient ⟨−14,−34⟩\langle -\tfrac14, -\tfrac34\rangle points mostly along −j^-\hat j.

(b)1 point

Say in which direction u^\hat u the largest value occurs, and in which direction the smallest.

Give each direction as a unit vector. For the boxes, write u^=⟨cos⁡θ,sin⁡θ⟩\hat u = \langle \cos\theta, \sin\theta\rangle, as MIT does in part (d): θ\theta is the angle from the positive xx-axis to u^\hat u, counterclockwise. Give θ\theta in degrees between 0 and 360, to one decimal place. (In this part and the next, θ\theta is this angle of u^\hat u, not the angle between u^\hat u and the gradient.)

Hint

For which angle between ∇f\nabla f and u^\hat u is the cosine equal to 11? And to −1-1?

Hint

Both components of the gradient are negative. In which quarter of the plane does it point? A calculator's inverse tangent only returns angles between −90°-90° and 90°90°.

Solution

The idea. By the lesson, the directional derivative is largest when u^\hat u points along the gradient and smallest when it points the opposite way.

The two unit vectors

Divide the gradient by its length 10/4\sqrt{10}/4:

Directions of the largest and smallest value
largest:u^=∇f∣∇f∣=⟨−1,−3⟩10,smallest:u^=−∇f∣∇f∣=⟨1,3⟩10\text{largest:}\quad \hat u = \frac{\nabla f}{|\nabla f|} = \frac{\langle -1, -3\rangle}{\sqrt{10}}, \qquad \text{smallest:}\quad \hat u = -\frac{\nabla f}{|\nabla f|} = \frac{\langle 1, 3\rangle}{\sqrt{10}}
In words

largest: u hat equals del f over the absolute value of del f equals the quantity the average of minus 1, minus 3, all over the square root of 10, smallest: u hat equals minus del f over the absolute value of del f equals the average of 1, 3 over the square root of 10

Source: MIT 18.02 Problem Set 5, Part B, Problem 1(b) (our own solution)

In decimals, the second one is ⟨0.3162,0.9487⟩\langle 0.3162, 0.9487\rangle.

The angles

The direction of the smallest value, ⟨1,3⟩/10\langle 1, 3\rangle/\sqrt{10}, points into the first quarter of the plane, with tan⁡θ=3\tan\theta = 3, so θ=71.57°\theta = 71.57°, which rounds to 71.6°71.6°. The direction of the largest value points the opposite way, into the third quarter: θ=71.57°+180°=251.57°\theta = 71.57° + 180° = 251.57°, which rounds to 251.6°251.6°.

Check the result

cos⁡251.57°=−0.316\cos 251.57° = -0.316 and sin⁡251.57°=−0.949\sin 251.57° = -0.949, the components of ⟨−1,−3⟩/10\langle -1, -3\rangle/\sqrt{10} to three decimal places. And the dot product of ∇f\nabla f with ⟨−1,−3⟩/10\langle -1, -3\rangle/\sqrt{10} is (14+94)/10=2.5/10=0.7906\big(\tfrac14 + \tfrac94\big)/\sqrt{10} = 2.5/\sqrt{10} = 0.7906, the largest value of part (a).

(c)1 point

Find the direction or directions u^\hat u in which the directional derivative of ff at PP is zero. Give them as unit vectors, and for the boxes as angles θ\theta in degrees, to one decimal place.

Hint

A dot product is zero when the two vectors are perpendicular.

Hint

In the plane, ⟨b,−a⟩\langle b, -a\rangle is perpendicular to ⟨a,b⟩\langle a, b\rangle. How many unit vectors are perpendicular to a given vector?

Solution

The idea. ∇f⋅u^=0\nabla f \cdot \hat u = 0 exactly when u^\hat u is perpendicular to the gradient. In the plane there are two such unit vectors, opposite to each other.

The two unit vectors

The gradient points along ⟨1,3⟩\langle 1, 3\rangle (or against it). The vector ⟨3,−1⟩\langle 3, -1\rangle is perpendicular to it, since 3−3=03 - 3 = 0:

Directions with zero directional derivative
u^=±⟨3,−1⟩10\hat u = \pm\frac{\langle 3, -1\rangle}{\sqrt{10}}
In words

u hat equals plus or minus the average of 3, minus 1 over the square root of 10

Source: MIT 18.02 Problem Set 5, Part B, Problem 1(c) (our own solution)

The angles

These directions are a quarter turn away from the ones of part (b): θ=71.57°+90°=161.57°\theta = 71.57° + 90° = 161.57° for ⟨−3,1⟩/10\langle -3, 1\rangle/\sqrt{10}, and θ=251.57°+90°=341.57°\theta = 251.57° + 90° = 341.57° for ⟨3,−1⟩/10\langle 3, -1\rangle/\sqrt{10}. Rounded: 161.6°161.6° and 341.6°341.6°.

Check the result

∇f⋅⟨3,−1⟩=−34+34=0\nabla f \cdot \langle 3, -1\rangle = -\tfrac34 + \tfrac34 = 0. By the lesson these are the two directions along the level curve of ff through PP: moving along a level curve does not change ff.

(d)4 points

Now find the same answers by experiment. MIT's students used an applet on the course's own website (the "directional derivatives" view of the applets at math.mit.edu/18.02/applets). It shows the contour plot of ff with the level curve through a movable point in blue, the gradient there in purple and a direction u^=⟨cos⁡θ,sin⁡θ⟩\hat u = \langle \cos\theta, \sin\theta\rangle in yellow that can be turned, and it prints the value of the directional derivative. The students clicked as close to (1/2,1)(1/2, 1) as they could. MIT accepts a point such as (0.51,1.01)(0.51, 1.01), as long as the point used is written down.

If you can run that applet, use it as MIT describes. Our version of the experiment, for any tool that calculates, is this. Take the point (x0,y0)=(0.51,1.01)(x_0, y_0) = (0.51, 1.01) and the small step h=0.001h = 0.001, and for a direction angle θ\theta compute

A directional derivative by experiment
Q(θ)=f(x0+hcos⁡θ, y0+hsin⁡θ)−f(x0,y0)hQ(\theta) = \frac{f(x_0 + h\cos\theta,\ y_0 + h\sin\theta) - f(x_0, y_0)}{h}
In words

Q( theta ) equals the quantity f of the quantity x nought plus h cos theta, y nought plus h sine theta, minus f( x nought, y nought ), all over h

Source: MIT 18.02 Problem Set 5, Part B, Problem 1(d) (our own version of the experiment)

This is the change of ff over a short walk of length hh in the direction u^\hat u, divided by the length of the walk: an estimate of the directional derivative at (0.51,1.01)(0.51, 1.01). (The name QQ and the choice of hh are ours.) Let θ\theta run from 0° to 360°, first in large steps and then in steps of 1° near the interesting places. Find the largest and smallest values and the angles at which they occur, and the angles at which the value passes through zero.

Then state, for the directions of parts (b) and (c), how the direction u^\hat u lies with respect to the level curve through the point and to the gradient vector there.

Hint

In a spreadsheet: one column with θ\theta in degrees, one with θ\theta in radians, one with Q(θ)Q(\theta). First compute f(0.51,1.01)f(0.51, 1.01) once.

Hint

The point has moved a little, so the numbers will differ a little from parts (a) to (c). To see whether your experiment is right, compute the gradient at (0.51,1.01)(0.51, 1.01) with the formulas of part (a).

Solution

The idea. The experiment measures the directional derivative without any formula for it. It must agree with ∇f⋅u^\nabla f \cdot \hat u, with the gradient taken at the point actually used.

The experiment

f(0.51,1.01)=0.3647f(0.51, 1.01) = 0.3647. Some values of Q(θ)Q(\theta) with h=0.001h = 0.001:

θ\theta0°69°90°159°160°180°249°250°270°339°340°
Q(θ)Q(\theta)−0.2911-0.2911−0.8237-0.8237−0.7706-0.7706−0.0066-0.00660.00770.00770.28810.28810.82180.82180.82180.82180.76960.76960.00460.0046−0.0098-0.0098

The largest value is about 0.8220.822, near θ=249.5°\theta = 249.5°. The smallest is about −0.824-0.824, near θ=69°\theta = 69° to 70°70°. The value passes through zero between 159° and 160°, and again between 339° and 340°.

Compare with the gradient

With the partial derivatives of part (a), at (0.51,1.01)(0.51, 1.01):

Gradient at the point of the experiment
∇f=⟨−0.2896,−0.7701⟩,∣∇f∣=0.8228\nabla f = \langle -0.2896, -0.7701\rangle, \qquad |\nabla f| = 0.8228
In words

del f equals the average of minus 0.2896, minus 0.7701, the absolute value of del f equals 0.8228

Source: MIT 18.02 Problem Set 5, Part B, Problem 1(d) (our own solution)

The gradient points at the angle θ=249.4°\theta = 249.4°. So the exact answers at this point are: largest value 0.82280.8228 at 249.4°249.4°, smallest value −0.8228-0.8228 at 69.4°69.4°, and zero at 159.4°159.4° and 339.4°339.4°. The experiment agrees to within about 0.0010.001 in the values. That small difference is the price of a step hh that is small but not zero.

The geometry

For part (b): the directional derivative is largest when u^\hat u lies along the gradient vector, and smallest when it points exactly the opposite way. In both cases u^\hat u is at right angles to the level curve through the point.

For part (c): the directional derivative is zero when u^\hat u is tangent to the level curve, in either of its two directions. Then u^\hat u is at right angles to the gradient.

On MIT's applet this reads: largest when the yellow arrow lies on the purple one, zero when the yellow arrow lies along the blue curve.

Check the result

The angles of the experiment fit together as they should: from 69.4°69.4° to 159.4°159.4° to 249.4°249.4° to 339.4°339.4° is a quarter turn each time. Compared with the point (1/2,1)(1/2, 1) of parts (a) to (c), every angle is about 2° smaller (249.4°249.4° against 251.6°251.6°) and the largest value is a little larger (0.82280.8228 against 0.79060.7906): moving the point by 0.010.01 in each coordinate changes the gradient noticeably. That is why MIT asks you to record the point you used.

After: MIT 18.02 Problem Set 5, Part B, Problem 1

Problem 2#

Problem

Downhill to a level surface, by linear approximation

5 points

This problem is about the function of three variables

The function of Problems 2 and 3
g(x,y,z)=x2+yzg(x, y, z) = x^2 + yz
In words

g(x, y, z) equals x squared plus y z

Source: MIT 18.02 Problem Set 5, Part B, Problem 2, p. 1

and the point P0=(2,−1,1)P_0 = (2, -1, 1). (The name P0P_0 is ours.)

(a)2 points

Find the direction from P0P_0 in which gg decreases fastest. Give it as a unit vector.

Hint

The lesson says in which direction a function increases fastest. Where is the directional derivative most negative?

Hint

The gradient of gg has three components, gxg_x, gyg_y and gzg_z. Take care with gyg_y and gzg_z: the derivative of yzyz with respect to yy is zz.

Solution

The idea. The directional derivative ∇g⋅u^=∣∇g∣cos⁡θ\nabla g \cdot \hat u = |\nabla g|\cos\theta is most negative when u^\hat u points opposite to the gradient.

The gradient

Gradient of g
∇g=⟨gx,gy,gz⟩=⟨2x,z,y⟩,∇g(2,−1,1)=⟨4,1,−1⟩\nabla g = \langle g_x, g_y, g_z\rangle = \langle 2x, z, y\rangle, \qquad \nabla g(2, -1, 1) = \langle 4, 1, -1\rangle
In words

del g equals the average of g sub x, g sub y, g sub z equals the average of 2 x, z, y, del g(2, minus 1, 1) equals the average of 4, 1, minus 1

Source: MIT 18.02 Problem Set 5, Part B, Problem 2(a) (our own solution)

Its length is 16+1+1=18=32=4.243\sqrt{16 + 1 + 1} = \sqrt{18} = 3\sqrt 2 = 4.243.

The direction

Direction of fastest decrease
u^=−∇g∣∇g∣=⟨−4,−1,1⟩18\hat u = -\frac{\nabla g}{|\nabla g|} = \frac{\langle -4, -1, 1\rangle}{\sqrt{18}}
In words

u hat equals minus del g over the absolute value of del g equals the quantity the average of minus 4, minus 1, 1, all over the square root of 18

Source: MIT 18.02 Problem Set 5, Part B, Problem 2(a) (our own solution)

Check the result

The directional derivative in this direction is ∇g⋅u^=−(16+1+1)/18=−18=−4.243\nabla g \cdot \hat u = -(16 + 1 + 1)/\sqrt{18} = -\sqrt{18} = -4.243: minus the length of the gradient, the most negative value possible. The vector ⟨−4,1,−1⟩/18\langle -4, 1, -1\rangle/\sqrt{18} would come from the gradient ⟨2x,y,z⟩\langle 2x, y, z\rangle, with gyg_y and gzg_z exchanged.

(b)3 points

At P0P_0 the value of gg is not 2. Follow the straight line from P0P_0 in the direction of part (a), and use the linear approximation to estimate where on it g=2g = 2. That point is an estimate of the point closest to P0P_0 on the surface g=2g = 2.

Do this without a calculator, and write the coordinates as fractions. Then use a calculator to find gg at your point: it should come out reasonably close to 2. For the boxes, turn your fractions into decimals, to four decimal places.

Hint

What is gg at P0P_0? By how much must it change?

Hint

Along the line, after a distance ss, the linear approximation says that gg has changed by about the directional derivative times ss.

Hint

The displacement is the distance ss times the unit vector of part (a). The two square roots multiply to a whole number.

Solution

The idea. Near P0P_0 the function gg is close to its linear approximation, whose level surfaces are planes perpendicular to ∇g\nabla g. The nearest point of such a plane is reached by going straight along the gradient, here against it, because gg must go down.

How far g must change

g(2,−1,1)=4+(−1)(1)=3g(2, -1, 1) = 4 + (-1)(1) = 3. To reach g=2g = 2 the change must be Δg=−1\Delta g = -1.

The distance along the line

A point of the line at distance ss from P0P_0 is P0+s u^P_0 + s\,\hat u. By part (a) the directional derivative along the line is −18-\sqrt{18}, so the linear approximation gives

Linear approximation along the line
Δg≈(dgds)u^s=−18 s=−1⟹s=118\Delta g \approx \left(\frac{dg}{ds}\right)_{\hat u} s = -\sqrt{18}\,s = -1 \quad\Longrightarrow\quad s = \frac{1}{\sqrt{18}}
In words

capital delta g is approximately ( d g over d s ) sub u hat s equals minus the square root of 18 s equals minus 1 which gives s equals 1 over the square root of 18

Source: MIT 18.02 Problem Set 5, Part B, Problem 2(b) (our own solution)

The point

The displacement is s u^=118⋅⟨−4,−1,1⟩18=118⟨−4,−1,1⟩s\,\hat u = \frac{1}{\sqrt{18}} \cdot \frac{\langle -4, -1, 1\rangle}{\sqrt{18}} = \frac{1}{18}\langle -4, -1, 1\rangle:

The estimated point
(x,y,z)≈(2−418, −1−118, 1+118)=(169, −1918, 1918)(x, y, z) \approx \left(2 - \tfrac{4}{18},\ -1 - \tfrac{1}{18},\ 1 + \tfrac{1}{18}\right) = \left(\tfrac{16}{9},\ -\tfrac{19}{18},\ \tfrac{19}{18}\right)
In words

(x, y, z) is approximately the quantity 2 minus 4 over 18, minus 1 minus 1 over 18, 1 plus 1 over 18, equals the quantity 16 over 9, minus 19 over 18, 19 over 18

Source: MIT 18.02 Problem Set 5, Part B, Problem 2(b) (our own solution)

In decimals: (1.7778,−1.0556,1.0556)(1.7778, -1.0556, 1.0556).

The value of g there

The function at the estimated point
g=(169)2−(1918)2=1024324−361324=663324=2.0463g = \left(\tfrac{16}{9}\right)^2 - \left(\tfrac{19}{18}\right)^2 = \tfrac{1024}{324} - \tfrac{361}{324} = \tfrac{663}{324} = 2.0463
In words

g equals ( 16 over 9 ) squared minus ( 19 over 18 ) squared equals 1024 over 324 minus 361 over 324 equals 663 over 324 equals 2.0463

Source: MIT 18.02 Problem Set 5, Part B, Problem 2(b) (our own solution)

Reasonably close to 2, as MIT promises.

Check the result

The error can be found exactly. Write the points of the line as P0−t ∇g=(2−4t,−1−t,1+t)P_0 - t\,\nabla g = (2 - 4t, -1 - t, 1 + t). Then g=(2−4t)2−(1+t)2=3−18t+15t2g = (2 - 4t)^2 - (1 + t)^2 = 3 - 18t + 15t^2. The linear approximation keeps 3−18t3 - 18t, which is 2 at t=118t = \tfrac{1}{18}. The term it drops is 15t2=15324=0.046315t^2 = \tfrac{15}{324} = 0.0463, exactly the amount by which gg misses 2.

After: MIT 18.02 Problem Set 5, Part B, Problem 2

Problem 3#

Problem

The closest point, exactly, with a Lagrange multiplier

6 points

Problem 2(b) estimated the point of the surface x2+yz=2x^2 + yz = 2 that is closest to P0=(2,−1,1)P_0 = (2, -1, 1). Now find that point without the linear approximation.

(a)2 points

Use the method of Lagrange multipliers to write down the system of equations that the closest point satisfies. (MIT's hint: it is easier to minimise the square of the distance.)

Write the multiplier on the side of the constraint, ∇f=λ ∇g\nabla f = \lambda\,\nabla g, as the lesson does.

Hint

What is the square of the distance from (x,y,z)(x, y, z) to (2,−1,1)(2, -1, 1)? That is the function ff to minimise. The constraint is g=2g = 2 with the gg of Problem 2.

Hint

The gradient of gg is in Problem 2(a). Three components give three equations, and the constraint is the fourth.

Solution

The idea. The point that makes the distance smallest also makes its square smallest, and the square has no root in it. Minimise it among the points with g=2g = 2.

The function and the constraint

The constrained problem
minimise f(x,y,z)=(x−2)2+(y+1)2+(z−1)2subject tog(x,y,z)=x2+yz=2\text{minimise } f(x, y, z) = (x - 2)^2 + (y + 1)^2 + (z - 1)^2 \quad\text{subject to}\quad g(x, y, z) = x^2 + yz = 2
In words

minimise f(x, y, z) equals the quantity x minus 2, all squared plus the quantity y plus 1, all squared plus the quantity z minus 1, all squared subject to g(x, y, z) equals x squared plus y z equals 2

Source: MIT 18.02 Problem Set 5, Part B, Problem 3(a) (our own solution)

The Lagrange equations

The lesson's condition is

Lagrange condition
∇f=λ ∇g\nabla f = \lambda\,\nabla g
In words

del f equals lambda del g

Source: 18.02 lecture summaries, Week 5 (Prof. Auroux), Lecture 12, pp. 1–2, and Lecture 13, pp. 2–3, Lecture 13, p. 2

Here ∇f=⟨2(x−2),2(y+1),2(z−1)⟩\nabla f = \langle 2(x - 2), 2(y + 1), 2(z - 1)\rangle and ∇g=⟨2x,z,y⟩\nabla g = \langle 2x, z, y\rangle. Component by component, and with the constraint:

The system for the closest point
2(x−2)=2λx,2(y+1)=λz,2(z−1)=λy,x2+yz=22(x - 2) = 2\lambda x, \qquad 2(y + 1) = \lambda z, \qquad 2(z - 1) = \lambda y, \qquad x^2 + yz = 2
In words

2 the quantity x minus 2, equals 2 lambda x, 2 the quantity y plus 1, equals lambda z, 2 the quantity z minus 1, equals lambda y, x squared plus y z equals 2

Source: MIT 18.02 Problem Set 5, Part B, Problem 3(a) (our own solution)

Check the result

There are four equations for the four unknowns xx, yy, zz and λ\lambda. If λ\lambda were zero, the first three equations would give (x,y,z)=(2,−1,1)(x, y, z) = (2, -1, 1), the point P0P_0 itself. But g=3g = 3 there, so the fourth equation fails: the multiplier is not zero, and the closest point is not P0P_0.

(b)4 points

Solve the equations, and give the closest point to four decimal places. Then compare with Problem 2(b): was each coordinate of the estimate within 1/1001/100 of the exact one?

MIT suggests this route. Add the second and third equations, and show that either z=−yz = -y or λ=2\lambda = 2. In the case z=−yz = -y, use the first three equations to write xx, yy and zz in terms of λ\lambda, and put those into the constraint. After the denominators are cleared, an equation of degree 4 for λ\lambda is left. Solve it with a calculator or a computer. (MIT names MATLAB's command roots; any solver for polynomials does the same.) It should have two real roots. Last, look at the case λ=2\lambda = 2. MIT's sheet says that it gives points further away from P0P_0: see what you find.

The boxes follow this route. Write the equation of degree 4 with the coefficient 11 in front of λ4\lambda^4.

Hint

Add the left sides and the right sides of the second and third equations. Both sides contain y+zy + z.

Hint

With z=−yz = -y the second equation holds only yy and λ\lambda. The first holds only xx and λ\lambda.

Hint

After substituting, multiply the constraint by both squared denominators. The right side becomes the square of a product of two brackets: multiply the two brackets first, then square.

Hint

Each real root gives one point. Compare their distances to P0P_0.

Solution

The idea. The second and third equations are alike with yy and zz exchanged. Adding them splits the problem into two cases, and in the main case everything can be written with λ\lambda alone.

Two cases

Adding 2(y+1)=λz2(y + 1) = \lambda z and 2(z−1)=λy2(z - 1) = \lambda y gives 2(y+z)=λ(y+z)2(y + z) = \lambda(y + z):

The two cases
(2−λ)(y+z)=0⟹z=−yorλ=2(2 - \lambda)(y + z) = 0 \quad\Longrightarrow\quad z = -y \quad\text{or}\quad \lambda = 2
In words

the quantity 2 minus lambda, the quantity y plus z, equals 0 which gives z equals minus y or lambda equals 2

Source: MIT 18.02 Problem Set 5, Part B, Problem 3(b), p. 2

The case z=−yz = -y: everything in terms of λ\lambda

The first equation is x−2=λxx - 2 = \lambda x, so x(1−λ)=2x(1 - \lambda) = 2. With z=−yz = -y the second equation is 2(y+1)=−λy2(y + 1) = -\lambda y, so y(2+λ)=−2y(2 + \lambda) = -2. (Neither bracket can be zero: λ=1\lambda = 1 would turn the first equation into −2=0-2 = 0, and λ=−2\lambda = -2 would turn the second into 2=02 = 0.)

The point in terms of the multiplier
x=21−λ,y=−22+λ,z=22+λx = \frac{2}{1 - \lambda}, \qquad y = -\frac{2}{2 + \lambda}, \qquad z = \frac{2}{2 + \lambda}
In words

x equals 2 over the quantity 1 minus lambda, y equals minus 2 over the quantity 2 plus lambda, z equals 2 over the quantity 2 plus lambda

Source: MIT 18.02 Problem Set 5, Part B, Problem 3(b) (our own solution)

The third equation, 2(z−1)=λy2(z - 1) = \lambda y, becomes −2y−2=λy-2y - 2 = \lambda y with z=−yz = -y: the second equation again, so it adds nothing.

The equation for λ

Put these into the constraint x2+yz=2x^2 + yz = 2, where yz=−y2yz = -y^2:

The constraint in terms of the multiplier
4(1−λ)2−4(2+λ)2=2\frac{4}{(1 - \lambda)^2} - \frac{4}{(2 + \lambda)^2} = 2
In words

4 over the quantity 1 minus lambda, all squared minus 4 over the quantity 2 plus lambda, all squared equals 2

Source: MIT 18.02 Problem Set 5, Part B, Problem 3(b) (our own solution)

Multiply by (1−λ)2(2+λ)2(1 - \lambda)^2(2 + \lambda)^2 and divide by 2. On the left, 2(2+λ)2−2(1−λ)2=2(3+6λ)=6+12λ2(2 + \lambda)^2 - 2(1 - \lambda)^2 = 2(3 + 6\lambda) = 6 + 12\lambda. On the right, (1−λ)(2+λ)=2−λ−λ2(1 - \lambda)(2 + \lambda) = 2 - \lambda - \lambda^2, and its square is λ4+2λ3−3λ2−4λ+4\lambda^4 + 2\lambda^3 - 3\lambda^2 - 4\lambda + 4. Bringing everything to one side:

The equation of degree 4
λ4+2λ3−3λ2−16λ−2=0\lambda^4 + 2\lambda^3 - 3\lambda^2 - 16\lambda - 2 = 0
In words

lambda to the power 4 plus 2 lambda cubed minus 3 lambda squared minus 16 lambda minus 2 equals 0

Source: MIT 18.02 Problem Set 5, Part B, Problem 3(b) (our own solution)

Its real roots and their points

A polynomial solver gives two real roots, λ=−0.1283\lambda = -0.1283 and λ=2.3448\lambda = 2.3448, and two that are not real. With the formulas for xx, yy and zz:

λ\lambdaxxyyzzdistance to P0P_0
−0.1283-0.12831.77251.7725−1.0686-1.06861.06861.06860.24730.2473
2.34482.3448−1.4872-1.4872−0.4603-0.46030.46030.46033.56983.5698

The case λ=2\lambda = 2

With λ=2\lambda = 2 the first equation is x−2=2xx - 2 = 2x, so x=−2x = -2. The second is 2(y+1)=2z2(y + 1) = 2z, so z=y+1z = y + 1 (the third says the same). The constraint becomes 4+y(y+1)=24 + y(y + 1) = 2:

The case with multiplier 2
y2+y+2=0,discriminant 1−8=−7y^2 + y + 2 = 0, \qquad \text{discriminant } 1 - 8 = -7
In words

y squared plus y plus 2 equals 0, discriminant 1 minus 8 equals minus 7

Source: MIT 18.02 Problem Set 5, Part B, Problem 3(b) (our own solution)

The discriminant is negative, so no real yy satisfies it. This case gives no point at all. (MIT's sheet asks to check that this case yields solutions further away. There are none to compare: with λ\lambda multiplying ∇g\nabla g, the convention that makes the two cases come out as z=−yz = -y or λ=2\lambda = 2, the case λ=2\lambda = 2 is empty.)

The closest point

The Lagrange equations have exactly two real solutions, the two rows of the table. The first is the nearer one by far:

The closest point
(x,y,z)=(1.7725, −1.0686, 1.0686),λ=−0.1283,distance 0.2473(x, y, z) = (1.7725,\ -1.0686,\ 1.0686), \qquad \lambda = -0.1283, \qquad \text{distance } 0.2473
In words

(x, y, z) equals the quantity 1.7725, minus 1.0686, 1.0686, lambda equals minus 0.1283, distance 0.2473

Source: MIT 18.02 Problem Set 5, Part B, Problem 3(b) (our own solution)

(Our remark, as the lesson warns that the method does not say which solution is a minimum: a closest point does exist, because points of the surface far from the origin are also far from P0P_0, and it must satisfy the Lagrange equations, because ∇g=⟨2x,z,y⟩\nabla g = \langle 2x, z, y\rangle is zero only at the origin, which is not on the surface. So the closest point is one of the two solutions, and comparing distances picks the first.)

Compare with Problem 2(b)

The estimate was (1.7778,−1.0556,1.0556)(1.7778, -1.0556, 1.0556). The differences from the exact point are 0.00530.0053 in xx and 0.01300.0130 in yy and in zz. So xx was within 1/1001/100, and yy and zz were not, though they missed by only a little more. The estimate went straight along the gradient at P0P_0, but the surface is curved, and the line from P0P_0 to the true closest point is perpendicular to the surface at that point, not at P0P_0.

Check the result

The point is on the surface: 1.77252−1.06862=3.1418−1.1419=1.99991.7725^2 - 1.0686^2 = 3.1418 - 1.1419 = 1.9999, which is 2 up to the rounding of the coordinates. The two gradients are parallel there: ∇f=⟨−0.4550,−0.1372,0.1372⟩\nabla f = \langle -0.4550, -0.1372, 0.1372\rangle and ∇g=⟨3.5450,1.0686,−1.0686⟩\nabla g = \langle 3.5450, 1.0686, -1.0686\rangle, and the ratios −0.4550/3.5450-0.4550/3.5450 and −0.1372/1.0686-0.1372/1.0686 are both −0.128-0.128, the multiplier. The distance 0.24730.2473 is a little more than the 1/18=0.23571/\sqrt{18} = 0.2357 of the linear estimate. That fits: along the line of Problem 2(b) the estimated point, with g=2.0463g = 2.0463, had not yet reached the surface.

After: MIT 18.02 Problem Set 5, Part B, Problem 3

More practice: MIT's own solved exercises#

Part A of MIT's Problem Set 5 (8 points at MIT, not scored here) is a list of short exercises from the problems section of MIT's "18.02 Supplementary Notes and Problems", which is on MIT OpenCourseWare under the same licence as the rest of the course, with solutions to the exercises that are not marked with a star. They are not rewritten here: open the exercises (section 2, Partial differentiation), try them, then compare with MIT's solutions.

An exercise number such as 2D-3 means section 2, group D, exercise 3; the letters after it are its parts. MIT assigned these, lecture by lecture (with this site's lecture numbers):

ForExercises in section 2 of the Notes
Lecture 12: the gradient, directional derivatives and tangent planes2D-1a, b, e, 2D-2b, 2D-3a, c, 2D-8, 2D-9; 2E-7
Lecture 13: Lagrange multipliers2I-1, 2I-3

MIT's list also names sections of the course textbook to read (Edwards and Penney, Multivariable Calculus, 6th edition). The textbook is not openly licensed and is not used on this site, so they are not part of this page.

Symbols on this page

Show the 37 symbols used here
Δ\Delta capital delta.
A change or difference in a quantity, e.g. Δx = x₂ − x₁. Say it: “capital delta”.
θ\theta theta.
In the lesson's formula |∇f| cos θ, the angle between the gradient and û. In the boxes of Problem 1, the angle from the positive x-axis to û = ⟨cos θ, sin θ⟩, counterclockwise. Unit: degrees. Say it: “theta” (sounds like “thay-ta or thee-ta”).
λ\lambda lambda.
The Lagrange multiplier of Problem 3: the number with ∇f = λ∇g. Say it: “lambda”.
≈\approx approximately equal.
Is approximately equal to. Say it: “is approximately”.
⇒\Rightarrow implies.
Implies: what follows is a consequence of what came before. Say it: “which gives”.
±\pm plus or minus.
Plus or minus: both signs, or an uncertainty (67.3 ± 1.2). Say it: “plus or minus”.
⋅\cdot dot.
Times (multiplication). Between two vectors: the dot product. Say it: “times”.
⟨\langle angle brackets.
The average (mean value) of what is inside, ⟨…⟩. Say it: “the average of”.
∇\nabla nabla (del).
Del: ∇f is the gradient, ∇·v the divergence, ∇×v the curl, ∇² the Laplacian. Say it: “del”.
sin⁡\sin sine.
Sine of an angle. Say it: “sine”.
cos⁡\cos cosine.
Cosine of an angle. Say it: “cos”.
tan⁡\tan tangent.
Tangent of an angle, sin/cos. Say it: “tan”.
ı^\hat\imath hat.
A unit vector: a vector of length 1 that only gives a direction (î, r̂). Say it: “hat”.
aa a.
In a hint of Problem 1(c), the first component of a vector ⟨a, b⟩ in the plane. Say it: “a”.
zz z.
The z coordinate, the third variable of g. Say it: “z”.
xx x.
The x coordinate, the first variable of f and of g. Say it: “x”.
yy y.
The y coordinate, the second variable of f and of g. Say it: “y”.
tt t.
In the check of Problem 2(b), the parameter of the line through P₀ against the gradient: the point is P₀ − t∇g. Say it: “t”.
dd d.
The d of a derivative, as in df/ds and dg/ds. Say it: “d”.
ff f.
In Problem 1, the function f(x, y) = x³ − xy² − 4x² + 3x + x²y. In Problem 3, the square of the distance to the point (2, −1, 1), the function to be minimised. Say it: “f”.
gg g.
The function g(x, y, z) = x² + yz of Problems 2 and 3; in Problem 3 the constraint is g = 2. Say it: “g”.
PP P.
The point (1/2, 1) of Problem 1. Say it: “P”.
QQ Q.
Our name for the difference quotient of Problem 1(d): the change of f over a short walk of length h in the direction at angle θ, divided by h. Say it: “Q”.
bb b.
In a hint of Problem 1(c), the second component of a vector ⟨a, b⟩ in the plane. Say it: “b”.
ss s.
Distance travelled along a straight line in the direction û. Say it: “s”.
hh h.
The small step of the experiment in Problem 1(d), 0.001. Say it: “h”.
x0x_{0} x nought.
The x coordinate of the point of the experiment in Problem 1(d), 0.51. Say it: “x nought”.
y0y_{0} y nought.
The y coordinate of the point of the experiment in Problem 1(d), 1.01. Say it: “y nought”.
uu u.
With a hat, û: a unit vector giving the direction of the directional derivative. Say it: “u”.
P0P_{0} processed power spectrum.
Our name for the point (2, −1, 1) of Problems 2 and 3. Say it: “P nought”.
i^\hat{i} i hat.
Unit vector in the x direction: length 1, pointing towards increasing x. Say it: “i hat”.
j^\hat{j} j hat.
Unit vector in the y direction: length 1, pointing towards increasing y. Say it: “j hat”.
fxf_{x} f sub x.
The partial derivative ∂f/∂x, with y held fixed. Say it: “f sub x”.
fyf_{y} f sub y.
The partial derivative ∂f/∂y, with x held fixed. Say it: “f sub y”.
gxg_{x} g sub x.
The partial derivative ∂g/∂x = 2x. Say it: “g sub x”.
gyg_{y} g sub y.
The partial derivative ∂g/∂y = z. Say it: “g sub y”.
gzg_{z} g sub z.
The partial derivative ∂g/∂z = y. Say it: “g sub z”.

Tap or click a symbol in a formula to see the same explanation. All symbols: symbols and notation.

Words on this page

Show the 30 words used here

Also used

gradient.
The vector of a function's partial derivatives; it points the way the function increases fastest, and its length is that fastest rate. Explained in Graphs, straight lines and slope.
directional derivative.
The rate at which a function changes as one moves from a point in a chosen direction, per unit distance travelled. Explained in The gradient and directional derivatives.
Lagrange multipliers.
A method for finding the largest or smallest value of a function when its variables must satisfy a constraint. Explained in A ring on a string, and Newton's method.
tangent plane.
The flat plane that just touches a surface at a point and tilts the same way as the surface there. Explained in Tangent planes, critical points and least squares.
MIT.
Massachusetts Institute of Technology: the university in Cambridge, USA, whose free courses this site rewrites.
unit vector.
A vector of length one, used only to point in a direction. Explained in Newton's law of gravitation.
dot product.
A way of multiplying two vectors that gives a number: multiply matching components and add, or lengths times the cosine of the angle between them. Explained in Vectors and the dot product.
vector.
A quantity with both a size and a direction, such as a velocity or a force, drawn as an arrow. Explained in Vectors.
partial derivative.
The rate of change of a function of several variables with respect to one of them, while all the others are held fixed. Explained in Functions of two variables and partial derivatives.
inverse tangent.
The function that undoes the tangent: arctan x is the angle, between −90 and 90 degrees, whose tangent is x.
perpendicular.
At right angles to a line, a surface or another direction. Explained in Inclined planes.
level curve.
A curve along which a function of two variables keeps the same value, like a line of equal height on a map. Explained in Functions of two variables and partial derivatives.
contour map.
A flat map of a function of two variables, drawing the curves along which it keeps one value, like height lines on a hiking map. Explained in Fields: scalar, vector, gravitational and electric.
with respect to.
Taking that variable as the one that changes: a derivative with respect to t measures change as t changes, others held fixed. Explained in Average value, weighted averages and probability.
radian.
The natural unit of angle: the angle whose arc on a circle is as long as the radius. A full turn is 2π radians. Explained in Angles, radians and trigonometry.
tangent.
A straight line that touches a curve at a point and runs in the same direction as the curve there. Explained in Angles, radians and trigonometry.
derivative.
The rate at which a function changes as its input changes: the slope of its graph at a point. Explained in Position and velocity in one dimension.
linear approximation.
Replacing a function near a point by the straight line, or flat plane, that best matches it there, using its first derivatives. Explained in Change of variables in double integrals.
displacement.
The change in position from start to finish: how far and in which direction, ignoring the route in between. Explained in Vectors.
constraint.
A condition that limits what is allowed, such as a rope of fixed length that links the motions of the bodies it joins. Explained in Tension in ropes and the spring force.
linear.
Of a relation or equation: using only first powers of the unknowns, so doubling the cause doubles the effect and effects simply add. Explained in Solving and rearranging formulas.
differentiation.
Finding a derivative: working out how fast a function changes. Explained in The derivative: slope of the tangent line and rate of change.

Academic

problem set.
A weekly sheet of exercises that students work through and hand in, to practise what the lectures taught.
on paper.
In theory or in a calculation, as opposed to in a real experiment or in reality.
significant.
Large enough to matter or to be noticed; in statistics, too large to put down to chance.
to within.
With an error no larger than the stated amount.
error.
The difference between a measured or computed value and the true one; often how large that difference may be.
satisfy.
To make an equation or condition true.
yield.
To give or produce as a result.
convention.
An agreed choice, such as which direction counts as positive, that could have been made differently.

Tap or click a word, here or in the text, for its meaning in this lesson. All words: the glossary. How many words are marked in the text: Reading options (the “Aa” button).

Credits and license

This page is a rewritten explanation based on MIT 18.02 Problem Set 5 from MIT 18.02 Multivariable Calculus (Fall 2007), taught by Prof. Denis Auroux, published on MIT OpenCourseWare under CC BY-NC-SA 4.0.

MIT readings used: 18.02 lecture summaries, Week 5 (Prof. Auroux) (Lecture 12, pp. 1–2, and Lecture 13, pp. 2–3).

MIT and the instructors do not endorse this site. All diagrams and plots on this page are generated by this site. This page is licensed CC BY-NC-SA 4.0: you may share and adapt it for non-commercial use with attribution, under the same license.