Skip to main content

Scientific Computing

Essential Maths

Differentiati... []

Scientific Computing

Essential Maths

Integration 2 []

This material has been adapted from material by Fergus Cooper from the "Essential Mathematics" module of the SABS R³ Center for Doctoral Training.

This material has been adapted from material by Fergus Cooper from the "Essential Mathematics" module of the SABS R³ Center for Doctoral Training.

Creative Commons License
This course material was developed as part of UNIVERSE-HPC, which is funded through the SPF ExCALIBUR programme under grant number EP/W035731/1

This course material was developed as part of UNIVERSE-HPC, which is funded through the SPF ExCALIBUR programme under grant number EP/W035731/1

Creative Commons License

Integration 1


YouTube lecture recording from October 2020

The following YouTube video was recorded for the 2020 iteration of the course. The material is still very similar:

Youtube lecture thumbnail


Introduction and Integration by Substitution

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\displaystyle y = f(x) = x^2\qquad{\rm between}\qquad x=1\text{ and }x=2

Individual rectangle under a curve

The area of the strip is δAiy(xi) δx\displaystyle \delta A_i \approx y(x_i)~\delta x

We can sum up all the strips between x=1x=1 and x=2x=2 to give an estimate for the total area:

AδAi=y(xi) δx.\displaystyle A \approx \sum \delta A_i = \sum y(x_i)~\delta x.

This becomes more accurate as δx\delta x becomes smaller. We can use the same trick as when differentiating: let δx\delta x tend to 00:

A=limδx0y(xi) δx=12y dx\displaystyle A = \lim_{\delta x \to 0}\sum y(x_i)~\delta x= \int\limits^{2}_{1} y~{\rm d}x

If we use a coarse approximation, then we are over-counting the area under the curve by quite a lot:

Coarse approximation to the integral

But, as the size of each rectangle reduces, we converge the true area under the curve:

Fine approximation to the integral

\displaystyle \int is the old English S and stands for the phrase "Sum Over".

This process is called integration.

Calculating the integral

Let us 'invent' a function F(x)F(x) that gives the area from 00 to xx. Then A=F(2)F(1)\displaystyle 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)\displaystyle F(x + \delta x) - F(x)

Remember we approximated this as yδx=f(x)δx\displaystyle y\,\delta x = f(x)\,\delta x, so:

F(x+δx)F(x)f(x)δx\displaystyle F(x + \delta x) - F(x) \approx f(x)\delta x > f(x)F(x+δx)F(x)δx\displaystyle f(x) \approx {F(x+\delta x)-F(x)\over\delta x}

The error in this approximation tends to 00 as δx0\displaystyle \delta x\to 0, so

f(x)=limδx0F(x+δx)F(x)δx=F(x)\displaystyle f(x) = \lim_{\delta x\to 0} {F(x+\delta x)-F(x)\over\delta x} = F'(x)

(recalling the definition of the derivative).

In other words, for our example,

A(x)=1xy(t) dttheny(x)=A(x)\displaystyle A(x) = \int\limits^{x}_{1} y(t)~{\rm d}t\qquad{\rm then}\qquad y(x) = A'(x)

Integration reverses the process of differentiation.

Calculating integrals

We know that:

d(x2)dx= 2x          [x2]x1x2=x1x22x dx\displaystyle {{\rm d} \left(x^2\right)\over {\rm d}x}=~2 x~~~~~\Rightarrow~~~~~\biggr[x^2\biggl]_{x_1}^{x_2} = \int_{x_1}^{x_2} 2 x~{\rm d}x

Likewise:

d(x33)dx= x2             x=1x=2x2 dx=[13x3]x=1x=2=8313=73\displaystyle {{\rm d}\left(\frac{x^3}{3}\right)\over {\rm d}x}=~x^2~~~~~~~\Rightarrow~~~~~~\int_{x=1}^{x=2} x^2~{\rm d}x = \biggr[{1\over3}x^3\biggl]_{x=1}^{x=2}={8\over 3}-{1\over 3}= {7\over 3}

In general:

d(axn+1)dx=(n+1)a xn         x1x2axn dx=[a(n+1)x(n+1)]x1x2\displaystyle {{\rm d}\left(a\thinspace x^{n+1}\right)\over {\rm d}x}=(n+1)a\thinspace~x^n~~~~~\Rightarrow ~~~~\int_{x_1}^{x_2} a\thinspace x^n~{\rm d}x = \biggr[{a\over(n+1)} \thinspace x^{(n+1)}\biggl]_{x_1}^{x_2}

SymPy examples

x1x2x6 dx=\displaystyle \int_{x_1}^{x_2} x^6~{\rm d}x =

import sympy as sp x, x1, x2 = sp.symbols('x x_1 x_2') sp.integrate(x**6,(x,x1,x2))

x177+x277\displaystyle - \frac{x_{1}^{7}}{7} + \frac{x_{2}^{7}}{7}


x1x2x32 dx=\displaystyle \int_{x_1}^{x_2} x^{3\over 2}~{\rm d}x =

sp.integrate(x**(sp.sympify(3)/2),(x,x1,x2))

2x1525+2x2525\displaystyle - \frac{2 x_{1}^{\frac{5}{2}}}{5} + \frac{2 x_{2}^{\frac{5}{2}}}{5}


x1x2x12 dx=\displaystyle \int_{x_1}^{x_2} x^{-{1\over 2}}~{\rm d}x =

sp.integrate(x**(-sp.sympify(1)/2),(x,x1,x2))

2x1+2x2\displaystyle - 2 \sqrt{x_{1}} + 2 \sqrt{x_{2}}

Indefinite integrals

Consider now the functions:

y=x2+7          (3)\displaystyle y=x^2+7 ~~~~~~~~~~{\rm (3)} > y=x2100         (4)\displaystyle y=x^2-100 ~~~~~~~~~{\rm (4)}

Differentiating (3):

dydx=2x\displaystyle {{\rm d}y\over {\rm d}x}=2x

Differentiating (4):

dydx=2x\displaystyle {{\rm d}y\over {\rm d}x}=2x

This implies that the integral:

y=2x dx=x2+κ     where  κ  is an unknown constant\displaystyle y=\int 2x~dx=x^2 + \kappa~~~~~{\rm where~~}\kappa~~{\rm is~an~unknown~constant}

An integral without limits is called an indefinite integral.

Indefinite integrals in SymPy

x = sp.symbols('x') sp.integrate(2*x,x)

x2\displaystyle x^{2}

Other integrals

Recall that:

ddxlnx=1x\displaystyle {{\rm d}\over {\rm d}x}\ln x={1\over x}

And, that:

ddxlnx=1x          1x dx=lnx+κ\displaystyle {{\rm d}\over {\rm d}x}\ln x={1\over x}~~~~~~~~\Rightarrow~~\int{1\over x}~{\rm d}x=\ln x + \kappa

This constant κ\kappa can be written as:

κ=lnB\displaystyle \kappa=\ln B

where BB is another constant. Thus:

1x dx=lnx+κ=lnx+lnB=ln(B x)\displaystyle \int {1\over x}~dx = \ln x + \kappa=\ln x +\ln B =\ln (B ~x)

Integrating trigonometric functions

Recall that:

ddx(sinx)=cosx             and           ddx(cosx)=sinx\displaystyle {{\rm d}\over {\rm d}x}\biggr(\sin x\biggl)= \cos x~~~~~~~~~~~~~{\rm and}~~~~~~~~~~~ {{\rm d}\over {\rm d}x}\biggr(\cos x\biggl)= -\sin x

Example (i):

0π/2cosxdx=[sinx]0π/2=10=1\displaystyle \int_{0}^{\pi/2} \cos x \thinspace {\rm d}x = \biggr[\sin x \biggl]_0^{\pi/2}=1-0=1

Example (ii):

0π/2sinxdx=[cosx]0π/2=0(1)=1\displaystyle \int_{0}^{\pi/2} \sin x \thinspace {\rm d}x =\biggr[-\cos x \biggl]_0^{\pi/2}=0-(-1)=1

Summary of integration formulae

adx=ax+C\displaystyle \int a\,{\rm d}x=ax+C


axdx=12ax2+C\displaystyle \int ax\,{\rm d}x={1\over2}ax^2+C


axndx=1n+1axn+1+Cfor alln except n=1\displaystyle \int ax^n\,{\rm d}x={1\over{n+1}}ax^{n+1}+C\qquad{\rm for~all}n{\rm ~except~}n=-1


x1dx=1xdx=lnx+C\displaystyle \int x^{-1}\,{\rm d}x=\int {1\over x}\,dx = \ln \vert x\vert +C

Application

Recall that f(t)f'(t) gives the rate at which f(t)f(t) changes at time tt.

Integrating the derivative f(t)f'(t), we see:

abf(t)dt=[f(t)]ab=f(b)f(1.\displaystyle \int_a^b f'(t) \thinspace {\rm d}t = \biggr[f(t)\biggl]_a^b = f(b)-f(1.

Therefore, the definite integral from aa to bb of f(t)f'(t) with respect to tt will always give the net change that f(t)f(t) has undergone as the parameter tt moves from aa to bb.

Example

A chemical process produces NaCl at the rate of 3t3\sqrt{t} grams per minute. We ask three questions:

  1. What is the rate of production one minute into the process?

  2. What is the quantity of NaCl produced over the next three minutes?

  3. What is the mean rate of NaCl production over this interval?

Solution

Let f(t)f(t) denote the grams of NaCl produced after tt minutes. Then f(t)=3tf'(t)= 3\sqrt{t}.

  1. The rate of production one minute into the process is f(1)=31=3f'(1) = 3\sqrt{1} = 3 grams per minute.

  2. The quantity of NaCl produced over the next three minutes is:

    f(4)f(1)=14f(t)dt=143tdt=[2t3/2]14=2×(81)=14\displaystyle f(4)-f(1) = \int_1^4\,f'(t)\,{\rm d}t = \int_1^4\,3\sqrt{t}\,{\rm d}t = \left[2t^{3/2}\right]_1^4 = 2\times(8-1) = 14

    t = sp.Symbol('t') sp.integrate(3*sp.sqrt(t),(t,1,4))

    14\displaystyle 14

  3. The mean rate is the constant rate which would give the same overall effect:

    1baabf(t)dt=141143tdt=143\displaystyle {1\over b-a}\int_a^b\,f'(t)\,{\rm d}t = {1\over 4-1}\int_1^4\,3\sqrt{t}\,{\rm d}t = {14\over 3}

    sp.integrate(3*sp.sqrt(t),(t,1,4))/(4-1)

143\displaystyle \frac{14}{3}

Substitution Method

Suppose we wish to integrate:

I=f(g(x)) dx            e.g.  ab(34x)5 dx\displaystyle I=\int f(g(x))~{\rm d}x~~~~~~~~~~~{\rm~e.g.}~~\int_{a}^{b} (3-4x)^{-5}~{\rm d}x

In general, for g(x)=ug(x)=u, we can write:

x1x2f(g(x)) dx=u1u2f(u)dxdudu\displaystyle \int_{x_1}^{x_2}\thinspace f(g(x))~{\rm d}x = \int_{u_1}^{u_2}\thinspace f(u) {{\rm d}x\over {\rm d}u} {\rm d}u

This can be thought of as being like the integral version of the chain rule.

Examples

Consider:

ab(2x+3)4 dx             Equation (7)\displaystyle \int_{a}^{b} (2x + 3)^4~{\rm d}x~~~~~~~~~~~~~{\rm Equation ~(7)}

Multiplying this out and then integrating it would be very tedious. Try a substitution instead:

u=2x+3   x=12(u3)=u232    dxdu=12\displaystyle u=2x+3~~~\Longleftrightarrow x={1\over 2}(u-3)={u\over 2}-{3\over 2}~~~~ \Longleftrightarrow {{\rm d}x\over {\rm d}u}={1\over 2}

Substitute into Equation (7) above:

u(1.u(b)u4×12 du=12u(1.u(b)u4 du=12[15u5]u(1.u(b)=12[15(2x+3)5]ab\displaystyle \int_{u(1.}^{u(b)} u^4 \times {1\over 2}~{\rm d}u ={1\over 2}\int_{u(1.}^{u(b)} u^4~du = {1\over 2}\biggr[{1\over 5}u^5\biggl]_{u(1.}^{u(b)}= {1\over 2}\biggr[{1\over 5}(2x+3)^5\biggl]_a^b

a, b = sp.symbols('a b') sp.integrate((2*x + 3)**4,(x,a,b))

16a5524a472a3108a281a+16b55+24b4+72b3+108b2+81b\displaystyle - \frac{16 a^{5}}{5} - 24 a^{4} - 72 a^{3} - 108 a^{2} - 81 a + \frac{16 b^{5}}{5} + 24 b^{4} + 72 b^{3} + 108 b^{2} + 81 b


Let's look at another example:

ab(34x)5 dx             Equation (8)\displaystyle \int_{a}^{b} (3-4x)^{-5}~{\rm d}x~~~~~~~~~~~~~{\rm Equation~(8)}

Let:

u=34x   x=14(3u)=34u4    dxdu=14\displaystyle u=3-4x~~~\Longleftrightarrow x={1\over 4}(3-u)={3\over 4}-{u\over 4}~~~~\Longleftrightarrow {{\rm d}x\over {\rm d}u}=-{1\over 4}

Substitute into Equation (8) above:

u(1.u(b)u5×14 du=14u(1.u(b)u5 du=14[14u4]u(1.u(b)\displaystyle \int_{u(1.}^{u(b)} u^{-5} \times {-1\over 4}~{\rm d}u = -{1\over 4}\int_{u(1.}^{u(b)} u^{-5}~{\rm d}u = -{1\over 4}\biggr[{1\over-4}u^{-4}\biggl]_{u(1.}^{u(b)} >    =116[(34x)4]ab\displaystyle \qquad \qquad \qquad \qquad \qquad \qquad \qquad \qquad ~~~ = {1\over 16}\biggr[(3-4x)^{-4}\biggl]_a^b

sp.integrate((3 - 4*x)**(-5),(x,a,b))

14096b412288b3+13824b26912b+129614096a412288a3+13824a26912a+1296\displaystyle \frac{1}{4096 b^{4} - 12288 b^{3} + 13824 b^{2} - 6912 b + 1296} - \frac{1}{4096 a^{4} - 12288 a^{3} + 13824 a^{2} - 6912 a + 1296}

Introductory problems

Introductory problems 1

Integrate the following functions with respect to xx. Remember that you can check your own answers by differentiating your results:

  1. x31x4+x2\displaystyle x^3-{1\over{x^4}}+x^2

  2. x3+13x4\displaystyle \sqrt[3]{x}+\frac{1}{3\sqrt[4]{x}}

  3. 1x2+1x37\displaystyle \frac{1}{x^2} + \frac{1}{\sqrt[3]{x}} - 7

Introductory problems 2

Evaluate the following definite integrals:

  1. 12x1/2 dx\displaystyle \int_1^2 x^{1/2}~{\rm d}x

  2. 23x2/3 dx\displaystyle \int_2^3 x^{-2/3}~{\rm d}x

  3. 0ln(2)e3x dx\displaystyle \int_0^{\ln(2)}e^{3x}~{\rm d}x

  4. 02(x+1)1/5 dx\displaystyle \int_0^2(x+1)^{1/5}~{\rm d}x

Introductory problems 3

Find the integrals below by making the substitution suggested:

  1. x2(2x35)3 dxusingu=2x35\displaystyle \int x^2(2x^3-5)^3~{\rm d}x \qquad\rm{using}\qquad u = 2x^3-5

  2. x72x2 dxusingu=72x2\displaystyle \int x\sqrt{7-2x^2}~{\rm d}x \qquad\rm{using}\qquad u = 7-2x^2

  3. 01ex(3ex10)4 dxusingu=3ex10\displaystyle \int_0^1 e^x(3e^x-10)^4~{\rm d}x \qquad\rm{using}\qquad u = 3e^x-10

  4. x3153x4 dxusingu=153x4\displaystyle \int x^3\sqrt{15-3x^4}~{\rm d}x \qquad\rm{using}\qquad u = 15-3x^4

  5. 04x34+x5/2 dxusingu=4+x5/2\displaystyle \int_0^4 \sqrt{x^3}\,\sqrt{4+x^{5/2}}~{\rm d}x \qquad\rm{using}\qquad u = 4+x^{5/2}

  6. 01xn1(1xn)2 dxusingu=1xn\displaystyle \int_0^1 x^{n-1}(1-x^{n})^2~{\rm d}x \qquad\rm{using}\qquad u = 1-x^{n}

Introductory problems 4

By making suitable substitutions, find the indefinite integrals of:

  1. 2(6x5)3\displaystyle 2(6x-5)^3

  2. 7xx22\displaystyle \frac{7x}{x^2-2}

  3. 35x\displaystyle \frac{3}{\sqrt{5-x}}

  4. 1xa\displaystyle \frac{1}{x-a}

Main problems

Main problems 1

Electrostatic work: the force acting between two electric charges q1q_1 and q2q_2 separated by distance xx in a vacuum is given by Coulomb's inverse square law:

F(x)=q1q24πϵ0x2\displaystyle F(x) = {q_1 q_2\over 4\pi \epsilon_0 x^2}

where ϵ0\epsilon_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 q2q_2 due to the presence of q1q_1 acts in a positive xx direction, away from q1q_1. Unlike charges (of opposite signs such as the proton and electron in the hydrogen atom) attract, and the force on q2q_2 is directed towards q1q_1 (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 q2q_2 from infinity to the distance xx from q1q_1. The force FF must be applied to overcome the repulsion.

  1. Explain why the total work done is given by

    W=xF(x) dx=q1q24πϵ0xdxx2\displaystyle W=-\int_\infty^x F(x')~{\rm d}{x'} = -{q_1 q_2\over 4\pi \epsilon_0} \int_\infty^x {{\rm d}{x'}\over {x'}^2}.

  2. Calculate the work, WW, in Joules when

    • x=5.3×1011mx =5.3 \times 10^{-11}\,\rm{m},

    • q1=q2=1.6×1019Cq_1=q_2=1.6 \times 10^{-19}\,\rm{C},

    • ϵ0=8.85×1012Fm1\epsilon_0=8.85 \times 10^{-12}\,\rm{Fm}^{-1}.

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)r=f(t), where tt is measured in years and t=0t=0 is the start of 1990.

  1. Write down a definite integral which represents the total quantity of oil used between the start of 1990 and the end of 2020.

  2. Calculate this integral using the function r(t)=32e0.05t\displaystyle r(t)=32 e^{0.05t}.

Main problems 3

Since 1850, global carbon emissions have been rising exponentially. Let C(t)C(t) represent the rate that carbon is emitted into the atmosphere, measured in Gigatonnes per year, where tt 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,C(t) = ke^{pt}, where kk and pp are positive constants.

  1. What are the units of kk and pp?

  2. 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 kk and pp.

  3. Calculate the total quantity of carbon emitted since the start of 1850.

Main problems 4

The velocity vv of blood in a cylindrical vessel of radius RR and length ll is given by

v(r)=P(R2r2)4ηlv(r) = {P(R^2 - r^2)\over 4\eta l}

where η\eta and PP are constants, and rr is the radial distance from the cylinder's axis.

Find the average velocity of blood along the radius of the cylinder (i.e. for 0rR0\leq r\leq R), and compare this with the maximum velocity.

Main problems 5

Consider the function y=4x3+2x28x+2\displaystyle y = 4x^3 +2x^2-8x + 2.

  1. Draw an accurate graph of this function for values of xx between 4-4 and 44.

  2. Calculate the turning points of the curve and mark these on the graph.

  3. On your graph, shade in the region under the curve between x=2x=-2 and x=2x=2 and estimate its area.

  4. Integrate the function between x=2x=-2 and x=2x=2. Is this an accurate calculation of the area of the shaded region in part 3?

  5. Identify and explain any differences you find between your estimate in part 3 and your calculation in part 4.

Extension problems

Extension problems 1

Evaluate the following definite integrals:

  1. π/2π/23cos(x)dx\displaystyle \int_{-\pi/2}^{\pi/2} 3\cos (x)\,{\rm d}x

  2. π2πcos(x)sin(x)dx\displaystyle \int_{\pi\over 2}^{\pi}\cos (x)\,\sin(x)\,{\rm d}x

  3. 0π(cos2(x)+sin2(x))dx\displaystyle \int_0^\pi(\cos^2(x)+\sin^2(x))\,{\rm d}x

Extension problems 2

Let uu and vv be functions of xx.

  1. Given that ddx(uv)=udvdx+vdudx,\displaystyle \def\dd#1#2{{\frac{{\rm d}#1}{{\rm d}#2}}} \quad\dd{}{x}(uv) = u\dd{v}{x} + v\dd{u}{x},\quad show that v dudx dx=uvu dvdx dx.\displaystyle \def\dd#1#2{{\frac{{\rm d}#1}{{\rm d}#2}}} \quad\int v~\dd{u}{x}~{\rm d}x = uv-\int u~\dd{v}{x}~{\rm d}x.

  2. By using this 'integration by parts' formula, and substituting z=x2z=x^2 or otherwise, show that 0xn ex2 dx=12(n1)0xn2ex2 dxfor  n>1.\int_0^{\infty} x^n~e^{-x^2}~{\rm d}x={1\over 2}(n-1)\int_0^{\infty} x^{n-2}e ^{-x^2}~dx\qquad \rm{for}\;n>1.

  3. Hence evaluate 0x5 ex2 dx.\displaystyle \int_0^{\infty} x^5~e^{-x^2}~{\rm d}x. :::

Extension problems 3

A country wishes to achieve net-zero CO2*{2} emissions in 50 years. At the start of the program, their emissions (EE) are 800MtCO2_{2}year1^{-1}. They decide that they will be able to reduce their emissions at a stable rate, so that each year they emit 12MtCO2_{2}year1^{-1} less than the previous year.

  • Write down the rate of change of the countries emissions (EE), each year (tt), dEdt\def\dd#1#2{{\frac{{\rm d}#1}{{\rm d}#2}}} \dd{E}{t}. Use this to calculate the total emissions that the country had produced over the 50 years.

After 10 years of these emissions, the country starts a CO2_{2} removal program, whereby a certain amount of CO2_{2} is captured from the atmosphere and sequestered underground each year. This CO2_{2} follows the curve R=0.1t2tR = 0.1t^{2} - t where RR is the amount of CO2_{2} removal in MtCO2_{2}year1^{-1}.

  • Determine whether the country achieves their 50 year net-zero emissions goal by finding the year in which the emissions produced are equal to the emissions removed.

After the 50 year program, the countries emission rate stabilises, and they emit the same amount of CO2_{2} each year after that. The CO2_{2} absorption rate per year follows the same trend as before. The country wishes to have not contributed to global warming at all since the start of the program. This means their net total CO2_{2} emissions over the entire program would have to be zero.

  • Show that is takes approximately 109 years for the country to have a net-zero effect on global warming since the start of the program.