Directional Derivatives & The Gradient

1388 words
7 min read
Python Week 1: the first filter for runtime behavior
Visual companion
Python
Type and operator map

Python Week 1: the first filter for runtime behavior

View
Revision summary

What this note is really saying

Short form

# Directional Derivatives & The Gradient ## ๐ŸŽฏ Learning Objectives After this topic you will be able to: - Compute the gradient vector $\nabla f$ of a multivariable function - Find the directional derivative in any direction - Determine the direction of steepest ascent/descent - Use the gradient to find tangent plan...

Directional Derivatives & The Gradient

๐ŸŽฏ Learning Objectives

After this topic you will be able to:
  • Compute the gradient vector โˆ‡f\nabla f of a multivariable function
  • Find the directional derivative in any direction
  • Determine the direction of steepest ascent/descent
  • Use the gradient to find tangent planes
  • Understand the relationship โˆ‡f\nabla f points in the direction of greatest increase

๐Ÿ“‹ Prerequisites

  • Partial Derivatives (this week) โ€” components of the gradient
  • Dot Product (Week 1) โ€” directional derivative = โˆ‡fโ‹…u\nabla f \cdot \mathbf{u}
  • The gradient is the vector calculus generalisation of the derivative

1. Intuition: Which Way is Up?

Imagine you're on a hillside. The gradient tells you:
  • Which direction is steepest uphill (the gradient direction)
  • How steep it is (the gradient magnitude) A directional derivative answers: if I walk in a specific direction, how fast does the elevation change? (Diagram)

2. The Gradient Vector

Definition (Gradient). For f:Rnโ†’Rf: \mathbb{R}^n \to \mathbb{R}, the gradient is the vector of all first partial derivatives:
>โˆ‡f=(โˆ‚fโˆ‚x1,โˆ‚fโˆ‚x2,โ€ฆ,โˆ‚fโˆ‚xn)>> \nabla f = \left(\frac{\partial f}{\partial x_1}, \frac{\partial f}{\partial x_2}, \dots, \frac{\partial f}{\partial x_n}\right) >
Example 1: Gradient of f(x,y,z)=x2y+ezf(x,y,z) = x^2y + e^z
>โˆ‡f=(2xy,x2,ez)>> \nabla f = (2xy, x^2, e^z) >

2.1 Properties of the Gradient

PropertyStatement
Directional derivativeDuf=โˆ‡fโ‹…uD_{\mathbf{u}} f = \nabla f \cdot \mathbf{u} (for unit u\mathbf{u} )
Steepest ascentDirection of โˆ‡f\nabla f
Steepest descentDirection of โˆ’โˆ‡f-\nabla f
Rate of steepest ascent$\
Level setsโˆ‡f\nabla f is perpendicular to level curves/surfaces

3. Directional Derivatives

3.1 Definition

Definition (Directional Derivative). The directional derivative of ff at x\mathbf{x} in the direction of unit vector u\mathbf{u} is:
>Duf(x)=limโกhโ†’0f(x+hu)โˆ’f(x)h=โˆ‡f(x)โ‹…u>> D_{\mathbf{u}} f(\mathbf{x}) = \lim_{h \to 0} \frac{f(\mathbf{x} + h\mathbf{u}) - f(\mathbf{x})}{h} = \nabla f(\mathbf{x}) \cdot \mathbf{u} >
Important: u\mathbf{u} must be a unit vector. If given a non-unit direction v\mathbf{v}, use u=vโˆฅvโˆฅ\mathbf{u} = \frac{\mathbf{v}}{\|\mathbf{v}\|}.
Example 2: Directional derivative
f(x,y)=x2+y2f(x,y) = x^2 + y^2 at (1,2)(1,2) in direction (3,4)(3,4).
โˆ‡f=(2x,2y)\nabla f = (2x, 2y), so โˆ‡f(1,2)=(2,4)\nabla f(1,2) = (2,4).
Direction v=(3,4)\mathbf{v} = (3,4), unit vector u=(3,4)5=(35,45)\mathbf{u} = \frac{(3,4)}{5} = \left(\frac{3}{5}, \frac{4}{5}\right).
Duf=(2,4)โ‹…(35,45)=65+165=225=4.4D_{\mathbf{u}} f = (2,4) \cdot \left(\frac{3}{5}, \frac{4}{5}\right) = \frac{6}{5} + \frac{16}{5} = \frac{22}{5} = 4.4.

3.2 Steepest Ascent and Descent

The maximum value of DufD_{\mathbf{u}} f is โˆฅโˆ‡fโˆฅ\|\nabla f\|, achieved when u\mathbf{u} points in the direction of โˆ‡f\nabla f.
Example 3: Steepest ascent
f(x,y)=x2+y2f(x,y) = x^2 + y^2 at (1,2)(1,2): โˆ‡f(1,2)=(2,4)\nabla f(1,2) = (2,4). Direction of steepest ascent: (2,4)20=(15,25)\frac{(2,4)}{\sqrt{20}} = \left(\frac{1}{\sqrt{5}}, \frac{2}{\sqrt{5}}\right). Rate of steepest ascent: โˆฅโˆ‡fโˆฅ=4+16=20โ‰ˆ4.47\|\nabla f\| = \sqrt{4+16} = \sqrt{20} \approx 4.47. Direction of steepest descent: โˆ’(15,25)-\left(\frac{1}{\sqrt{5}}, \frac{2}{\sqrt{5}}\right).

4. Gradient and Level Sets

Theorem. The gradient โˆ‡f\nabla f at a point is perpendicular to the level set (contour) passing through that point. This is why โˆ‡f\nabla f gives the normal vector to the tangent plane of f(x,y,z)=cf(x,y,z) = c. Example 4: Gradient perpendicular to level curve
f(x,y)=x2+y2f(x,y) = x^2 + y^2 at (1,1)(1,1). Level curve through (1,1)(1,1): x2+y2=2x^2 + y^2 = 2 (a circle). โˆ‡f(1,1)=(2,2)\nabla f(1,1) = (2,2), which points outward from the circle, perpendicular to it โœ“.

5. Tangent Planes via Gradient

For a surface defined implicitly by F(x,y,z)=0F(x,y,z) = 0, the tangent plane at x0\mathbf{x}_0 is:
โˆ‡F(x0)โ‹…(xโˆ’x0)=0\nabla F(\mathbf{x}_0) \cdot (\mathbf{x} - \mathbf{x}_0) = 0
For z=f(x,y)z = f(x,y), define F(x,y,z)=zโˆ’f(x,y)=0F(x,y,z) = z - f(x,y) = 0, then:
โˆ‡F=(โˆ’fx,โˆ’fy,1)\nabla F = (-f_x, -f_y, 1)
Tangent plane: zโˆ’z0=fx(x0,y0)(xโˆ’x0)+fy(x0,y0)(yโˆ’y0)z - z_0 = f_x(x_0,y_0)(x-x_0) + f_y(x_0,y_0)(y-y_0).

6. Edge Cases & Gotchas

SituationWhat Happens
** โˆ‡f=0\nabla f = \mathbf{0} **Critical point โ€” no direction of increase
Direction not unit lengthMust normalise first
Function not differentiableDirectional derivative may not exist in all directions

7. Common Pitfalls

โŒ Pitfall 1: Forgetting to normalise the direction vector

Duf=โˆ‡fโ‹…uD_{\mathbf{u}} f = \nabla f \cdot \mathbf{u} only works when โˆฅuโˆฅ=1\|\mathbf{u}\| = 1. If given (3,4)(3,4), normalise to (3/5,4/5)(3/5, 4/5).

โŒ Pitfall 2: Thinking โˆ‡f\nabla f points uphill at the same rate everywhere

The gradient changes from point to point. โˆ‡f(1,2)\nabla f(1,2) and โˆ‡f(3,4)\nabla f(3,4) are different.

โŒ Pitfall 3: Confusing gradient with directional derivative

The gradient is a vector of partial derivatives; the directional derivative is a scalar (rate of change in a specific direction).

8. Formula Summary Table

ConceptFormula
Gradientโˆ‡f=(fx1,fx2,โ€ฆ,fxn)\nabla f = (f_{x_1}, f_{x_2}, \dots, f_{x_n})
Directional derivativeDuf=โˆ‡fโ‹…uD_{\mathbf{u}} f = \nabla f \cdot \mathbf{u} ( $\
Max directional derivative$\
Min directional derivative$-\
Tangent planeโˆ‡F(x0)โ‹…(xโˆ’x0)=0\nabla F(\mathbf{x}_0) \cdot (\mathbf{x} - \mathbf{x}_0) = 0

9. ๐Ÿ“ Practice Questions

Q1: Gradient computation
f(x,y)=3x2yโˆ’y3f(x,y) = 3x^2y - y^3. Find โˆ‡f\nabla f.
Solution: โˆ‡f=(6xy,3x2โˆ’3y2)\nabla f = (6xy, 3x^2 - 3y^2). Q2: Directional derivative
f(x,y)=xeyf(x,y) = xe^y at (2,0)(2,0) in direction toward (5,4)(5,4).
Solution: โˆ‡f=(ey,xey)\nabla f = (e^y, xe^y), โˆ‡f(2,0)=(1,2)\nabla f(2,0) = (1, 2). Direction v=(5โˆ’2,4โˆ’0)=(3,4)\mathbf{v} = (5-2, 4-0) = (3,4), โˆฅvโˆฅ=5\|\mathbf{v}\| = 5, u=(3/5,4/5)\mathbf{u} = (3/5, 4/5). Duf=(1,2)โ‹…(3/5,4/5)=3/5+8/5=11/5=2.2D_{\mathbf{u}} f = (1,2) \cdot (3/5, 4/5) = 3/5 + 8/5 = 11/5 = 2.2. Q3: Steepest ascent
f(x,y)=sinโก(xy)f(x,y) = \sin(xy) at (ฯ€/2,1)(\pi/2, 1). Find direction of steepest ascent.
Solution: โˆ‡f=(ycosโก(xy),xcosโก(xy))\nabla f = (y\cos(xy), x\cos(xy)). At (ฯ€/2,1)(\pi/2, 1): โˆ‡f=(1โ‹…cosโก(ฯ€/2),(ฯ€/2)cosโก(ฯ€/2))=(1โ‹…0,(ฯ€/2)โ‹…0)=(0,0)\nabla f = (1\cdot\cos(\pi/2), (\pi/2)\cos(\pi/2)) = (1\cdot 0, (\pi/2)\cdot 0) = (0,0). โˆ‡f=0\nabla f = \mathbf{0}! This is a critical point. There's no direction of increase. Q4: Rate of change
In what direction does f(x,y)=x2โˆ’y2f(x,y) = x^2 - y^2 increase most rapidly at (1,2)(1,2)? What's the rate?
Solution: โˆ‡f=(2x,โˆ’2y)\nabla f = (2x, -2y), โˆ‡f(1,2)=(2,โˆ’4)\nabla f(1,2) = (2, -4). Direction: (2,โˆ’4)20=(15,โˆ’25)\frac{(2,-4)}{\sqrt{20}} = \left(\frac{1}{\sqrt{5}}, -\frac{2}{\sqrt{5}}\right). Rate: โˆฅโˆ‡fโˆฅ=20=25\|\nabla f\| = \sqrt{20} = 2\sqrt{5}. Q5: Gradient perpendicular to level set
For f(x,y)=x2+y2f(x,y) = x^2 + y^2, show โˆ‡f\nabla f is perpendicular to the level curve at (1,1)(1,1).
Solution: โˆ‡f(1,1)=(2,2)\nabla f(1,1) = (2,2). Level curve: x2+y2=2x^2 + y^2 = 2. Tangent vector to level curve: differentiate implicitly: 2x+2yyโ€ฒ=0โ‡’yโ€ฒ=โˆ’x/y=โˆ’12x + 2y y' = 0 \Rightarrow y' = -x/y = -1 at (1,1)(1,1). Tangent direction: (1,โˆ’1)(1,-1). Dot product: (2,2)โ‹…(1,โˆ’1)=2โˆ’2=0(2,2)\cdot(1,-1) = 2-2 = 0 โœ“. Q6: Tangent plane
Find the tangent plane to z=x2+3xy+y2z = x^2 + 3xy + y^2 at (1,1,5)(1,1,5).
Solution: fx=2x+3yf_x = 2x + 3y, fx(1,1)=5f_x(1,1) = 5. fy=3x+2yf_y = 3x + 2y, fy(1,1)=5f_y(1,1) = 5. zโˆ’5=5(xโˆ’1)+5(yโˆ’1)z - 5 = 5(x-1) + 5(y-1) โ‡’ z=5x+5yโˆ’5z = 5x + 5y - 5. Q7: Direction of no change
For f(x,y)=x2+y2f(x,y) = x^2 + y^2 at (1,2)(1,2), find a direction where the directional derivative is 0.
Solution: We need โˆ‡fโ‹…u=0\nabla f \cdot \mathbf{u} = 0. โˆ‡f(1,2)=(2,4)\nabla f(1,2) = (2,4). A perpendicular vector: u=(โˆ’4,2)20=(โˆ’25,15)\mathbf{u} = \frac{(-4,2)}{\sqrt{20}} = \left(-\frac{2}{\sqrt{5}}, \frac{1}{\sqrt{5}}\right). Check: (2,4)โ‹…(โˆ’2/5,1/5)=(โˆ’4+4)/5=0(2,4)\cdot(-2/\sqrt{5}, 1/\sqrt{5}) = (-4+4)/\sqrt{5} = 0 โœ“. Q8: Gradient in 3D
f(x,y,z)=xyzf(x,y,z) = xyz. Find โˆ‡f(1,2,3)\nabla f(1,2,3) and the directional derivative toward (2,1,0)(2,1,0).
Solution: โˆ‡f=(yz,xz,xy)\nabla f = (yz, xz, xy), โˆ‡f(1,2,3)=(6,3,2)\nabla f(1,2,3) = (6, 3, 2). Direction: v=(2โˆ’1,1โˆ’2,0โˆ’3)=(1,โˆ’1,โˆ’3)\mathbf{v} = (2-1, 1-2, 0-3) = (1,-1,-3), โˆฅvโˆฅ=11\|\mathbf{v}\| = \sqrt{11}. u=(1/11,โˆ’1/11,โˆ’3/11)\mathbf{u} = (1/\sqrt{11}, -1/\sqrt{11}, -3/\sqrt{11}). Duf=(6,3,2)โ‹…(1/11,โˆ’1/11,โˆ’3/11)=(6โˆ’3โˆ’6)/11=โˆ’3/11D_{\mathbf{u}} f = (6,3,2)\cdot(1/\sqrt{11}, -1/\sqrt{11}, -3/\sqrt{11}) = (6 - 3 - 6)/\sqrt{11} = -3/\sqrt{11}. Q9: Maximum rate of change
Find the maximum rate of change of f(x,y,z)=xlnโก(yz)f(x,y,z) = x\ln(yz) at (1,1,1)(1,1,1).
Solution: โˆ‡f=(lnโก(yz),x/z,x/y)\nabla f = (\ln(yz), x/z, x/y). At (1,1,1)(1,1,1): โˆ‡f=(0,1,1)\nabla f = (0, 1, 1). Maximum rate = โˆฅโˆ‡fโˆฅ=0+1+1=2\|\nabla f\| = \sqrt{0+1+1} = \sqrt{2}. Q10: Gradient descent direction
If you're at (2,1)(2,1) on f(x,y)=x2+2y2f(x,y) = x^2 + 2y^2, which direction should you move to descend most steeply?
Solution: โˆ‡f=(2x,4y)\nabla f = (2x, 4y), โˆ‡f(2,1)=(4,4)\nabla f(2,1) = (4,4). Direction of steepest descent = โˆ’โˆ‡f=(โˆ’4,โˆ’4)-\nabla f = (-4,-4), or unit vector (โˆ’12,โˆ’12)\left(-\frac{1}{\sqrt{2}}, -\frac{1}{\sqrt{2}}\right).

๐Ÿ”— Cross-References

Document outline

Keep your place and jump directly to a heading.

Table of contents

No note selected

Open a chapter to see its outline, backlinks, and sources here.