This material has been adapted from material by Fergus Cooper and others from the "Essential Mathematics" module at the Doctoral Training Centre, University of Oxford.
This course material was developed as part of UNIVERSE-HPC, which is funded through the SPF ExCALIBUR programme under grant number EP/W035731/1
Integration 1
Learning outcomes
Understand the concept of the area under a graph
Be able to calculate the integral of a function
Recognise integration as the inverse operation of differentiation
Be able to use SymPy to integrate functions in Python
Be able to use the substitution method to integrate a function of a function
YouTube lecture recording from October 2020
A recording of this lecture from October 2020; the material has changed a little since.
Why integration?
We often know the rate at which something happens (e.g. how quickly a product is made), and want to know the total amount over some time.
Integration lets us work this out.
It is also how we find the area under a curve, and, as we will see, it reverses differentiation.
Integration
Calculating the area under a curve:
If we want to find the area under a curve, we can divide the area into strips, calculate the area of each strip, and sum these areas together.
e.g. find the area of
y=f(x)=x2betweenx=1 and x=2
The area of the strip is δAi≈y(xi)δx
We can sum up all the strips between x=1 and x=2 to give an estimate for the total area:
A≈∑δAi=∑y(xi)δx.
This becomes more accurate as δx becomes smaller.
We can use the same trick as when differentiating: let δx tend to 0:
A=δx→0lim∑y(xi)δx=1∫2ydx
If we use a coarse approximation, then we are over-counting the area under the curve by quite a lot:
But, as the size of each rectangle reduces, we converge to the true area under the curve:
∫ is an elongated S, for the Latin summa (sum).
This process is called integration.
Calculating the integral
Let us 'invent' a function F(x) that gives the area from some fixed point to x.
Then A=F(2)−F(1).
With this (imagined) function, we can find the area of one of our tiny steps exactly, as
F(x+δx)−F(x)
Remember we approximated this as yδx=f(x)δx, so:
F(x+δx)−F(x)f(x)≈f(x)δx≈δxF(x+δx)−F(x)
The error in this approximation tends to 0 as δx→0, so
f(x)=δx→0limδxF(x+δx)−F(x)=F′(x)
(recalling the definition of the derivative).
In other words, for our example,
A(x)=1∫xy(t)dttheny(x)=A′(x)
Integration reverses the process of differentiation.
An integral without limits is called an indefinite integral.
Indefinite integrals in SymPy
x = sp.symbols('x')sp.integrate(2*x,x)
x2
Other integrals
Recall that dxdlnx=x1. In fact, for any x=0:
dxdln∣x∣=x1⇒∫x1dx=ln∣x∣+C
We need the modulus because ln is only defined for positive numbers, but 1/x is defined for negative x too.
For x>0, ∣x∣=x, so this is just the derivative of lnx that we already know.
For x<0, ∣x∣=−x, and the chain rule gives
dxdln(−x)=−x1×(−1)=x1.
So ln∣x∣ has derivative 1/x on both sides of zero.
This constant C can be written as:
C=lnB
where B is another constant. Thus:
∫x1dx=ln∣x∣+C=ln∣x∣+lnB=ln(B∣x∣)
Integrating trigonometric functions
Recall that:
dxd(sinx)=cosxanddxd(cosx)=−sinx
Example 1:
∫0π/2cosxdx=[sinx]0π/2=1−0=1
Example 2:
∫0π/2sinxdx=[−cosx]0π/2=0−(−1)=1
Summary of integration formulae
∫adx∫axdx∫axndx∫x−1dx=ax+C=21ax2+C=n+11axn+1+Cfor all n except n=−1=∫x1dx=ln∣x∣+C
Application
Recall that f′(t) gives the rate at which f(t) changes at time t.
Integrating the derivative f′(t), we see:
∫abf′(t)dt=[f(t)]ab=f(b)−f(a)
Therefore, the definite integral from a to b of f′(t) with respect to t will always give the net change that f(t) has undergone as the parameter t moves from a to b.
Example
A chemical process produces NaCl at the rate of 3t grams per minute.
We ask three questions:
What is the rate of production one minute into the process?
What is the quantity of NaCl produced over the next three minutes?
What is the mean rate of NaCl production over this interval?
Solution
Let f(t) denote the grams of NaCl produced after t minutes. Then f′(t)=3t.
The rate of production one minute into the process is f′(1)=31=3 grams per minute.
The quantity of NaCl produced over the next three minutes is:
For more practice, an AI tool can write new problems like the ones below.
Ask it for problems of the same type and difficulty, or for problems set in your own field.
For example, you could ask it to "write five climate science problems on definite integrals, at the level of these ones".
Work them on paper first, then ask the tool to check your answers and to explain any step you are unsure of.
Introductory problems 1
Integrate the following functions with respect to x. Remember that you can check your own answers by differentiating your results:
x3−1/x4+x2
3x+1/(34x)
1/x2+1/3x−7
In each case, first write every term as a power of x, then use ∫xndx=xn+1/(n+1)+C.
By making suitable substitutions, find the indefinite integrals of:
2(6x−5)3
7x/(x2−2)
3/5−x
1/(x−a)
Let u=6x−5, so dx=du/6:
∫2(6x−5)3dx=62∫u3du=12u4+C=12(6x−5)4+C
Let u=x2−2, so xdx=du/2:
∫x2−27xdx=27∫u1du=27ln∣u∣+C=27lnx2−2+C
Let u=5−x, so dx=−du:
∫5−x3dx=−3∫u−1/2du=−6u1/2+C=−65−x+C
Let u=x−a, so dx=du:
∫x−a1dx=∫u1du=ln∣x−a∣+C
Introductory problems 5
Consider the area under y=1/x between x=1 and x=3.
Estimate the area by dividing it into 4 strips of width 0.5, taking the height of each strip as the value of y at its right-hand end.
Is your estimate too big or too small? Why?
Calculate the area exactly by integration, and compare.
Use Python to repeat the estimate with 100 strips.
The right-hand ends of the strips are at x=1.5, 2, 2.5 and 3:
A≈0.5(1.51+21+2.51+31)=0.95
Too small.
1/x decreases as x increases, so the value at the right-hand end of each strip is the lowest in that strip, and each rectangle lies below the curve.
(For y=x2 in the lecture, which increases, the same method gave an estimate that was too big.)
A=∫13x1dx=[lnx]13=ln3−ln1=ln3≈1.0986
So, the estimate with 4 strips is about 14% too small.
With 100 strips, each strip has width 0.02:
import numpy as np
n =100dx =(3-1)/ n
x = np.linspace(1+ dx,3, n)# the right-hand end of each stripprint('estimate =', np.sum(dx / x))print('exact =', np.log(3))
With 100 strips the estimate is much closer, and it gets closer still as the strips get narrower.
Main problems
Main problems 1
Electrostatic work: the force acting between two electric charges q1 and q2 separated by distance x in a vacuum is given by Coulomb's inverse square law:
F(x)=4πϵ0x2q1q2
where ϵ0 is the permittivity of a vacuum.
Like charges (charges with the same sign, such as 2 nuclei or 2 electrons) repel so that the force acting on q2 due to the presence of q1 acts in a positive x direction, away from q1.
Unlike charges (of opposite signs such as the proton and electron in the hydrogen atom) attract, and the force on q2 is directed towards q1 (i.e. F is negative).
Consider 2 like charges, initially infinitely far apart.
Because the charges repel, work must be done on the system to bring q2 from infinity to the distance x from q1.
The force F must be applied to overcome the repulsion.
Explain why the total work done is given by
W=−∫∞xF(x′)dx′=−4πϵ0q1q2∫∞xx′2dx′.
Calculate the work, W, in Joules when
x=5.3×10−11m,
q1=q2=1.6×10−19C,
ϵ0=8.85×10−12Fm−1.
To move q2 inwards we must push it with a force that balances the repulsion, i.e. a force −F(x′) at each distance x′.
Work is force times distance moved, and when the force changes with distance we add up the small amounts of work −F(x′)dx′ along the way.
We start at infinity and end at x, so the total is
W=∫∞x(−F(x′))dx′=−∫∞xF(x′)dx′
Substituting Coulomb's law for F gives the second form.
(Both the applied force and the movement point towards q1, so W is positive.)
(This distance is the radius of a hydrogen atom, so W is the work needed to bring two protons that close together.)
Main problems 2
The rate at which the world's oil is being consumed is continuously increasing.
Suppose the rate (in billions of barrels per year) is given by the function r=f(t), where t is measured in years and t=0 is the start of 1990.
Write down a definite integral which represents the total quantity of oil used between the start of 1990 and the end of 2020.
Calculate this integral using the function r(t)=24e0.015t.
The end of 2020 is t=31, so the total quantity of oil used, in billions of barrels, is
So about 947 billion barrels of oil were used.
(In this model the rate rises from 24 to about 38 billion barrels per year, which is close to the real figures.)
Main problems 3
Since 1850, global carbon dioxide (CO2) emissions have been rising exponentially.
Let C(t) represent the rate that CO2 is emitted into the atmosphere, measured in Gigatonnes per year, where t measures the number of years since the start of 1850.
A model for the rate of emission over time is given by
C(t)=kept,
where k and p are positive constants.
What are the units of k and p?
Given that, at the start of 1850, the global emission rate was 0.2 Gigatonnes per year, and that at the start of 2010 the global emission rate was 32 Gigatonnes per year, calculate k and p.
Calculate the total quantity of CO2 emitted between the start of 1850 and the start of 2010.
C is in Gigatonnes per year, and ept is just a number, so k is also in Gigatonnes per year.
The power pt must be a number too, so p is in "per year" (year−1).
At the start of 1850, t=0, so C(0)=k=0.2 Gigatonnes per year.
The start of 2010 is t=160, so
The velocity is largest on the axis, at r=0, since R2−r2 decreases as r increases.
So the maximum velocity is v(0)=PR2/(4ηl), and
v(0)vˉ=64=32
The average velocity along the radius is two thirds of the maximum.
Note, this is the average along a line from the axis to the wall.
The average over the whole cross-section of the vessel is 21v(0), which is smaller, because more of the cross-section lies near the wall, where the blood is slow.
Main problems 5
Consider the function y=4x3+2x2−8x+2.
Draw an accurate graph of this function for values of x between −4 and 4.
Calculate the turning points of the curve and mark these on the graph.
On your graph, shade in the region under the curve between x=−2 and x=2 and estimate its area.
Integrate the function between x=−2 and x=2. Is this an accurate calculation of the area of the shaded region in part 3.?
Identify and explain any differences you find between your estimate in part 3. and your calculation in part 4.
Some useful points: y(0)=2, y(−4)=−190 and y(4)=258.
The curve crosses the x axis where
4x3+2x2−8x+2=2(x−1)(2x2+3x−1)=0
i.e. at x=1 and, from the quadratic formula, x=(−3±17)/4, which is x≈−1.78 and x≈0.28.
import numpy as np
from matplotlib import pyplot as plt
x = np.linspace(-4,4,400)y =4* x**3+2* x**2-8* x +2plt.plot(x, y)plt.axhline(0, color='black', linewidth=0.5)plt.xlabel('x')plt.ylabel('y')
The turning points are where
dxdy=12x2+4x−8=4(3x−2)(x+1)=0
i.e. at x=−1 and x=2/3.
The second derivative is d2y/dx2=24x+4.
At x=−1 it is −20<0, so (−1,8) is a maximum.
At x=2/3 it is 20>0, so (2/3,−34/27), i.e. about (0.67,−1.26), is a minimum.
Between x=−2 and x=2 the curve is below the axis for −2<x<−1.78 and for 0.28<x<1, and above it elsewhere (y(−2)=−6 and y(2)=26).
Counting squares, or splitting the region into triangles, gives two large pieces of about 10 each and two small pieces of under 1 each, so an estimate of about 21.
(Any careful estimate close to this is fine.)
The integral counts the parts of the region below the x axis as negative, so it subtracts them instead of adding them.
To find the area, we integrate separately between the points where the curve crosses the axis, and add up the sizes of the results.
The two pieces below the axis have areas of about 0.62 and 0.60, so
area≈18.67+2×(0.62+0.60)≈21.11
Any remaining difference from part 3. is the error in the estimate.
Extension problems
Extension problems 1
Evaluate the following definite integrals:
∫−π/2π/23cos(x)dx
∫π/2πcos(x)sin(x)dx
∫0π(cos2(x)+sin2(x))dx
Since sin(x) has derivative cos(x),
∫−π/2π/23cos(x)dx=3[sin(x)]−π/2π/2=3(1−(−1))=6
Let u=sin(x), so that du=cos(x)dx.
At x=π/2, u=1, and at x=π, u=0:
∫π/2πcos(x)sin(x)dx=∫10udu=[2u2]10=−21
Since cos2(x)+sin2(x)=1 for every x,
∫0π(cos2(x)+sin2(x))dx=∫0π1dx=π
Extension problems 2
Let u and v be functions of x.
Given that
dxd(uv)=udxdv+vdxdu,
show that
∫vdxdudx=uv−∫udxdvdx.
By using this 'integration by parts' formula, and substituting z=x2 or otherwise, show that
∫0∞xne−x2dx=21(n−1)∫0∞xn−2e−x2dxfor n>1.
Hence evaluate
∫0∞x5e−x2dx.
Integrating both sides of the product rule with respect to x,
uv=∫udxdvdx+∫vdxdudx
since integration reverses differentiation.
Rearranging gives the formula.
Write xne−x2=xn−1⋅xe−x2, and choose
v=xn−1,dxdu=xe−x2
Then dv/dx=(n−1)xn−2, and, substituting z=x2 (so dz=2xdx), u=∫xe−x2dx=21∫e−zdz=−21e−x2.
The integration by parts formula gives
The first term is zero at both ends.
At x=0, xn−1=0 because n>1.
As x→∞, e−x2 shrinks much faster than xn−1 grows, so their product tends to 0.
This leaves the result.
Using the result with n=5 and then n=3,
∫0∞x5e−x2dx=24∫0∞x3e−x2dx=2⋅22∫0∞xe−x2dx
From part 2., ∫xe−x2dx=−21e−x2, so
∫0∞xe−x2dx=[−21e−x2]0∞=0−(−21)=21
Therefore,
∫0∞x5e−x2dx=2×21=1
Extension problems 3
A country wishes to achieve net-zero CO2 emissions in 50 years.
Let t be the time in years since the start of its programme, and let E(t) be the rate at which the country emits CO2, in Mt CO2year−1.
At the start, E=800.
The country plans to reduce this rate steadily, so that each year its rate of emission is 12 Mt CO2year−1 lower than the year before.
1. Write down dE/dt, and hence find E(t).
Use this to calculate the total CO2 that the country emits over the 50 years.
After 10 years, the country starts a CO2 removal programme, which captures CO2 from the atmosphere and stores it underground.
The rate of removal R(t), in Mt CO2year−1, is
R(t)=0.1t2−tfort≥10
(where t is still the time since the start of the programme).
2. Find the time at which the rate of removal equals the rate of emission.
Does the country reach net-zero emissions within 50 years?
After 50 years, the country's rate of emission stays at its value at t=50, while the rate of removal carries on following R(t).
The country wants the total CO2 it has emitted since the start of the programme to be balanced by the total it has removed, so that overall it has added no CO2 to the atmosphere.
3. Show that this happens about 108.5 years after the start of the programme.
1. The rate of emission falls by 12 every year, so
dtdE=−12
Integrating, E=−12t+C, and E(0)=800 gives C=800, so E(t)=800−12t.
The total emitted over the 50 years is
The negative root has no meaning here, so the rates are equal at t=50.
So, the country just reaches net-zero emissions at 50 years.
3. After 50 years the rate of emission stays at E(50)=800−12×50=200.
So, by a time T>50, the total emitted is
25000+200(T−50)=15000+200T
and the total removed is
∫10T(0.1t2−t)dt=[30t3−2t2]10T=30T3−2T2+350
Setting these equal and multiplying through by 30,
T3−15T2−6000T−449500=0
We can't easily solve this cubic exactly, so we try values.
The left-hand side is −12748 at T=108 and 13314 at T=109, so it is zero between them, at about T=108.5 years.