Skip to main content

Scientific Computing

Essential Maths

Differentiati... []

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

Differentiation 3


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


Exponentials and Partial Differentiation

Examples of applying chain rule to the exponential function

  1. y=eax\displaystyle y=e^{-ax}

    • Let u=axdudx=a\displaystyle u=-ax\Rightarrow\frac{{\rm d}u}{{\rm d}x}=-a.

    • Thus y=eu\displaystyle y=e^u and

    • dydu=eu    dydx=dydu×dudx=eu×(1.=aeax.\displaystyle \frac{{\rm d}y}{{\rm d}u}=e^u~~\Rightarrow~~\frac{{\rm d}y}{{\rm d}x}=\frac{{\rm d}y}{{\rm d}u}\times\frac{{\rm d}u}{{\rm d}x}=e^u\times(-1.=-ae^{-ax}.

  2. y=ex2\displaystyle y = e^{x^2}

    • Then, letting u=x2\displaystyle u = x^2

    • ddxex2=dydx=dydu×dudx=eu2x=ex22x.\displaystyle \frac{{\rm d}}{{\rm d}x}e^{x^2}=\frac{{\rm d}y}{{\rm d}x}=\frac{{\rm d}y}{{\rm d}u}\times\frac{{\rm d}u}{{\rm d}x}=e^u\cdot 2x = e^{x^2}\cdot 2x.

So an important generalization is:

ddxef(x)=ef(x)f(x)\displaystyle \frac{{\rm d}}{{\rm d}x}e^{f(x)}=e^{f(x)}f'(x) for any function f(x)f(x)

Example with the natural logarithm

  1. y=ln(ax)2=2ln(ax)=2lnu\displaystyle y=\ln(a-x)^2=2\ln(a-x)=2\ln u.

    • Let u=(ax)\displaystyle u=(a-x):

    • dudx=1  and     dydu=2u   Thus    dydx=2u×(1)=2ax\displaystyle \Rightarrow {{\rm d}u\over {\rm d}x}=-1~~{\rm and~~~~~}{{\rm d}y\over {\rm d}u}={2\over u}~~~{\rm Thus~~~~}{{\rm d}y\over {\rm d}x}={2\over u}\times (-1)={-2\over a-x}

This also generalises:

ddxln(f(x))=f(x)f(x)\displaystyle \frac{{\rm d}}{{\rm d}x}\ln(f(x)) = {f'(x)\over f(x)}

The Derivative of axa^x

By the properties of logarithms and indices we have

ax=(elna)x=e(xlna)\displaystyle a^x = \left({e^{\ln a}}\right)^x=e^{\left({x\cdot\ln a}\right)}.

Thus, as we saw above we have:

ddxax=ddxe(xlna)=e(xlna)ddx(xlna)=axlna\displaystyle \frac{{\rm d}}{{\rm d}x}a^x = \frac{{\rm d}}{{\rm d}x}e^{\left({x\cdot\ln a}\right)} = e^{\left({x\cdot\ln a}\right)}\frac{{\rm d}}{{\rm d}x}{\left({x\cdot\ln a}\right)} =a^x\cdot\ln a

Similarly, in general:

ddxaf(x)=af(x)lnaf(x)\displaystyle \frac{{\rm d}}{{\rm d}x}a^{f(x)} = a^{f(x)}\cdot \ln a\cdot f'(x)

Sympy Example

Let's try and use Sympy to demonstrate this:

import sympy as sp x, a = sp.symbols('x a') # declare the variables x and a f = sp.Function('f') # declare a function dependent on another variable sp.diff(a**f(x),x) # write the expression we wish to evaluate

af(x)log(a)ddxf(x)\displaystyle a^{f{\left(x \right)}} \log{\left(a \right)} \frac{d}{d x} f{\left(x \right)}

The Derivative of logax\displaystyle \log_a x\,\,

Recall the conversion formula logax=lnxlna\displaystyle \log_a x = {{\ln x}\over {\ln a}} and note that lna\ln a is a constant. Thus:

ddxlogax=ddx(1lnalnx)=(1lna)ddxlnx=(1lna)1x=1xlna\displaystyle \frac{{\rm d}}{{\rm d}x}\log_a x = \frac{{\rm d}}{{\rm d}x}\left({1\over{\ln a}}\cdot\ln x\right) = \left({1\over{\ln a}}\right)\cdot\frac{{\rm d}}{{\rm d}x}\ln x = \left({1\over{\ln a}}\right)\cdot{1\over {x}} = {1\over{x\cdot\ln a}}

In general:

ddxlogaf(x)=f(x)f(x)(ln1.\displaystyle \frac{{\rm d}}{{\rm d}x}\log_a f(x) = {{f'(x)} \over {f(x){(\ln 1.}}}

Sympy Example

Again, let's use SymPy to demonstrate this:

x, a = sp.symbols('x a') # declare the variables x and a f = sp.Function('f') # declare a function dependent on another variable sp.diff(sp.log(f(x),a),x) # write the expression we wish to evaluate

ddxf(x)f(x)log(a)\displaystyle \frac{\frac{d}{d x} f{\left(x \right)}}{f{\left(x \right)} \log{\left(a \right)}}

Further examples

  1. Product Rule: Let y=x2ex\displaystyle y = x^2\,e^x. Then:

    dydx=ddxx2ex=ddxx2ex+x2ddxex=(2x+x2)ex\displaystyle {{dy\over dx}}={d\over dx}x^2e^x={d\over dx}x^2\cdot e^x+x^2\cdot{d\over dx}e^x = (2x + x^2)e^x

  2. Quotient Rule: Let y=exx\displaystyle y = {{e^x}\over x}. Then:

    dydx=ddxexxexddxxx2=exxex1x2=x1x2ex\displaystyle {{dy\over dx}}={{{{d\over dx}e^x}\cdot x - e^x\cdot {d\over dx}x}\over {x^2}}={{e^x\cdot x - e^x\cdot 1\over {x^2}}}={{x - 1}\over x^2}e^x

  3. Chain Rule: y=ex2\displaystyle y = e^{x^2}. Then, letting f(x)=x2\displaystyle f(x) = x^2:

    ddxex2=ef(x)f(x)=ex22x\displaystyle \frac{{\rm d}}{{\rm d}x}e^{x^2} = e^{f(x)}f'(x) = e^{x^2}\cdot 2x

  4. y=ln(x2+1)\displaystyle y=\ln (x^2 + 1). Then, letting f(x)=x2+1f(x) = x^2+1:

    ddxln(x2+1)=f(x)f(x)=2xx2+1\displaystyle \frac{{\rm d}}{{\rm d}x}\ln(x^2+1) = {f'(x)\over f(x)} = {2x\over {x^2+1}}

  5. ddx2x3=2x3ln23x2\displaystyle {{\rm d}\over {\rm d}x}2^{x^3}=2^{x^3}\cdot\ln 2\cdot 3x^2

  6. ddx10x2+1=10x2+1ln102x\displaystyle {{\rm d}\over {\rm d}x}10^{x^2+1}=10^{x^2+1}\cdot\ln 10\cdot 2x

  7. ddxlog10(7x+5)=7(7x+5)ln10\displaystyle \frac{{\rm d}}{{\rm d}x}\log_{10}(7x+5)={7\over {(7x+5)\cdot \ln10}}

  8. ddxlog2(3x+x4)=3xln3+4x3ln2(3x+x4)\displaystyle \frac{{\rm d}}{{\rm d}x}\log_2(3^x+x^4)={{3^x\cdot\ln3 + 4x^3}\over{\ln 2\cdot(3^x+x^4)}}

Functions of several variables: Partial Differentiation

Definition: Given a function z=f(x,y)z=f(x,y) of two variables xx and yy, the partial derivative of zz with respect to xx is the function obtained by differentiating f(x,y)f(x,y) with respect to xx, holding yy constant.

We denote this using \partial (the "curly" delta, sometimes pronounced "del") as shown below:

zx=xf(x,y)=fx(x,y)\displaystyle \frac{\partial z}{\partial x}=\frac{\partial}{\partial x}f(x,y) = f_x(x,y)

Example 1

f(x,y)=z=x22y2\displaystyle f(x,y)=z=x^2-2y^2 > fx=zx=2xandfy=zy=4y\displaystyle f_x={\partial z\over \partial x}=2x\qquad\rm{and}\qquad f_y={\partial z\over \partial y}=-4y

Example 2

Let z=3x2y+5xy2\displaystyle z=3x^2y+5xy^2. Then the partial derivative of zz with respect to xx, holding yy fixed, is:

zx=x(3x2y+5xy2)\displaystyle \frac{\partial z}{\partial x}=\frac{\partial}{\partial x}\,\left(3x^2y+5xy^2\right) > =3y2x+5y21\displaystyle \qquad =3y\cdot 2x + 5y^2\cdot 1 > =6xy+5y2\displaystyle \qquad =6xy+5y^2

while the partial of zz with respect to yy holding xx fixed is:

zy=y(3x2y+5xy2)\displaystyle \frac{\partial z}{\partial y}=\frac{\partial}{\partial y}\,\left(3x^2y+5xy^2\right)\, > =3x21+5x2y=3x2+10xy\displaystyle \qquad =3x^2\cdot 1 + 5x\cdot 2y = 3x^2+10xy

Sympy example

In the previous slide we had:

x(3x2y+5xy2)=6xy+5y2\displaystyle \frac{\partial}{\partial x}\,\left(3x^2y+5xy^2\right)\, = 6xy+5y^2

Let's redo this in Sympy:

x, y = sp.symbols('x y') sp.diff(3*x**2*y + 5*x*y**2,x)

6xy+5y2\displaystyle 6 x y + 5 y^{2}

Higher-Order Partial Derivatives

Given z=f(x,y)z = f(x,y) there are now four distinct possibilities for the second-order partial derivatives.

  1. With respect to xx twice:

    x(zx)=2zx2=zxx\displaystyle \frac{\partial}{\partial x}\left(\frac{\partial z}{\partial x}\right) =\frac{\partial^2z}{\partial x^2} =z_{xx}

  2. With respect to yy twice:

    y(zy)=2zy2=zyy\displaystyle \frac{\partial}{\partial y}\left(\frac{\partial z}{\partial y}\right) =\frac{\partial^2z}{\partial y^2} =z_{yy}

  3. First with respect to xx, then with respect to yy:

    y(zx)=2zyx=zxy\displaystyle \frac{\partial}{\partial y}\left(\frac{\partial z}{\partial x}\right) =\frac{\partial^2z}{\partial y\partial x} =z_{xy}

  4. First with respect to yy, then with respect to xx:

    x(zy)=2zxy=zyx\displaystyle \frac{\partial}{\partial x}\left(\frac{\partial z}{\partial y}\right) =\frac{\partial^2z}{\partial x\partial y} =z_{yx}

Example: LaPlace's equation for equilibrium temperature distribution on a copper plate

Let T(x,y)\displaystyle T(x,y) give the temperature at the point (x,y)\displaystyle (x,y).

According to a result of the French mathematician Pierre LaPlace (1749 - 1827), at every point (x,y)\displaystyle (x,y) the second-order partials of T\displaystyle T must satisfy the equation:

Txx+Tyy=0\displaystyle T_{xx} + T_{yy} = 0

We can verify that the function T(x,y)=y2x2\displaystyle T(x,y)=y^2-x^2 satisfies LaPlace's equation:

First with respect to xx:

Tx(x,y)=02x=2xsoTxx(x,y)=2\displaystyle T_x(x,y)=0-2x=-2x\qquad\rm{so}\qquad T_{xx}(x,y)=-2

Then with respect to yy:

Ty(x,y)=2y0=2ysoTyy(x,y)=2\displaystyle T_y(x,y)=2y-0=2y\qquad\rm{so}\qquad T_{yy}(x,y)=2

Finally:

Txx(x,y)+Tyy(x,y)=2+(2)=0\displaystyle T_{xx}(x,y)+T_{yy}(x,y) = 2 + (-2) = 0

which proves the result.

The function z=x2yxy2\displaystyle z=x^2y - xy^2 does not satisfy LaPlace's equation (and so cannot be a model for thermal equilibrium).

First note that

zx=2xyy2\displaystyle z_x = 2xy - y^2 > zxx=2y\displaystyle z_{xx}=2y

and that

zy=x22xy\displaystyle z_y = x^2 - 2xy > zyy=2x\displaystyle z_{yy} =-2x

Therefore:

zxx+zyy=2y2x0\displaystyle z_{xx}+z_{yy}=2y-2x\ne 0

We can also verify this in Sympy like so:

T1 = y**2 - x**2 sp.diff(T1, x, x) + sp.diff(T1, y, y)

0\displaystyle 0

and for the second function:

T2 = x**2*y - x*y**2 sp.diff(T2, x, x) + sp.diff(T2, y, y)

2x+2y\displaystyle - 2 x + 2 y

A Note on the Mixed Partials fxyf_{xy} and fyxf_{yx}

If all of the partials of f(x,y)\displaystyle f(x,y) exist, then fxy=fyx\displaystyle f_{xy}=f_{yx} for all (x,y)\displaystyle (x,y).

Example

Let z=x2y3+3x22y4\displaystyle z = x^2y^3+3x^2-2y^4. Then zx=2xy3+6x\displaystyle z_x=2xy^3+6x and zy=3x2y28y3\displaystyle z_y = 3x^2y^2-8y^3.

Taking the partial of zx\displaystyle z_x with respect to y\displaystyle y we get

zxy=y(2xy3+6x)=6xy2\displaystyle z_{xy}=\frac{\partial}{\partial y}\left(2xy^3+6x\right)=6xy^2

Taking the partial of zy\displaystyle z_y with respect to xx we get the same thing:

zyx=x(3x2y28y3)=6xy2\displaystyle z_{yx}=\frac{\partial}{\partial x}\left(3x^2y^2-8y^3\right)=6xy^2

So the operators x\displaystyle {\partial \over \partial x} and y\displaystyle {\partial \over \partial y} are commutative:

 i.e.     x(zy)    =y(zx)\displaystyle {\rm~i.e.~~~~}~{\partial\over \partial x}\biggr({\partial z\over \partial y}\biggl)~~~~={\partial\over \partial y}\biggr({\partial z\over \partial x}\biggl)

Introductory problems

Introductory problems 1

Differentiate the following functions with respect to xx, using the stated rules where indicated:

  1. Product rule: xex\displaystyle \sqrt{x}\,e^x

  2. Product rule: 3x2log(x)\displaystyle 3x^2 \log(x)

  3. Chain rule: e4x3\displaystyle e^{-4x^3}

  4. Chain rule: ln(x3/26)\displaystyle \ln \sqrt {\left({x^{3/2}\over 6}\right)}

  5. Chain rule: 10x2\displaystyle 10^{x^2}

  6. Any rules: lnx5x7\displaystyle \frac{\ln x}{5x-7}

  7. Any rules: ex2x31\displaystyle \frac{e^x}{2x^3-1}

  8. Any rules: log2(xcos(x))\displaystyle \log_2\left(x\cos(x)\right)

Introductory problems 2

If y=eaxshow that2d2ydx2+adydxa2y=0\displaystyle \quad y=e^{-ax} \quad\rm{show~that}\quad 2{{{{\rm d}^2y}\over{{{\rm d}x}^2}}}+a{{\frac{{\rm d}y}{{\rm d}x}}}-a^2y=0.

Introductory problems 3

If y=exsin(x)show thatd2ydx2+2dydx+2y=0\displaystyle \quad y=e^{-x}\sin(x) \quad\rm{show~that}\quad {{{{\rm d}^2y}\over{{{\rm d}x}^2}}} + 2{{\frac{{\rm d}y}{{\rm d}x}}} + 2y = 0.

Main problems

Main problems 1

The power, WW, that a certain machine develops is given by the formula

W=EIRI2\displaystyle W=EI-RI^2

where II is the current and EE and RR are positive constants.

Find the maximum value of WW as II varies.

Main problems 2

Environmental health officers monitoring an outbreak of food poisoning after a wedding banquet were able to model the time course of the recovery of the guests using the equation:

r=100t1+t\displaystyle r = {100t\over 1+t}

where tt represents the number of days since infection and rr is the percentage of guests who no longer display symptoms. Determine an expression for the rate of recovery.

Main problems 3

An experiment called 'the reptilian drag race' looks at how agamid lizards accelerate from a standing start.

The distance xx travelled in time tt on a horizontal surface has been modelled as

x=vmax(t+ektk1k),\displaystyle x = v_{\rm max} \left(t + {e^{-kt}\over k} - {1\over k}\right),

where vmaxv_{\rm max} is the maximum velocity, and kk is a rate constant.

  1. Find expressions for the velocity vv and acceleration aa as functions of time.

  2. For vmax=3v_{\rm max} = 3\,m\,s1^{-1} and k=10k=10\,s1^{-1}, sketch xx, vv and a/10a/10 on the same axes for 0t10\leq t\leq 1\,s.

Main problems 4

The distance xx that a particular organism travels over time from its starting location is modelled by the equation

x(t)=t2ek(1t),\displaystyle x(t) = t^2 e^{k(1-t)},

where kk is a positive constant and 0t10\leq t\leq 1\,s.

  1. Sketch xx over time for k=12k={1\over 2} and k=3k=3.

  2. Calculate an expression for the organism's velocity as a function of time.

  3. What is the largest value of kk such that the organism never starts moving back towards where it started?

Main problems 5

The function

S=Smax(1etτ)\displaystyle S = S_{max}(1- e^{-t\over\tau})

is used to describe sediment thickness accumulating in an extensional basin through time. What is the sedimentation rate?

Extension problems

Extension problems 1

Let z=23x334x2y+25y3\displaystyle \quad z = {2\over 3}x^3 - {3\over 4}x^2y + {2\over 5}y^3.

  1. Find zx\displaystyle z_x and zy\displaystyle z_y

  2. Find zxx\displaystyle z_{xx} and zyy\displaystyle z_{yy}

  3. Show that zxy=zyx\displaystyle z_{xy} = z_{yx}

Extension problems 2

Show that fxy=f_yxf*{xy}=f\_{yx} for the following functions:

  1. f(x,y)=x2xy+y3\displaystyle f(x,y) = x^2 - xy + y^3

  2. f(x,y)=eyln(2xy)\displaystyle f(x,y) = e^y\,\ln(2x-y)

  3. f(x,y)=2xye2xy\displaystyle f(x,y) = 2\,x\,y\,e^{2xy}

  4. f(x,y)=xsin(y)\displaystyle f(x,y) = x\,\sin(y)

Extension problems 3

The body mass index, BB, is used as a parameter to classify people as underweight, normal, overweight and obese. It is defined as their weight in kg, ww, divided by the square of their height in meters, hh.

  1. Sketch a graph of BB against ww for a person who is 1.7m tall.

  2. Find the rate of change of BB with weight of this person.

  3. Sketch a graph of BB against hh for a child whose weight is constant at 35 kg.

  4. Find the rate of change of BB with height hh of this child.

  5. Show that (2Bhw)=(2Bwh)\displaystyle \left({\partial^2 B\over \partial h \partial w}\right)=\left({\partial^2 B\over \partial w \partial h}\right).

Extension problems 4

A light wave or a sound wave propagated through time and space can be represented in a simplified form by:

y=Asin(2π(xλ+ωt))y=A\sin\left(2\pi\left({x\over\lambda}+\omega t\right)\right)

where AA is the amplitude, λ\lambda is the wavelength and ω\omega is the frequency of the wave. xx and tt are position and time respectively.

An understanding of this function is essential for many problems such as sound, light microscopy, phase microscopy and X-ray diffraction.

  1. Draw a graph of yy as a function of xx assuming t=0t=0.

  2. Draw a graph of yy as a function of tt assuming x=0x=0.

  3. At what values of xx and tt does the function repeat itself?

  4. Find the rate at which yy changes at an arbitrary fixed position.

  5. Show that yxt=ytx\displaystyle y_{xt} = y_{tx}.