Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
148 views
ubuntu2204
Kernel: SageMath 10.1

Directional Derivatives, Gradient Vectors, Tangent Planes and Differential

Directional derivatives and gradient vectors

Definition

The derivative of ff at P0(x0,y0)P_0(x_0,y_0) in the direction of the unit vector u=u1i+u2j\vec{u}=u_1\vec{i}+u_2\vec{j} is the number (dfds)u,P0=lims0f(x0+su1,y0+su2)f(x0,y0)s,\left({df\over ds}\right)_{\vec{u},P_0}=\lim_{s\rightarrow 0}{f(x_0+su_1,y_0+su_2)-f(x_0,y_0)\over s}, provided the limit exists.

The directional derivative is also denoted as ParseError: KaTeX parse error: Got function '\vec' with no arguments as subscript at position 4: (D_\̲v̲e̲c̲{u}f)_{P_0}.

Example

Find the derivative of f(x,y)=x2+xyf(x,y)=x^2+xy at P0(1,2)P_0(1,2) in the direction of the unit vector u=(1/2)i+(1/2)j\vec{u}=(1/\sqrt{2})\vec{i}+(1/\sqrt{2})\vec{j}.

reset() var('x,y,u1,u2,s') f(x,y) = x^2 + x*y # choose direction of a unit vector u = u1*i+ u2*j u1 = 1/sqrt(2) u2 = 1/sqrt(2) # choose a point P_0(x0,y0) x0 = 1 y0 = 2 show(limit((f(x0 + s*u1,y0+s*u2)-f(x0,y0))/s, s=0)) # find the derivative of f(x,y) at P0 in the direction of the unit vector u.

522\displaystyle \frac{5}{2} \, \sqrt{2}

Gradient

Definition

The gradient vector (gradient) of f(x,y)f(x,y) at a point P0(x0,y0)P_0(x_0,y_0) is the vector f=fxi+fyj\nabla f ={\partial f\over \partial x}\vec{i}+{\partial f\over \partial y}\vec{j} obtained by evaluating the partial derivatives of ff at P0P_0.

Theorem

If f(x,y)f(x,y) is differentiable in an open region containing P0(x0,y0)P_0(x_0,y_0), then (dfds)u,P0=(f)P0u,\left({df\over ds}\right)_{\vec{u},P_0}=(\nabla f)_{P_0}\cdot \vec{u}, the dot product of the gradient f\nabla f at P0P_0 and u\vec{u}. In brief, ParseError: KaTeX parse error: Got function '\vec' with no arguments as subscript at position 3: D_\̲v̲e̲c̲{u} f=\nabla f\….

Example

Find the derivative of f(x,y)=x2+xyf(x,y)=x^2+xy at P0(1,2)P_0(1,2) in the direction of the unit vector u=i+j\vec{u}=\vec{i}+\vec{j}.

reset() var('x,y') f(x,y) = x^2+x*y # specify a point P0 x0 = 1 y0 = 2 # choose a vector showing direction v = vector([1,1]) u = v/v.norm() # find the unit vector of the direction fx(x,y)=f.diff(x) fy(x,y)=f.diff(y) Grad_f(x,y) = vector([fx(x,y),fy(x,y)]) # Gradient of f at (x,y) Grad = Grad_f(x0,y0) # calculate gradient of f at P0 print("The Gradient of f at P0 is: ") show(Grad) Df = Grad.dot_product(u) # calculate the directional derivative using Theorem 9 print("The derivative of f at P0 in the direction of vector v is: ") show(Df)
The Gradient of f at P0 is:

(4,1)\displaystyle \left(4,\,1\right)

The derivative of f at P0 in the direction of vector v is:

522\displaystyle \frac{5}{2} \, \sqrt{2}

Properties of the directional derivative

Note that Duf=fu=fcos(θ)D_{\vec{u}}f=\nabla f\cdot \vec{u}=|\nabla f|\cos(\theta) because u=1|\vec{u}|=1.

  • The function ff increases most rapidly when cos(θ)=1\cos(\theta)=1 or when θ=0\theta=0 and u\vec{u} is the direction of f\nabla f. The direction derivative is f|\nabla f|.

  • The function ff decreases most rapidly in the direction of f-\nabla f, whose directional derivative is f-|\nabla f|.

  • Any direction u\vec{u} orthogonal to a gradient f0\nabla f\neq \vec{0} is a direction of zero change in ff because the directional derivative is 0.

Gradients and tangents to level curves

If a differentiable function f(x,y)f(x, y) has a constant value cc along a smooth curve r=g(t)i+h(t)j,\vec{r} = g(t)\vec{i} + h(t)\vec{j}, at every point (x0,y0)(x_0, y_0) in the domain of a differentiable function f(x,y)f(x, y), the gradient of ff is normal to the level curve through (x0,y0)(x_0, y_0).

Tanget Line to a Level Curve

fx(x0,y0)(xx0)+fy(x0,y0)(yy0)=0.f_x(x_0, y_0)(x - x_0) + f_y(x_0,y_0)(y - y_0) = 0.

Example

Find an equation for the tangent line to the ellipse x24+y2=2{x^2\over 4}+y^2=2 at the point (2,1)(-2,1).

# Hint:The ellipse is a level curve of the function f(x,y)=x^2/4+y^2 reset() var('x,y') f(x,y)=x^2/4+y^2 # specify a level curve x0 = -2 # specify P_0 y0 = 1 fx(x,y)=f.diff(x) fy(x,y)=f.diff(y) Grad_f(x,y) = vector([fx(x,y),fy(x,y)]) # Gradient of f at (x,y) Grad = Grad_f(x0,y0) # calculate gradient of f at P_0(x0,y0) print("The Gradient of f at P0 is: ") show(Grad) print("The tangent to the graph at P0 is the line:") show(Grad[0]*(x-x0)+Grad[1]*(y-y0) == 0) # Find the tangent line to the level curve
The Gradient of f at P0 is:

(1,2)\displaystyle \left(-1,\,2\right)

The tangent to the graph at P0 is the line:

x+2y4=0\displaystyle -x + 2 \, y - 4 = 0

Algebra rules for gradient

  • Sum rule: (f+g)=f+g\nabla (f+g) = \nabla f + \nabla g

  • Difference rule: (fg)=fg\nabla (f-g) = \nabla f - \nabla g

  • Constant multiple rule: (kf)=ff\nabla (kf) = f\nabla f, for any kRk\in \R.

  • Product rule: (fg)=fg+gf\nabla (fg) = f\nabla g+ g\nabla f

  • Quotient rule: (fg)=gffgg2\nabla \left({f\over g}\right) = {g\nabla f-f\nabla g\over g^2}, when g0g\neq 0.

Functions of Three Variables

Find the derivative of f(x,y,z)=x3xy2zf(x,y,z)=x^3-xy^2-z at P0(1,1,0)P_0(1,1,0) in the direction of v=2i3j+6k\vec{v}=2\vec{i}-3\vec{j}+6\vec{k}. In what directions do ff change most rapidly at P0P_0, and what is the rate of change in these directions?

reset() var('x,y,z') f(x,y,z)=x^3-x*y^2-z x0 = 1 # specify P_0 y0 = 1 z0 = 0 vi = 2 # specify a direction vector v vj = -3 vk = 6 v = vector([vi,vj,vk]) u = v/v.norm() # calculate the directional unit vector fx(x,y)=f.diff(x) fy(x,y)=f.diff(y) fz(x,y)=f.diff(z) Grad_f(x,y) = vector([fx(x,y),fy(x,y),fz(x,y)]) # Gradient of f at (x,y,z) Grad = Grad_f(x0,y0,z0) # calculate gradient of f at P0 print("The Gradient of f at P0 is: ") show(Grad) Df = Grad.dot_product(u) # calculate the directional derivative using Theorem 9 print("The derivative of f at P0 in the direction of vector v is: ") show(Df) print("f increases most rapidly in the direction of its gradient: ") show(Grad) print("with the rate of change: ") show(Grad.norm()) print("f decreases most rapidly in the opposite direction of its gradient: ") show(-Grad) print("with the rate of change: ") show(-Grad.norm())
The Gradient of f at P0 is:

(2,2,1)\displaystyle \left(2,\,-2,\,-1\right)

The derivative of f at P0 in the direction of vector v is:

47\displaystyle \frac{4}{7}

f increases most rapidly in the direction of its gradient:

(2,2,1)\displaystyle \left(2,\,-2,\,-1\right)

with the rate of change:

3\displaystyle 3

f decreases most rapidly in the opposite direction of its gradient:

(2,2,1)\displaystyle \left(-2,\,2,\,1\right)

with the rate of change:

3\displaystyle -3

Chain rule for paths

w=f(r(t))=f(x(t),y(t),z(t))w=f(\vec{r}(t))=f(x(t),y(t),z(t))

Find the derivative along the path ddtf(r(t))=f(r(t))r(t)).{d\over dt}f(\vec{r}(t))=\nabla f(\vec{r}(t))\cdot \vec{r}'(t)).

Tangent Planes and Differentials

Chain rule for paths in the space

Consider a parameterized curve r(t)\vec{r}(t) such that c=f(r(t))=f(x(t),y(t),z(t)).c=f(\vec{r}(t))=f(x(t),y(t),z(t)). Taking the derivative with respect to tt on both sides, we have 0=ddtf(r(t))=f(r(t))r(t)0={d\over dt}f(\vec{r}(t))=\nabla f(\vec{r}(t))\cdot \vec{r}'(t)

  • tangent line at the point P0P_0 on the curve r(t)\vec{r}(t): the line through P0P_0 in the direction of r\vec{r}'.

  • tangent line at the point P0P_0 on the curve r(t)\vec{r}(t) such that f(r(t))=cf(\vec{r}(t))=c: a line through P0P_0 orthogonal to f\nabla f.

Tangent planes and normal lines

Definition

  • tangent plane to the level surface f(x,y,z)=cf(x,y,z)=c at the point P0(x0,y0,z0)P_0(x_0,y_0,z_0): the plane through P0P_0 normal to fP0\nabla f|_{P_0}.

  • normal line of the surface at P0P_0: the line through P0P_0 parallel to fP0\nabla f|_{P_0}.

Tangent plane to f(x,y,z)=cf(x,y,z)=c at P0(x0,y0,z0)P_0(x_0,y_0,z_0) fx(P0)(xx0)+fy(P0)(yy0)+fz(P0)(zz0)=0f_x(P_0)(x - x_0) + f_y(P_0)(y - y_0) + f_z(P_0)(z - z_0)= 0 Normal line to f(x,y,z)=cf(x,y,z)=c at P0(x0,y0,z0)P_0(x_0,y_0,z_0) x=x0+fx(P0)t,y=y0+fy(P0)t,z=z0+fz(P0)tx = x_0 + f_x(P_0)t, y = y_0 + f_y(P_0)t, z = z_0 + f_z(P_0)t

Example

Find the tangent plane and normal line of the level surface f(x,y,z)=x2+y2+z9=0f(x,y,z)=x^2+y^2+z-9=0 at the point P0(1,2,4)P_0(1,2,4).

reset() var('x,y,z,t') f(x,y,z) = x^2+y^2+z-9 # specify f for the level surface fx(x,y,z)= f(x,y,z).diff(x) fy(x,y,z)= f(x,y,z).diff(y) fz(x,y,z)= f(x,y,z).diff(z) Grad_f(x,y,z) = vector([fx(x,y,z),fy(x,y,z),fz(x,y,z)]) # Gradient of f at (x,y,z) x0 = 1 # specify a point P_0 y0 = 2 z0 = 4 A = point((x0,y0)) Grad = Grad_f(x0,y0,z0)# Gradient of f at P_0 print("The Gradient of f at P_0 is: ") show(Grad) print("The tangent plane at P_0 is: ") P = Grad[0]*(x-x0)+Grad[1]*(y-y0)+Grad[2]*(z-z0) == 0 # find the tangent plane show(P) print("The line normal to the surface at P_0 is: ") show( x == x0 + Grad[0]*t) # find the normal line show( y == y0 + Grad[1]*t) show( z == z0 + Grad[2]*t) p = implicit_plot3d(f(x,y,z)==0, (x, -3, 3), (y, -3, 3), (z, 0, 9),opacity = 0.5, color = 'cyan') # plot f(x,y,z) p += implicit_plot3d(P, (x, -3, 3), (y, -3, 3), (z, 0, 9),opacity = 0.5, color = 'orange') # plot tangent plane at P_0 p += A[0].plot3d(z = z0, size = 30) # plot P_0 p += parametric_plot3d((x0 + Grad[0]*t,y0 + Grad[1]*t, z0 + Grad[2]*t), (t, 0, 1), opacity = 0.5, color = 'red', size = 500) # plot the normal line at P_0 p.show()
The Gradient of f at P_0 is:

(2,4,1)\displaystyle \left(2,\,4,\,1\right)

The tangent plane at P_0 is:

2x+4y+z14=0\displaystyle 2 \, x + 4 \, y + z - 14 = 0

The line normal to the surface at P_0 is:

x=2t+1\displaystyle x = 2 \, t + 1

y=4t+2\displaystyle y = 4 \, t + 2

z=t+4\displaystyle z = t + 4

Graphics3d Object

Plane tangent to a surface z=f(x,y)z=f(x,y) at (x0,y0,f(x0,y0))(x_0,y_0,f(x_0,y_0))

The plane tangent to the surface z=ƒ(x,y)z = ƒ(x, y) of a differentiable function ƒ at the point P0(x0,y0,z0)=(x0,y0,ƒ(x0,y0))P_0(x_0 , y_0 , z_0) = (x_0 , y_0 , ƒ(x_0 , y_0)) is ƒx(x0,y0)(xx0)+ƒy(x0,y0)(yy0)(zz0)=0.ƒ_x(x_0 , y_0)(x - x_0) + ƒ_y(x_0 , y_0)(y - y_0) - (z - z_0) = 0.

Example

Find the plane tangent to the surface z=xcosyyexz=x\cos y-ye^x at (0,0,0)(0,0,0).

reset() var('x,y,z') f(x,y)=x*cos(y)-y*e^x # specify a level surface z = f(x,y) x0 = 0 # specify P_0(x_0, y_0, z_0) y0 = 0 z0 = 0 fx(x,y)=f.diff(x) # find partial derivatice of f(x,y) fy(x,y)=f.diff(y) print("The tangent plane at P_0 is: ") show(fx(x0,y0)*(x-x0)+fy(x0,y0)*(y-y0)-(z-z0)== 0) p = implicit_plot3d(f(x,y)== z, (x, -1, 1), (y, -1, 1), (z, -1, 1),opacity = 0.3, color = 'blue') # plot f(x,y)= z p += implicit_plot3d(fx(x0,y0)*(x-x0)+fy(x0,y0)*(y-y0)-(z-z0)== 0, (x, -1, 1), (y, -1, 1), (z, -1, 1),opacity = 0.4, color = 'red') # plot tangent plane at P_0 p.show()
The tangent plane at P_0 is:

xyz=0\displaystyle x - y - z = 0

Find the parametric equations for the line tangent to an ellipse EE

f(x,y,z)=x2+y22=0,g(x,y,z)=x+z4=0f(x,y,z)=x^2+y^2-2=0,\quad g(x,y,z)=x+z-4=0

meet in an ellipse EE.

# The tangent line is orthogonal to both the gradient of f and the gradient of g at P_0 => it is parallel to the cross product of the two gradients reset() var('x,y,z,t') f(x,y,z) = x^2+y^2-2 # specify to function that intersect g(x,y,z) = x+z-4 x0 = 1 # specify a point P_0 y0 = 1 z0 = 3 fx= f(x,y,z).diff(x) fy = f(x,y,z).diff(y) fz = f(x,y,z).diff(z) gx= g(x,y,z).diff(x) gy = g(x,y,z).diff(y) gz = g(x,y,z).diff(z) Grad_f(x,y,z) = vector([fx,fy,fz]) # Gradients of f and g at (x,y,z) Grad_g(x,y,z) = vector([gx,gy,gz]) Grad_f = Grad_f(x0,y0,z0) # Gradients of f and g at P_0 Grad_g = Grad_g(x0,y0,z0) print("The Gradient of f at P_0 is: ") show(Grad_f) print("The Gradient of g at P_0 is: ") show(Grad_g) v = Grad_f.cross_product(Grad_g)# find the cross product: Grad_f x Grad_g, which is parallel to the tangent line print("The direction of the tangent line at P_0 is: ") show(v) print("The direction of the tangent line to the intersection at P_0 is: ") show(x == x0 + v[0]*t) show(y == y0 + v[1]*t) show(z == z0 + v[2]*t)
The Gradient of f at P_0 is:

(2,2,0)\displaystyle \left(2,\,2,\,0\right)

The Gradient of g at P_0 is:

(1,0,1)\displaystyle \left(1,\,0,\,1\right)

The direction of the tangent line at P_0 is:

(2,2,2)\displaystyle \left(2,\,-2,\,-2\right)

The direction of the tangent line to the intersection at P_0 is:

x=2t+1\displaystyle x = 2 \, t + 1

y=2t+1\displaystyle y = -2 \, t + 1

z=2t+3\displaystyle z = -2 \, t + 3

Estimating the change in ff in a direction u\vec{u}

To estimates the change in the function value of ff when we move a small distance dsds from a point P0P_0 in the direction u\vec{u}, we use the formula df=(fP0u)dsdf= (\nabla f|_{P_0}\cdot\vec{u})ds

Linearize a function of TWO variables

The linearization of f(x,y)f(x,y) at (x0,y0)(x_0,y_0) where ff is differentiable is the function L(x,y)=f(x0,y0)+fx(x0,y0)(xx0)+fy(x0,y0)(yy0).L(x,y)=f(x_0,y_0)+f_x(x_0,y_0)(x-x_0)+f_y(x_0,y_0)(y-y_0). The approximation f(x,y)L(x,y)f(x,y)\approx L(x,y) is the standard linear approximation of ff at (x0,y0)(x_0,y_0).

Example

Find the linearization of f(x,y)=x2xy+12y2+3f(x,y)=x^2-xy+{1\over 2}y^2+3 at (3,2)(3,2).

reset() var('x,y,L,z') x0 = 3 # specify(x0,y0) y0 = 2 f(x,y) = x^2 - x*y +(1/2)*y^2+3 fx(x,y) = f(x,y).diff(x) fy(x,y) = f(x,y).diff(y) l = L == f(x0,y0)+fx(x0,y0)*(x-x0)+fy(x0,y0)*(y-y0) print("The linearization of f at (x0, y0) is: ") show(l) p = implicit_plot3d(f(x,y)== z, (x, 0, 5), (y, 0, 5), (z, 0, 10),opacity = 0.3, color = 'blue') # plot f(x,y)=z p += implicit_plot3d(f(x0,y0)+fx(x0,y0)*(x-x0)+fy(x0,y0)*(y-y0)==z, (x, 0, 5), (y, 0, 5), (z, 0, 10),opacity = 0.3, color = 'cyan')# plot tangent plane at P_0 p.show() print("The tangent plane L(x,y) represent the linearization of f(x,y)")
The linearization of f at (x0, y0) is:

L=4xy2\displaystyle L = 4 \, x - y - 2

Graphics3d Object
The tangent plane L(x,y) represent the linearization of f(x,y)

The error f(x,y)L(x,y)f(x,y)-L(x,y) in the standard linear approximation

f(x,y)L(x,y)f(x,y)-L(x,y) Definition If we move from (x0,y0)(x_0, y_0) to (x0+dx,y0+dy)(x_0 + dx, y_0 + dy) nearby, the resulting change df=fx(x0,y0)dx+fy(x0,y0)dydf = f_x(x_0, y_0) dx + f_y(x_0, y_0) dy in the linearization of ff is called the total differential of ff.

Example

A cylindrical can is designed to have a radius of 1 cm and a height of 5 cm, but the radius and height are off by the amounts drdr = +0.03 and dhdh = -0.1. Estimate the resulting absolute change in the volume of the can.

The error f(x,y)L(x,y)f(x,y)-L(x,y) in the standard linear approximation

If ff has continuous first and second partial derivatives throughout an open set containing a rectangle RR centered at (x0,y0)(x_0,y_0) and if MM is any upper bound for the values of fxx|f_{xx}|, fxy|f_{xy}|, and fyy|f_{yy}| on RR, then the error E(x,y)=f(x,y)L(x,y)E(x,y)=f(x,y)-L(x,y) incurred in replacing f(x,y)f(x,y) on RR by its linearization L(x,y)=f(x0,y0)+fx(x0,y0)(xx0)+fy(x0,y0)(yy0)L(x,y)=f(x_0,y_0)+f_x(x_0,y_0)(x-x_0)+f_y(x_0,y_0)(y-y_0) satisfies the inequality E(x,y)12M(xx0+yy0)2.|E(x,y)|\leq {1\over2}M(|x-x_0|+|y-y_0|)^2.

Definition

If we move from (x0,y0)(x_0, y_0) to (x0+dx,y0+dy)(x_0 + dx, y_0 + dy) nearby, the resulting change df=fx(x0,y0)dx+fy(x0,y0)dydf = f_x(x_0, y_0) dx + f_y(x_0, y_0) dy in the linearization of ff is called the total differential of ff.

Example

A cylindrical can is designed to have a radius of 1 cm and a height of 5 cm, but the radius and height are off by the amounts drdr = +0.03 and dhdh = -0.1. Estimate the resulting absolute change in the volume of the can.

var('dV,r,h') V = (pi)*r^2*h # write the equation for volume calculation Vr(r,h) = V.diff(r) # find the partial derivatives with respect to r and h Vh(r,h) = V.diff(h) r0 = 1 h0 = 5 dr = 0.03 # specify dr and dh dh = -0.1 dV = Vr(r0,h0)*(dr)+Vh(r0,h0)*(dh) #find the total differential print("The resulting change in the volume is about") show(round(dV, ndigits=2))
The resulting change in the volume is about

0.63\displaystyle 0.63

Functions of more than two variables

  • The linearization of f(x,y,z)f(x, y, z) at P0(x0,y0,z0)P_0(x_0, y_0, z_0) is L(x,y,z)=f(P0)+fx(P0)(xx0)+fy(P0)(yy0)+fz(P0)(zz0).L(x, y, z) = f(P_0) + f_x(P_0)(x - x_0) + f_y(P_0)(y - y_0) + f_z(P_0)(z - z_0).

  • Suppose that RR is a closed rectangular solid centered at P0P_0 and lying in an open region where the second partial derivatives of ff are continuous. Suppose also that fxx|f_{xx}|, fyy|f_{yy}|, fzz|f_{zz}|, fxy|f_{xy}|, fxz|f_{xz}|, and fyz|f_{yz}| are all less than or equal to MM throughout RR. Then the error E(x,y,z)=f(x,y,z)L(x,y,z)M2(xx0+yy0+zz0)2.|E(x, y, z)| = |f(x, y, z) - L(x, y, z)|\leq {M\over 2}( |x - x_0| +|y - y_0| + |z - z_0|)^2.

  • If the second partial derivatives of ff are continuous and if xx, yy, and zz change from x0x_0, y0y_0, and z0z_0 by small amounts dxdx, dydy, and dzdz, the total differential df=fx(P0)dx+fy(P0)dy+fz(P0)dzdf = f_x(P_0) dx + f_y(P_0) dy + f_z(P_0) dz gives a good approximation of the resulting change in ff.