Tutorial 9
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. and , to the right of the -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
The printed solution integrates (upper minus lower in the wrong order) and quotes , which is negative. An area must be positive; the correct integrand is .
ii. and .
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
iii. and , 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
Question 2
Area bounded by the parabola , the -axis, and .
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
The printed solution says the parabola "cuts the -axis at , ". The factorisation is , so the roots are and .
Question 3
A cylindrical tank of radius and height is filled to a depth of . Find the work needed to pump the water out of the top.
Each horizontal layer at depth (measured downward from the top) has volume and must be lifted a distance , so the total work is .
W = 9800 * 16 * pi * integrate(x, (x, 2, 10))
display(W, sy.N(W, 8)) # 7526400*pi = 23644883
Question 4
An object moves with acceleration , and . 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 and the speed is . Both the maximum distance from the origin and the maximum speed are .
The printed solution stops at without answering the question. The object oscillates between and , so the maximum distance from zero is and the maximum speed is .
Question 5
A particle's velocity is for , then for , then constant at for .
(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 for , for , and afterwards.
The printed solution gives on the middle interval. The velocity is decreasing there (), so the acceleration must be .
(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
Question 6
A force of stretches a spring from to .
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 .
W = integrate(100*x, (x, 0, Rational(1, 2)))
display(W, sy.N(W, 4)) # 25/2 = 12.5 J
The printed solution gives , which is an arithmetic slip: .
Question 7
Arc length of from to .
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
Question 8
Arc length of the catenary from to .
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
Question 9
Centroid of the area bounded by and .
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 .
Question 10
Hydrostatic force on a circular plate of radius whose top is below the surface. Taking from the centre of the plate, the depth is and the strip width is .
F = 9810 * integrate((8 - y) * 2 * sqrt(4 - y**2), (y, -2, 2))
display(simplify(F), sy.N(F, 8)) # 313920*pi = 986208.77
Extra Learning Resources
Key Concepts to Master
- Area between curves: , with the limits at the intersection points
- Work: , or for pumping problems
- Hooke's law: , so
- Arc length:
- Centroid: ,
- Hydrostatic force:
SymPy Resources
- SymPy
integrate— definite and nested integrals - SymPy
solve— finding intersection points - SymPy
Rational— keep fractions exact instead of using floats
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 than3/2when the exponent must stay exact