Skip to main content

Scientific Computing

Essential Maths

Integration 1 []

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 2


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


Integration by Parts and by Partial Fractions

Integration reverses the process of differentiation

In general

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

Reminder: method 1: integration by substitution

This method can be thought of as an integral version of the chain rule. Suppose we wish to integrate:

I=f(g(x)) dx=f(u) dx\displaystyle I=\int f(g(x))~dx= \int f(u)~dx > I=f(u)dxdu du\displaystyle I =\int f(u){dx\over du}~du

Integration Method 2: Integration by Parts

Recall that:

ddxf(x) g(x)=f(x) g(x)+g(x) f(x)\displaystyle {d\over dx}f(x)~g(x)=f(x)~g'(x)+ g(x)~f'(x)

Integrate and rearrange to get:

abf(x) g(x) dx=[  f(x) g(x)  ]ababg(x) f(x) dx\displaystyle \int\limits_a^b f(x)~g'(x)~dx=\biggr[\;f(x)~g(x)\;\biggl]_a^b-\int\limits_a^b g(x)~f'(x)~dx

This is known as the formula for 'integrating by parts' and can also be written:

abu dvdx dx  =  [uv]ababv dudx dx\displaystyle \int\limits_a^b u~{dv\over dx}~dx ~~= ~~ \biggr[uv\biggl]^b_a-\int\limits_a^b v~{du\over dx}~dx

or

abu v dx  =  [uv]ababv u dx\displaystyle \int\limits_a^b u~v'~dx~~ =~~ \biggr[uv\biggl]^b_a-\int\limits_a^b v~u'~dx

with f(x)uf(x) \equiv u and g(x)vg(x) \equiv v.

Integration by parts: Example 1

abx (x+1) dx=abx (x+1)1/2 dx\displaystyle \int\limits_a^b x~\sqrt{(x+1)}~dx=\int\limits_a^b x~(x+1)^{1/2}~dx

Choose

u=xandv=(x+1)\displaystyle u=x\qquad{\rm and}\qquad v'=\sqrt{(x+1)}

so that:

u=1andv=23(x+1)3/2\displaystyle u'=1\qquad{\rm and}\qquad v={2 \over 3}(x+1)^{3/2}.

Choose

u=xandv=(x+1)\displaystyle u=x\qquad{\rm and}\qquad v'=\sqrt{(x+1)}

so that:

u=1andv=23(x+1)3/2\displaystyle u'=1\qquad{\rm and}\qquad v={2 \over 3}(x+1)^{3/2}

Then:

abx (x+1) dx=[x 23(x+1)3/2]abab1×23(x+1)3/2 dx\displaystyle \int\limits_a^b x~\sqrt{(x+1)}~dx =\biggr[x~{2\over 3}(x+1)^{3/2}\biggl]_a^b - \int\limits_a^b 1 \times {2\over 3}(x+1)^{3/2}~dx > =[23 x (x+1)3/2]ab[2325(x+1)5/2]ab\displaystyle =\biggr[{2\over 3}~x~(x+1)^{3/2}\biggl]_a^b- \biggr[{2\over 3}\cdot {2\over 5}(x+1)^{5/2}\biggl]_a^b

If we had chosen the other option for uu and vv' we would have got:

[(x+1)1/2 x22]abab12 1(x+1) x22 dx\displaystyle \biggr[(x+1)^{1/2}~{x^2\over 2}\biggl]_a^b - \int\limits_a^b {1\over 2}~{1\over \sqrt{(x+1)}}~{x^2\over 2}~dx

The second term is worse than the integral we started with! It's important to choose uu and vv carefully. This comes with practice.

Integration by parts: Example 2

Let us calculate the indefinite integral,

lnx dx\displaystyle \int \ln x~dx

We can do a bit of a trick. Let:

u=lnxu=1xandv=1v=x\displaystyle u=\ln x \quad\Longrightarrow\quad u'={1\over x}\qquad{\rm and}\qquad v'=1\Longrightarrow v=x

Putting these into our equation:

lnx dx=lnx xx 1xdx\displaystyle \int \ln x~dx\quad=\quad\ln x~\cdot x - \int x~\frac{1}{x}dx > =xlnx1dx=xlnxx+C\displaystyle = \quad x \ln x - \int 1 dx\quad=\quad x \ln x - x + C

We can also check this calculation using SymPy:

import sympy as sp x = sp.symbols('x') sp.integrate(sp.log(x),x)

xlog(x)x\displaystyle x \log{\left(x \right)} - x

Integration by parts: Example 3

0x3 ex dx\displaystyle \int\limits^{\infty}_0 x^3~e^{-x}~dx

Using the formula:

(uvdx=[uv]vudx)\displaystyle \biggl(\int u\thinspace v'\thinspace dx = [u\thinspace v]-\int v\thinspace u'\thinspace dx\biggr)

Choose

u=x3andv=ex\displaystyle u=x^3\qquad{\rm and}\qquad v'=e^{-x}

so that:

u=3x2andv=ex\displaystyle u'=3x^2\qquad{\rm and}\qquad v=-e^{-x}

Then:

0x3 ex dx=[x3 ex]0+03x2 ex dx\displaystyle \int\limits^{\infty}_0 x^3~e^{-x}~dx=-\biggr[x^3~e^{-x}\biggl]^{\infty}_0 +\int\limits^{\infty}_0 3x^2~e^{-x}~dx

Now apply integration by parts to the right-hand side:

Choose

u=3x2andv=ex\displaystyle u=3x^2\qquad{\rm and}\qquad v'=e^{-x}

so that:

u=6xandv=ex\displaystyle u'=6x\qquad{\rm and}\qquad v=-e^{-x}

Then:

03x2 ex dx=[3x2 ex]0+06x ex dx\displaystyle \int\limits^{\infty}_0 3x^2~e^{-x}~dx=-\biggr[3x^2~e^{-x}\biggl]^{\infty}_0 +\int\limits^{\infty}_0 6x~e^{-x}~dx

And, once more:

Choose

u=6xandv=ex\displaystyle u=6x\qquad{\rm and}\qquad v'=e^{-x}

so that:

u=6andv=ex\displaystyle u'=6\qquad{\rm and}\qquad v=-e^{-x}

Then:

06x ex dx=[6x ex]0+06 ex dx\displaystyle \int\limits^{\infty}_0 6x~e^{-x}~dx =-\biggr[6x~e^{-x}\biggl]^{\infty}_0 +\int\limits^{\infty}_0 6~e^{-x}~dx > 06 ex dx=[6 ex]0=6e+6e0=6\displaystyle \Longrightarrow \int\limits^{\infty}_0 6~e^{-x}~dx=-\biggr[6~e^{-x}\biggl]^{\infty}_0=-6e^{-\infty}+6e^0=6

(Since e=0e^{-\infty}=0 and e0=1e^0=1)

The other terms all go to zero:

[x3 ex]0=3 e+0=0\displaystyle -\bigr[x^3~e^{-x}\bigl]^{\infty}_0 =-{\infty}^3~e^{-\infty} + 0 =0 > [3x2 ex]0=32 e+0=0\displaystyle -\bigr[3x^2~e^{-x}\bigl]^{\infty}_0 =-3{\infty}^2~e^{-\infty} + 0 =0

So, to answer our original question:

0x3 ex dx=6\displaystyle \int\limits^{\infty}_0 x^3~e^{-x}~dx=6

Let's also check it with SymPy:

sp.integrate(x**3 * sp.exp(-x),(x,0,sp.oo))

6\displaystyle 6

This result actually generalises:

0xn ex dx=n!\displaystyle \int\limits^{\infty}_0 x^n~e^{-x}~dx=n!

Integration by parts: Example 4, trigonometry

Recall that:

ddx(sinx)=cosx\displaystyle {d\over dx}(\sin x)=\cos x > ddx(cosx)=sinx\displaystyle {d\over dx}(\cos x)=-\sin x

Let's try and calculate the following integral:

ab cosx  ex dx=I\displaystyle \int\limits^b_a~\cos x\;e^{-x}~dx = I

Choose

u=cosxandv=ex\displaystyle u=\cos x\qquad{\rm and}\qquad v'=e^{-x}

so that:

u=sinxandv=ex\displaystyle u'=-\sin x\qquad{\rm and}\qquad v=-e^{-x}

Then:

I=[cosx   ex]abab ()sinx ()ex dx\displaystyle I =\biggr[-\cos x~\; e^{-x}\biggl]^b_a -\int\limits^b_a ~(-)\sin x~(-)e^{-x}~dx > I=[cosx   ex]ab    ab ()sinx ()ex dx\displaystyle I =\biggr[-\cos x~\; e^{-x}\biggl]^b_a~~-~~\int\limits^b_a ~(-)\sin x~(-)e^{-x}~dx

Next, choose

u=sinxandv=ex\displaystyle u=\sin x\qquad{\rm and}\qquad v'=e^{-x}

so that:

u=cosxandv=ex\displaystyle u'=\cos x\qquad{\rm and}\qquad v=-e^{-x}

Then:

I=[cosx    ex]ab    [sinx ()ex]ab  +  ab cosx ()ex dx\displaystyle I =\biggr[-\cos x~\;~e^{-x}\biggl]^b_a~~-~~\biggr[\sin x~(-)e^{-x}\biggl]^b_a ~~+~~\int\limits^b_a ~\cos x~(-)e^{-x}~dx

The last term is the integral we started with:

   2 ab cosx ex dx = [sinx   ex]ab    [cosx   ex]ab\displaystyle \Longrightarrow~~~2~\int\limits^b_a ~\cos x~e^{-x}~dx~ =~\biggr[\sin x~\; e^{-x}\biggl]^b_a~~ -~~\biggr[\cos x~\; e^{-x}\biggl]^b_a

Integration Method 3: Partial Fractions

If we want to calculate the integral below, none of the previous rules allow us to make much progress.

dx(2x+1)(x5)\displaystyle \int {dx \over (2x+1)(x-5)}

But, in this case, we can try splitting the denominator up into two fractions that we can deal with:

Let     1(2x+1)(x5)=A(2x+1)+B(x5)\displaystyle {\rm Let~~~~~} {1 \over (2x+1)(x-5)}={A\over (2x+1)} + {B\over (x-5)}

If we multiply both sides by (2x+1)(x5)(2x+1)(x-5), we get:

A(x5)+B(2x+1)=1\displaystyle A(x-5)+B(2x+1)=1 so Ax5A+B2x+B=1Ax-5A+B2x+B=1

We can then equate coefficients of xx:

A+2B=0    thus  A=2B          (A)\displaystyle A+2B=0~~~~{\rm thus~~} A=-2B~~~~~~~~~~\rm (A)

Equate units (coefficients of x0x^0):

5A+B=1    so from (A):  10B+B=1,  B=111 ,  A=211\displaystyle -5A+B=1 ~~{\rm~~so~from~(A):~~} 10B+B=1,~~B={1\over 11}~,~~A=-{2\over 11}

Thus:

dx(2x+1)(x5)=2dx11(2x+1)+dx11(x5)\displaystyle \int {dx \over (2x+1)(x-5)}=-\int {2 dx\over 11(2x+1)} + \int {dx\over 11(x-5)}

Now use method of substitution on the first fraction:

u=2x+1\displaystyle u=2x+1

so dudx=2\displaystyle \frac{du}{dx}=2 and dxdu=1/2\displaystyle \frac{dx}{du}=1/2

And on the second fraction:

w=x5\displaystyle w=x-5

so dwdx=1\displaystyle \frac{dw}{dx}=1 and dxdw=1\displaystyle \frac{dx}{dw}=1

2du2×11×u+dw11w=lnu11+lnw11\displaystyle \int {2 du \over 2 \times 11 \times u} + \int {dw\over 11w}= -{\ln u\over 11} + {\ln w \over 11} > =ln2x+111+lnx511\displaystyle =-{\ln |2x+1|\over 11} + {\ln |x-5| \over 11}

SymPy can also solve integrals requiring partial fractions:

sp.integrate(1/((2*x + 1)*(x - 5)),x)

log(x5)11log(x+12)11\displaystyle \frac{\log{\left(x - 5 \right)}}{11} - \frac{\log{\left(x + \frac{1}{2} \right)}}{11}

This answer seems different because of the arbitrary constant of integration.

Introductory problems

Introductory problems 1

By using suitable substitutions, evaluate the following integrals:

  1. x2(x3+4)2  dx\displaystyle \def\d#1{{\rm d}#1} \int x^2(x^3+4)^2~~\d{x}

  2. ex(54ex) dx\displaystyle \def\d#1{{\rm d}#1} \int e^{-x}(5-4e^{-x})~\d{x}

  3. (1+x)(4x2+8x+3) dx\displaystyle \def\d#1{{\rm d}#1} \int (1+x)\sqrt{(4x^2+8x+3)}~\d{x}

  4. 3xe(x2+1) dx\displaystyle \def\d#1{{\rm d}#1} \int 3x e^{(x^2+1)}~\d{x}

Introductory problems 2

Find the indefinite integrals, with respect to xx, of the following functions:

  1. xe3bx\displaystyle x\,e^{3bx}

  2. x3e3x\displaystyle x^3\,e^{-3x}

  3. xcos(x)\displaystyle x \cos (x)

  4. ebxsin(x)\displaystyle e^{bx} \sin(x)

Introductory problems 3

Sketch the curve y=(x2)(x5)y=(x-2)(x-5) and calculate by integration the area under the curve bounded by x=2x=2 and x=5x=5.

Main problems

Main problems 1

Evaluate the following indefinite and definite integrals:

  1. 6(7x)3 dx\displaystyle \def\d#1{{\rm d}#1} \int \frac{6}{(7-x)^3}~\d{x}

  2. 13x3(9x4)5 dx\displaystyle \def\d#1{{\rm d}#1} \int 13x^3(9-x^4)^5~\d{x}

  3. 255log(x) dx\displaystyle \def\d#1{{\rm d}#1} \int_2^5 5\log(x)~\d{x}

  4. xx(1+log(x)) dx\displaystyle \def\d#1{{\rm d}#1} \int x^x\,(1 + \log(x))~\d{x}

Main problems 2

Suppose the area A(t)A(t) (in cm2^2) of a healing wound changes at a rate

dAdt=4t3,\displaystyle \def\dd#1#2{{\frac{{\rm d}#1}{{\rm d}#2}}} \dd{A}{t} = -4t^{-3},

where tt, measured in days, lies between 1 and 10, and the area is 22\,cm2^2 after 1 day. What will the area of the wound be after 10 days?

Main problems 2

A rocket burns fuel, so its mass decreases over time.

If it burns fuel at a constant rate ρkg/s\rho\,{\rm kg/s}, and if the exhaust velocity relative to the rocket is a constant vem/sv_e\,{\rm m/s}, then there will be a constant force of magnitude ρve\rho v_e propelling it.

The rocket starts burning fuel at t=0st=0\,{\rm s} with total mass of m0kgm_0\,{\rm kg}, and runs out of fuel at a later time t=tfst=t_f\,{\rm s}, with a final mass of mfkgm_f\,{\rm kg}.

  1. Newton's second law tells us that the instantaneous acceleration aa of the rocket at time tt is equal to the force propelling it at that time, divided by its mass at that time. Write down an expression for aa as a function of tt.

  2. By integrating this expression, show that the rocket's total change in velocity is given by veln(m0mf).\displaystyle v_e \ln\left({m_0\over m_f}\right).

Main problems 3

The flow of water pumped upwards through the xylem of a tree, FF, is given by:

F=M0(p+qt)3/4,\displaystyle F = M_0(p+qt)^{3/4},

where tt is the tree's age in days, pp and qq are positive constants, and M0p3/4M_0p^{3/4} is the mass of the tree when planted (i.e.\ at t=0t=0).

Determine the total volume of water pumped up the tree in its tenth year (ignoring leap years) if:

  • p=10p=10,

  • q=0.01q=0.01\,day1^{-1}, and

  • M0=0.92M_0=0.92\,l\,day1^{-1}.

Extension problems

Extension problems 1

Express 1x(x216)in the formAx+B(x+4)+C(x4)\displaystyle \frac{1}{x(x^2-16)}\quad{\rm in~the~form}\quad\frac{A}{x} + \frac{B}{(x+4)} + \frac{C}{(x-4)}.

Hence calculate 1x(x216)dx.\displaystyle \def\d#1{{\rm d}#1} \int\frac{1}{x(x^2-16)}\,\d{x}.

Extension problems 2

The probability that a molecule of mass mm in a gas at temperature TT has speed vv is given by the Maxwell-Boltzmann distribution:

f(v)=4π(m2πkT)3/2v2emv2/2kT\displaystyle f(v) = 4 \pi \left({m\over 2\pi k T} \right)^{3/2} v^2 e^{-mv^2/2kT}

where kk is Boltzmann's constant. Find the average speed:

v=0vf(v)dv.\displaystyle \def\d#1{{\rm d}#1} \overline {v} =\int_0^{\infty}v\,f(v)\,\d{v}.

Extension problems 3

Baranov developed expressions for commercial yields of fish in terms of lengths, LL, of the fish. His formula gave the total number of fish of length LL as kecL\displaystyle k\,e^{-cL}, where cc and kk are constants (kk is positive).

  1. Give a sketch of the graph f(L)=kecL\displaystyle f(L)=k\,e^{-cL}. (Something decreasing, concave upward and asymptotic to horizontal axis will do.) On your sketch, introduce marks on the horizontal axis that represent lengths L=1,L=2,L=3,L=4andL=5L=1, L=2, L=3, L=4 {\rm and } L=5. Now draw a rectangle on your sketch that represents the number of fish whose lengths are between L=3L=3 and L=4L=4.

  2. Explain how we can represent the total number of fish NN as an area. Show that this number equals k/ck/c.

  3. Only fish longer than L0L_0 count as commercial. Hence, assuming that the fish are all similar in shape (i.e. their width and breadth scales with their length) and of equal density ρ\rho, show that the weight, WW, of the commercial fish population is

    W=L0+akρL3ecLdL,\displaystyle \def\d#1{{\rm d}#1} W= \int_{L_0}^{+\infty} a\, k \rho\,L^3 e^{-cL}\,\d{L},

    and hence that

    W=NaρecL0c3((cL0)3+3(cL0)2+6cL0+6),\displaystyle W={N\, a\, \rho\, e^{-cL_0}\over c^3} \left((cL_0)^3 +3(cL_0)^2+ 6cL_0 +6\right),

    where aa is a constant.