Skip to main content

Tutorial 9

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:

  • Area between curves
  • Work: pumping a tank, Hooke's law
  • Motion problems: velocity, acceleration, distance travelled
  • Arc length
  • Centroid of a plane area
  • Hydrostatic force

Introduction​

integrate(f, (x, a, b)) computes a definite integral, and definite integrals can be nested just like the iterated integrals in the tutorial. Definite integrals are the easiest to check, because there is no arbitrary constant to worry about.

import sympy as sy
from sympy.abc import x, y, z, t, r, a, H
from sympy import (sqrt, sin, cos, tan, pi, ln, exp, log, integrate, diff, simplify,
Rational, N, Symbol)
sy.init_printing(use_latex=True)

Question 1​

Find the area bounded by the curves.

i. y=x4−x2y=x^{4}-x^{2} and y=x2y=x^{2}, to the right of the yy-axis.

# intersection: x^4 - x^2 = x^2  ->  x^2 (x^2 - 2) = 0
display(sy.solve(x**4 - x**2 - x**2, x)) # [0, -sqrt(2), sqrt(2)]

# on (0, sqrt(2)) the line y = x^2 is above y = x^4 - x^2, so the integrand is
# (upper - lower) = x^2 - (x^4 - x^2) = 2x^2 - x^4
A = integrate(2*x**2 - x**4, (x, 0, sqrt(2)))
display(A, sy.N(A, 6)) # 8*sqrt(2)/15 = 0.754247

A=∫02(2x2−x4)dx=27/215≈0.754A=\int_{0}^{\sqrt{2}}\left(2x^{2}-x^{4}\right)dx=\frac{2^{7/2}}{15}\approx0.754

note

The printed solution integrates x4−x2−x2x^{4}-x^{2}-x^{2} (upper minus lower in the wrong order) and quotes 27/215−2\frac{2^{7/2}}{15}-2, which is negative. An area must be positive; the correct integrand is 2x2−x42x^{2}-x^{4}.

ii. x=y3x=y^{3} and x=y2x=y^{2}.

display(sy.solve(y**3 - y**2, y))                # [0, 1]

# on (0, 1) the curve x = y^2 is to the right of x = y^3
A = integrate(y**2 - y**3, (y, 0, 1))
display(A) # 1/12

A=∫01(y2−y3)dy=112A=\int_{0}^{1}\left(y^{2}-y^{3}\right)dy=\frac{1}{12}

iii. y=cos⁡(πx2)y=\cos\left(\dfrac{\pi x}{2}\right) and y=1−x2y=1-x^{2}, in the first quadrant.

A = integrate(1 - x**2 - cos(pi*x/2), (x, 0, 1))
display(A, sy.N(A, 6)) # 2/3 - 2/pi = 0.030047

A=∫01(1−x2−cos⁡πx2)dx=23−2π≈0.03A=\int_{0}^{1}\left(1-x^{2}-\cos\frac{\pi x}{2}\right)dx=\frac{2}{3}-\frac{2}{\pi}\approx0.03

Question 2​

Area bounded by the parabola x=8+2y−y2x=8+2y-y^{2}, the yy-axis, y=−1y=-1 and y=3y=3.

display(sy.factor(8 + 2*y - y**2))               # -(y - 4)*(y + 2)

A = integrate(8 + 2*y - y**2, (y, -1, 3))
display(A) # 92/3

A=∫−13(8+2y−y2)dy=923A=\int_{-1}^{3}\left(8+2y-y^{2}\right)dy=\frac{92}{3}

note

The printed solution says the parabola "cuts the yy-axis at y=−4y=-4, y=−2y=-2". The factorisation is (4−y)(2+y)(4-y)(2+y), so the roots are y=4y=4 and y=−2y=-2.

Question 3​

A cylindrical tank of radius 4 m4\ \text{m} and height 10 m10\ \text{m} is filled to a depth of 8 m8\ \text{m}. Find the work needed to pump the water out of the top.

Each horizontal layer at depth xx (measured downward from the top) has volume 16π Δx16\pi\,\Delta x and must be lifted a distance xx, so the total work is ∫2109800⋅16π x dx\int_{2}^{10}9800\cdot16\pi\,x\,dx.

W = 9800 * 16 * pi * integrate(x, (x, 2, 10))
display(W, sy.N(W, 8)) # 7526400*pi = 23644883

W=7 526 400π≈2.36×107 JW=7\,526\,400\pi\approx2.36\times10^{7}\ \text{J}

Question 4​

An object moves with acceleration a(t)=−cos⁡ta(t)=-\cos t, s(0)=1s(0)=1 and v(0)=0v(0)=0. Find the maximum distance from zero and the maximum speed.

tau = Symbol('tau', positive=True)               # dummy variable of integration

v = integrate(-cos(tau), (tau, 0, t)) + 0 # apply v(0) = 0
display(v) # -sin(t)

s = 1 + integrate(v.subs(t, tau), (tau, 0, t)) # apply s(0) = 1
display(simplify(s)) # cos(t)

The position is s(t)=cos⁡ts(t)=\cos t and the speed is ∣v(t)∣=∣sin⁡t∣|v(t)|=|\sin t|. Both the maximum distance from the origin and the maximum speed are 11.

note

The printed solution stops at s=cos⁡ts=\cos t without answering the question. The object oscillates between x=−1x=-1 and x=1x=1, so the maximum distance from zero is 1 m1\ \text{m} and the maximum speed is 1 m/s1\ \text{m/s}.

Question 5​

A particle's velocity is v(t)=3.2tv(t)=3.2t for t≤5t\le5, then v(t)=16.0−1.5(t−5)v(t)=16.0-1.5(t-5) for 5≤t≤115\le t\le11, then constant at 7.07.0 for t>11t>11.

(a) The acceleration is the slope of each segment:

display(diff(3.2*t, t))                          # 3.2   for t <= 5
display(diff(16.0 - 1.5*(t - 5), t)) # -1.5 for 5 <= t <= 11
display(diff(7.0, t)) # 0 for t > 11

So a(t)=3.2 m/s2a(t)=3.2\ \text{m/s}^{2} for t≤5t\le5, a(t)=−1.5 m/s2a(t)=-1.5\ \text{m/s}^{2} for 5≤t≤115\le t\le11, and a(t)=0a(t)=0 afterwards.

note

The printed solution gives a(t)=+1.5 m/s2a(t)=+1.5\ \text{m/s}^{2} on the middle interval. The velocity is decreasing there (v(11)=16−1.5(6)=7v(11)=16-1.5(6)=7), so the acceleration must be −1.5 m/s2-1.5\ \text{m/s}^{2}.

(b) The position is obtained by integrating each segment, matching the value at the junction.

x1 = integrate(3.2*tau, (tau, 0, t))                     # x(0) = 0
display(x1.subs(t, 2)) # 6.4 m

x2 = 40 + integrate(16.0 - 1.5*(tau - 5), (tau, 5, t)) # x(5) = 1.6*(5^2) = 40
display(x2.subs(t, 7)) # 69.0 m

x3 = 109 + integrate(7.0, (tau, 11, t)) # x(11) = 109 m
display(x3.subs(t, 12)) # 116.0 m

x(2)=6.4 m,x(7)=69 m,x(12)=116 mx(2)=6.4\ \text{m},\qquad x(7)=69\ \text{m},\qquad x(12)=116\ \text{m}

Question 6​

A force of 50 N50\ \text{N} stretches a spring from 2 m2\ \text{m} to 2.5 m2.5\ \text{m}.

i. Spring constant.

k = 50 / Rational(1, 2)                          # F = k x with x = 0.5 m
display(k) # 100 N/m

ii. Work needed to stretch it by 0.5 m0.5\ \text{m}.

W = integrate(100*x, (x, 0, Rational(1, 2)))
display(W, sy.N(W, 4)) # 25/2 = 12.5 J

W=∫00.5100x dx=100(0.5)22=12.5 JW=\int_{0}^{0.5}100x\,dx=\frac{100(0.5)^{2}}{2}=12.5\ \text{J}

note

The printed solution gives W=100⋅0.52/2=0.25 JW=100\cdot0.5^{2}/2=0.25\ \text{J}, which is an arithmetic slip: 100×0.25/2=12.5 J100\times0.25/2=12.5\ \text{J}.

Question 7​

Arc length of y=x3/2y=x^{3/2} from x=0x=0 to x=5x=5.

y7 = x**Rational(3, 2)
dy = diff(y7, x)
display(dy) # 3*sqrt(x)/2

L = integrate(sqrt(1 + dy**2), (x, 0, 5))
display(L, sy.N(L, 6)) # 335/27 = 12.4074

L=∫051+94x  dx=33527L=\int_{0}^{5}\sqrt{1+\frac{9}{4}x}\;dx=\frac{335}{27}

Question 8​

Arc length of the catenary y=a2(ex/a+e−x/a)y=\dfrac{a}{2}\left(e^{x/a}+e^{-x/a}\right) from x=0x=0 to x=ax=a.

a = Symbol('a', positive=True)                   # declare a positive so the square root collapses
y8 = a/2*(exp(x/a) + exp(-x/a))
dy8 = simplify(diff(y8, x))
display(dy8) # sinh(x/a)

# 1 + sinh^2(x/a) = cosh^2(x/a), so the integrand reduces to cosh(x/a)
integrand = simplify(sqrt(1 + dy8**2))
display(integrand) # sqrt(cosh(x/a)**2) = cosh(x/a)

L = integrate(integrand, (x, 0, a))
display(simplify(L)) # a*sinh(1)

# a*sinh(1) and a/2*(e - e^-1) are the same number, but `simplify` alone leaves
# sinh(1) unexpanded, so rewrite it into exponentials before subtracting.
display(simplify((L - a/2*(exp(1) - exp(-1))).rewrite(exp))) # 0

L=a2(e−e−1)=asinh⁡1L=\frac{a}{2}\left(e-e^{-1}\right)=a\sinh 1

Question 9​

Centroid of the area bounded by y=2x−x2y=2x-x^{2} and y=3x2−6xy=3x^{2}-6x.

f, g = 2*x - x**2, 3*x**2 - 6*x
display(sy.solve(f - g, x)) # [0, 2]

A = integrate(integrate(1, (y, g, f)), (x, 0, 2))
My = integrate(integrate(x, (y, g, f)), (x, 0, 2))
Mx = integrate(integrate(y, (y, g, f)), (x, 0, 2))

display(A, My, Mx) # 16/3, 16/3, -64/15
display(simplify(My/A), simplify(Mx/A)) # 1, -4/5

The centroid is (1,−45)\left(1,-\dfrac{4}{5}\right).

Question 10​

Hydrostatic force on a circular plate of radius 22 whose top is 6 m6\ \text{m} below the surface. Taking yy from the centre of the plate, the depth is 8−y8-y and the strip width is 24−y22\sqrt{4-y^{2}}.

F = 9810 * integrate((8 - y) * 2 * sqrt(4 - y**2), (y, -2, 2))
display(simplify(F), sy.N(F, 8)) # 313920*pi = 986208.77

F=19620∫−22(8−y)4−y2 dy=313 920π≈9.86×105 NF=19620\int_{-2}^{2}(8-y)\sqrt{4-y^{2}}\,dy=313\,920\pi\approx9.86\times10^{5}\ \text{N}


Extra Learning Resources​

Key Concepts to Master​

  1. Area between curves: ∫(upper−lower) dx\int(\text{upper}-\text{lower})\,dx, with the limits at the intersection points
  2. Work: ∫F dx\int F\,dx, or ∫(weight density)(area)(distance) dx\int(\text{weight density})(\text{area})(\text{distance})\,dx for pumping problems
  3. Hooke's law: F=kxF=kx, so W=∫kx dxW=\int kx\,dx
  4. Arc length: L=∫1+(y′)2 dxL=\int\sqrt{1+(y')^{2}}\,dx
  5. Centroid: xˉ=My/A\bar{x}=M_{y}/A, yˉ=Mx/A\bar{y}=M_{x}/A
  6. Hydrostatic force: F=∫ρg (depth)(width) dyF=\int \rho g\,(\text{depth})(\text{width})\,dy

SymPy Resources​

Common Pitfalls​

  • Always check which curve is on top before writing the integrand; a negative area is a sign that the order is reversed
  • Areas, masses and lengths are positive — treat a negative result as a warning, not an answer
  • For piecewise motion, match the constants of integration at every junction
  • Use Rational(3, 2) rather than 3/2 when the exponent must stay exact