Skip to main content

Scientific Computing

Essential Maths

Indices, logs... []

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

Graphs


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


Basics

Terminology:

  • YY or yy is the dependent variable, sometimes called the ordinate marked on the vertical axis

  • XX or xx is the independent variable, sometimes called the abscissa marked on the horizontal axis

  • The dependent variable is said to be graphed against the independent variable

Essential Features:

  • Title

  • Axis labels (and units if appropriate)

Example graph with a title and axis labels

Equation of a straight line

Defined by a gradient, mm, and a yy-axis intercept, cc:

y=mx+cy = m x + c

Interpretation:

  • The intercept of this line on the yy axis is given by y=cy=c, since at x=0x=0, y=cy = c

  • The gradient of this line (also called its "slope") is given by m=y2y1x2x1m = {y_2-y_1\over x_2 - x_1} ("change in yy divided by change in xx")

  • The intercept of this line on the xx axis is given by x=cmx = -{c \over m}, since at y=0y=0 we must have mx=cmx=-c

Graphs of Polynomials

An expression involving higher powers of xx is called a polynomial in xx.

Example

y=x55x3+4xy=x^5-5x^3+4x

Example graph of a polynomial

In general

y=anxn+an1xn1+an2xn2++a1x1+a0x0y = a_n x^n + a_{n-1} x^{n-1} + a_{n-2} x^{n-2}+\ldots+a_1 x^1 + a_0x^0

The graph of a polynomial of degree nn has at most n1n-1 bends in it.

Transforming from non-linear to linear

If we wish to test visually whether some data fit a particular relationship, we can transform the data to plot something which should be linear if the relationship holds.

e.g. Test for parabolic shape for data in (x,y)(x,y): i.e. y=x2y = x^2

  • We can plot YY against XX where we let Y=yY=y and X=x2X=x^2.

First plot the original data

There's a definite curve, and we may suspect the trend is quadratic

Graph of data with nonlinear trend

Now plot the data nonlinearly

If the parabolic relationship holds, plotting Y=yY=y against X=x2X=x^2 should result in a straight line.

Graph of data transformed to a linear trend

Calculate the gradient and the intercept

We next add a trendline through these points which we can use to determine the gradient and intercept.

Graph of linear trend with trendline

  • We find (X,Y)(X,Y) lie along a straight line with slope 5 and Y-intercept 87.

  • This means that Y=5X+87Y=5X+87

  • So, yy and xx can be modelled by the polynomial equation y=5x2+87y=5x^2+87.

Example from biosciences

The rate at which a given enzyme can catalyse a reaction can be dependent upon the substrate concentration: 1V=mS+c{1\over V} = {m\over S} + c

where VV is the rate of the reaction, SS is the substrate concentration and mm and cc are constants.

  • We can derive a straight line graph from the above formula by plotting Y=1/VY=1/V against X=1/SX=1/S

  • It will have gradient mm and ordinate intercept cc

First, plot the original data which is observations of VV given varying SS:

Graph of original data

Now plot the data nonlinearly

If the hypothesised relationship holds, plotting Y=1/VY=1/V against X=1/SX=1/S should result in a straight line.

Graph of linear trend

Calculate the gradient and the intercept

We next add a trendline through these points which we can use to determine the gradient and intercept.

Graph of linear trend with trendline

  • We find (X,Y)(X,Y) lie along a straight line with slope 3 and Y-intercept 5.

  • This means that Y=3X+5Y=3X+5

  • So, VV and SS can be modelled by the equation 1/V=3/S+51/V=3/S+5.

Introductory problems

Introductory problems 1

Sketch the following graphs. First, use pen & paper, then use Python to check your answers. The notation after each equation indicates the range of values that xx can take.

  1. y=3x+5x[0,10]\displaystyle y = 3x+5 \qquad\qquad x\in[0,10]

  2. y=x224x[4,4]\displaystyle y = \frac{x^2}{2} - 4 \qquad\qquad x\in[-4,4]

  3. y=xx[0,25]\displaystyle y = \sqrt{x} \qquad\qquad x\in[0,25]

  4. y=sin(t)t[0,2π]\displaystyle y = \sin(t) \qquad\qquad t\in[0,2\pi]

  5. y=sin(2t)t[0,2π]\displaystyle y = \sin(2t) \qquad\qquad t\in[0,2\pi]

  6. y=1xx[0.1,5]\displaystyle y = \frac{1}{x} \qquad\qquad x\in[0.1,5]

  7. y=1x2x[0.1,5]\displaystyle y = \frac{-1}{x^2} \qquad\qquad x\in[0.1,5]

# hint import numpy as np from matplotlib import pyplot as plt x = np.linspace(0, 10, 100) y = 3 * x + 5 plt.plot(x, y)

Introductory problems 2

For which values of xx are the following functions positive? Negative? Zero?

  1. x29\displaystyle x^2 - 9

  2. sin(x)\displaystyle\sin(x)

  3. sin(3x)\displaystyle\sin(3x)

  4. 2x1x2\displaystyle\frac{2}{x} - \frac{1}{x^2}

Main problems

Text relevant to these problems: Croft and Davison, 5th^{\rm th} Edition, Chapters 17 & 18.

Main problems 1

The Lennard-Jones potential energy between two non-polar atoms may be given by the equation: V(R)=AR12BR6V(R)={A\over R^{12}} - {B \over R^6} where AA and BB are positive constants, V(R)V(R) is the potential energy, measured in Joules, and RR is the internuclear distance measured in \AA.

  1. For which values of RR is V(R)V(R) positive? Negative? Zero?

  2. Plot a graph showing the potential energy between the two atoms as a function of RR given that A=0.06A=0.06 and B=0.03B = 0.03.

  3. What is the potential energy between the two atoms at infinite separation?

  4. What would happen to the two atoms if they were brought very close together?

  5. What is the physical interpretation of the sign of V(R)V(R), and of its slope?

  6. What are the dimensions ([Length], [Mass], [Time]) and units of the constants AA and BB?

  7. Use Python to plot the graph of VV versus RR for A=0.06A=0.06 and B=0.03B = 0.03. Remember to add relevant axis labels. Plot on the same graph the line of V=0V = 0, so you can verify your answers in 1. and b).

Main problems 2

How should these equations be rearranged to allow the plotting of a suitable linear graph, assuming that the constant parameters aa and bb are unknown, and we wish to use the graph to find them? Write down expressions for the gradient, XX-intercept and YY-intercept of each rearranged equation:

  1. y=ax\displaystyle y = \frac{a}{x}

  2. y=bax\displaystyle y = b - a \sqrt{x}

  3. y=b1+ax\displaystyle y = \frac{b}{1+ax}

Main problems 3

The osmotic pressure of a solution of a protein is related to the concentration of that protein by the equation: Z=R  T  bZ = R\;T\;b where ZZ is the osmotic pressure in kPa, TT is the temperature in Kelvin, RR is the gas constant (R=8.314  kPadm3mol1K1R=8.314\;{\rm kPa}\cdot{\rm dm}^3\cdot{\rm mol}^{-1}\cdot{\rm K}^{-1}) and bb is the molarity of the protein (mol. solute per dm3^3 solution). Plot a suitable graph to determine, as accurately as possible, the molecular mass (take care with units!) of the protein given the following data taken at room temperature (usually taken as 21^{\circ}C):

Protein Concentration (in g dm3)^{-3})7.318.427.642.157.4
Osmotic Pressure (in kPa)0.2110.5330.8041.2361.701

Hint: compare the function with the equation of a straight line, y=mx+cy=mx+c, and think about the relationship between concentration, molar concentration and molecular weight).

Use Python to plot the graph and confirm your pen & paper solution.

Extension problems

Extension problems 1

The rate at which a given enzyme catalyses a reaction is dependent upon the substrate concentration: V=Sm+cSV = \frac{S}{m+cS} where VV is the rate of the reaction, SS is the substrate concentration and mm and cc are unknown constants. How can we transform VV and SS to derive a straight line graph relating them? What will be the gradient and the ordinate intercepts?