Skip to main content

Tutorial 5

Binder Open In Colab

Interactive Notebooks

Click the badges above to run this tutorial interactively in your browser without installing anything!

  • Binder: Free cloud-based Jupyter environment
  • Colab: Google's free Jupyter notebook environment

Topics Covered​

This tutorial covers the following topics using Python and SymPy:

  • Navigation problems: adding velocity vectors given as compass headings
  • Work and torque: the dot product in engineering
  • Directional derivatives and the gradient
  • Tangent planes, normal lines and unit normals
  • Divergence and curl and their physical meaning

Introduction​

Headings are measured clockwise from North. A velocity of speed at compass heading hdg therefore has components

(East,North)=(ssin⁡(hdg),  scos⁡(hdg))(\text{East},\text{North})=\big(s\sin(\text{hdg}),\;s\cos(\text{hdg})\big)

SymPy's atan2(E, N) inverts this and returns a bearing that we shift into [0∘,360∘)[0^\circ,360^\circ).

import sympy as sy
from sympy.abc import x, y, z, t, r
from sympy import sqrt, sin, cos, tan, pi, atan, atan2, acos, exp, ln, Matrix, simplify
sy.init_printing(use_latex=True)

def velocity(speed, hdg):
"""Velocity vector (East, North) for a given speed and compass heading in degrees."""
return Matrix([speed*sin(hdg*pi/180), speed*cos(hdg*pi/180)])

def gradient(f, vars=(x, y, z)):
return Matrix([sy.diff(f, v) for v in vars])

def divergence(F, vars=(x, y, z)):
return sum(sy.diff(F[i], vars[i]) for i in range(len(vars)))

def curl(F):
return Matrix([sy.diff(F[2], y) - sy.diff(F[1], z),
sy.diff(F[0], z) - sy.diff(F[2], x),
sy.diff(F[1], x) - sy.diff(F[0], y)])

Question 1​

A boat heads for Dunes Beach. Part (a) gives the heading 250∘250^\circ; in part (b) a wind of 0.80.8 knot at 200∘200^\circ acts while the skipper keeps the same heading.

boat = velocity(2.4, 250)                  # intended course, 2.4 knots
wind = velocity(0.8, 200) # wind acting on the boat
display([sy.N(v, 4) for v in boat]) # [-2.255, -0.821] (East, North)
display([sy.N(v, 4) for v in wind]) # [-0.274, -0.752]

res = boat + wind
display([sy.N(v, 4) for v in res]) # [-2.529, -1.573]

speed = sqrt(res.dot(res))
display(speed, sy.N(speed, 4)) # 2.978 knots

hdg = atan2(res[0], res[1]) * 180/pi # compass heading, may be negative
display(sy.N(hdg, 6), sy.N(hdg + 360, 6)) # -121.88 ... 238.12 degrees

a. The intended heading is 250∘250^\circ.

c. The altered speed is 2.9782.978 knots at a heading of 238.12∘238.12^\circ.

Question 2​

Work done by a constant force, W=F⋅PQ→=∣F∣∣PQ→∣cos⁡θW=\mathbf{F}\cdot\overrightarrow{PQ}=|\mathbf{F}||\overrightarrow{PQ}|\cos\theta.

a. 12000 J12000\ \text{J} of work to pull a sled 200 m200\ \text{m} with a 150 N150\ \text{N} force.

theta = acos(12000/(150*200))
display(sy.N(theta*180/pi, 6)) # 66.42 degrees

b. F=5i\mathbf{F}=5i moving an object from the origin to (1,1)(1,1).

F = Matrix([5, 0]); d = Matrix([1, 1])
display(F.dot(d)) # 5 J

c. A 1000 lb force on a sail moves a boat 1 mile.

W = 1000 * 5280 * cos(60*pi/180)
display(W) # 2640000 ft.lb
note

The downloadable solution PDF writes F=5j\mathbf{F}=5\mathbf{j}, the vertical field. The displacement is purely horizontal, so the correct field is F=5i\mathbf{F}=5\mathbf{i} and the work is the xx-component alone: 5 J5\ \text{J}.

Question 3​

A bolt is tightened with a 20 N20\ \text{N} force at 60∘60^\circ to a 30 cm30\ \text{cm} wrench.

tau = 0.3 * 20 * sin(60*pi/180)
display(tau, sy.N(tau, 4)) # 5.196 N.m

The magnitude of the torque is 5.196 N⋅m5.196\ \text{N}\cdot\text{m} (about 5.25.2). The two pictures in part (b) have the same magnitude but opposite direction — one tightens the bolt, the other loosens it.

note

Torque is measured in N⋅m\text{N}\cdot\text{m}, so the magnitude 5.1965.196 rounds to 5.2 N⋅m5.2\ \text{N}\cdot\text{m} (not joules).

Question 4​

a. Is there a direction in which the rate of change of T=2xy−yzT=2xy-yz at P(1,−1,1)P(1,-1,1) equals −3 ∘C/ft-3\,^\circ\text{C/ft}?

T = 2*x*y - y*z
grad_T = gradient(T)
display(grad_T) # <2y, 2x - z, -y>

g = grad_T.subs({x: 1, y: -1, z: 1})
display(g) # <-2, 1, 1>
display(sqrt(g.dot(g)), sy.N(-sqrt(g.dot(g)), 6)) # sqrt(6), -2.449

The directional derivative lies in [−∣∇T∣, ∣∇T∣]=[−6,6]≈[−2.449,2.449]\left[-|\nabla T|,\,|\nabla T|\right]=\left[-\sqrt{6},\sqrt{6}\right]\approx[-2.449,2.449]. Since −3-3 is outside that interval, no such direction exists.

b. For the paraboloid 2z=x2+y22z=x^{2}+y^{2} at (1,3,5)(1,3,5), write the surface as f=x2+y2−2z=0f=x^{2}+y^{2}-2z=0.

f = x**2 + y**2 - 2*z
grad_f = gradient(f)
display(grad_f) # <2x, 2y, -2>

n = grad_f.subs({x: 1, y: 3, z: 5})
display(n) # <2, 6, -2>

# tangent plane: n . (X - P) = 0
plane = n[0]*(x - 1) + n[1]*(y - 3) + n[2]*(z - 5)
display(simplify(plane)) # 2x + 6y - 2z - 10
display(simplify(plane/2)) # x + 3y - z - 5

# unit normal vector
display(n / sqrt(n.dot(n))) # <1, 3, -1>/sqrt(11)

So ∇f=2x i+2y j−2 k\nabla f=2x\,\boldsymbol{i}+2y\,\boldsymbol{j}-2\,\boldsymbol{k}, ∇f(1,3,5)=⟨2,6,−2⟩\nabla f(1,3,5)=\langle2,6,-2\rangle, the tangent plane is 2x+6y−2z=102x+6y-2z=10, the unit normal is ⟨1,3,−1⟩11\dfrac{\langle1,3,-1\rangle}{\sqrt{11}}, and the normal line is x=1+2t, y=3+6t, z=5−2tx=1+2t,\ y=3+6t,\ z=5-2t.

note

The gradient of f=x2+y2−2zf=x^{2}+y^{2}-2z is ⟨2x, 2y, −2⟩\langle 2x,\,2y,\,-2\rangle, so the zz-component of ∇f\nabla f is the constant −2-2, not −2z-2z.

c.i. 2x2+y2−z2=−32x^{2}+y^{2}-z^{2}=-3 at (1,2,3)(1,2,3).

f = 2*x**2 + y**2 - z**2 + 3
g = gradient(f).subs({x: 1, y: 2, z: 3})
display(g) # <4, 4, -6>
display(simplify(g[0]*(x-1) + g[1]*(y-2) + g[2]*(z-3))) # 4x + 4y - 6z + 6

Tangent plane 4x+4y−6z+6=04x+4y-6z+6=0; normal line x=1+4t, y=2+4t, z=3−6tx=1+4t,\ y=2+4t,\ z=3-6t.

c.ii. 30−y2−z2=x230-y^{2}-z^{2}=x^{2} at (1,−2,5)(1,-2,5).

f = x**2 + y**2 + z**2 - 30
g = gradient(f).subs({x: 1, y: -2, z: 5})
display(g) # <2, -4, 10>
display(simplify(g[0]*(x-1) + g[1]*(y+2) + g[2]*(z-5))) # 2x - 4y + 10z - 60

Tangent plane 2x−4y+10z−60=02x-4y+10z-60=0; normal line x=1+2t, y=−2−4t, z=5+10tx=1+2t,\ y=-2-4t,\ z=5+10t.

Question 5​

a. Divergence of F=xyi+(2x−3y)jF=\dfrac{x}{y}\boldsymbol{i}+(2x-3y)\boldsymbol{j}

display(simplify(divergence(Matrix([x/y, 2*x - 3*y]), (x, y))))   # 1/y - 3

The divergence is a scalar, so it describes whether the field is expanding (positive) or compressing (negative) at a point.

b. Curl of F=xi−yj+zkF=x\boldsymbol{i}-y\boldsymbol{j}+z\boldsymbol{k}

display(curl(Matrix([x, -y, z])))          # <0, 0, 0>

The curl is the zero vector, so this field is irrotational.

Question 6​

A 2.5 N2.5\ \text{N} force is applied perpendicular to a 15 cm15\ \text{cm} spanner.

tau = 2.5 * 0.15 * sin(pi/2)               # 15 cm = 0.15 m
display(tau, tau*100) # 0.375 N.m = 37.5e-2 N.m

The torque is 0.375 N⋅m=37.5×10−2 N⋅m0.375\ \text{N}\cdot\text{m}=37.5\times10^{-2}\ \text{N}\cdot\text{m}, acting anticlockwise.

note

The spanner is 15 cm=0.15 m15\ \text{cm}=0.15\ \text{m}, which is what gives the quoted answer 37.5×10−2 N⋅m37.5\times10^{-2}\ \text{N}\cdot\text{m}.


Extra Learning Resources​

Key Concepts to Master​

  1. Relative velocity: add the vectors tip-to-tail, then convert back to speed and heading
  2. Work: W=F⋅d=∣F∣∣d∣cos⁡θW=\mathbf{F}\cdot\mathbf{d}=|\mathbf{F}||\mathbf{d}|\cos\theta
  3. Torque: τ=∣r∣∣F∣sin⁡θ\tau=|\mathbf{r}||\mathbf{F}|\sin\theta, in N⋅m\text{N}\cdot\text{m}
  4. Gradient: points in the direction of steepest increase, with magnitude equal to that maximum rate
  5. Divergence vs curl: divergence is a scalar (source/sink), curl is a vector (rotation)

SymPy Resources​

Common Pitfalls​

  • Compass headings run clockwise from North, so the East component uses sin⁡\sin and the North component uses cos⁡\cos — the opposite of the usual maths convention
  • atan2(E, N) returns angles in (−180∘,180∘](-180^\circ,180^\circ]; add 360∘360^\circ if you want a bearing
  • A directional derivative can never exceed ∣∇f∣|\nabla f| in magnitude
  • Torque uses sin⁡θ\sin\theta (cross product) while work uses cos⁡θ\cos\theta (dot product)