1Functions and their graphs
What a function is, how a graph encodes one, and the families of functions that appear throughout physical science: linear, power, exponential, logarithmic, periodic and Gaussian. Includes logarithmic axes and how to read a law of nature from data.
Functions
Science is largely the study of how one quantity depends on another. The pressure of a gas depends on its temperature, the energy of two atoms depends on the distance between them, the number of undecayed nuclei in a sample depends on how long you have waited. The mathematical object that captures “depends on” is the function.
A function is a rule that takes an input and produces exactly one output. If the rule is called and the input is , the output is written , read “f of x”. The insistence on exactly one output is the whole point: if you know the input, the output is determined. The rule “square the number” is a function, because every number has one square. The rule “give me a number whose square is ” is not, because 4 has two square roots, and , and the rule does not say which to choose.
It helps to picture a function as a machine. A number goes in on one side, the machine does something to it, and a number comes out of the other side. The machine does not remember previous inputs and does not behave differently on different days. The figure below lets you feed numbers into such a machine. Each time a number comes out, the pair (input, output) is recorded as a point on a graph, and if you feed many inputs the points join up into a curve. That curve is the graph of the function, and it is nothing more than the record of every input–output pair.
A function as a machine, and its graph as a record of what it did
Loading the interactive figure…
Some vocabulary makes it possible to talk about functions precisely. The set of inputs a function accepts is its domain. The square root of a negative number is not a real number, so the domain of is ; the function accepts every number except zero. The set of outputs a function can produce is its range: never produces a negative number, so its range is . The input is often called the independent variable and the output the dependent variable, because the output depends on the input and not the other way round.
Functions can be described in four equivalent ways, and moving between them is a skill worth practising. A formula such as gives the rule symbolically. A table lists selected input–output pairs, which is how experimental data usually arrive. A graph shows every pair at once as a curve. And a description in words says what the rule does: “convert a temperature from degrees Celsius to degrees Fahrenheit”. Each form is good for something different. The formula is good for calculation, the table for recording measurements, the graph for seeing behaviour at a glance, and the words for remembering what the function means.
Functions in science carry units. In the input is in °C and the output in °F, so the number 1.8 has units of °F per °C and the 32 is in °F. Keeping track of units is the single most effective way to catch mistakes in a formula: if two terms that are added together have different units, the formula is wrong.
Reading a graph
A graph is drawn on two perpendicular axes. The horizontal axis carries the input, conventionally , and the vertical axis the output, . The point where the axes cross is the origin, . Every point on the curve has coordinates .
Several features of a function can be read directly from its graph. Where the curve crosses the vertical axis, the input is zero, so that height is , the intercept. Where the curve crosses the horizontal axis the output is zero; these inputs are the roots or zeros of the function and solving the equation means finding them. Where the curve rises from left to right the function is increasing, and where it falls it is decreasing. The highest and lowest points of a hump or a dip are maxima and minima, and they matter enormously in science: a stable arrangement of atoms is a minimum of the energy, and the barrier a chemical reaction must cross is a maximum along the reaction path. A curve may also approach a straight line without ever reaching it, as approaches the horizontal axis when becomes large; such a line is an asymptote.
Graphs can be transformed in predictable ways, and recognising these transformations makes new functions look familiar. Replacing by moves the whole graph up by . Replacing by moves it to the right by , which surprises many people at first: the output that used to occur at now occurs at . Multiplying the output, , stretches the graph vertically by the factor , and a negative also flips it upside down. Multiplying the input, , squeezes the graph horizontally by the factor . A Gaussian peak centred at with width , for example, is just the standard bell curve shifted by and stretched by .
Linear functions
The simplest non-trivial function is the straight line,
The slope is the defining property of a straight line: between any two points and on it, the ratio is the same number . “Rise over run” is the usual mnemonic. A positive slope means grows with , a negative slope means it shrinks, and a zero slope gives a horizontal line. The slope has units, output units per input unit, and it often has a physical meaning of its own: in a graph of position against time the slope is a velocity, in a graph of charge against voltage it is a capacitance.
When the line passes through the origin and is proportional to , written : doubling doubles . Many laws of physics take this form near equilibrium. Hooke’s law says the restoring force of a spring is proportional to its extension, . Ohm’s law says the current through a resistor is proportional to the voltage across it. Linear behaviour is so common because almost any smooth function looks like a straight line if you only look at a small enough piece of it, an idea that becomes the derivative in the next chapter.
Linear functions are also the workhorse of data analysis. Plotting data so that a law appears as a straight line, and then measuring the slope and intercept, is one of the oldest and most reliable ways of extracting physical constants from experiment. The next sections show how to do this even when the underlying law is not linear at all.
Powers and polynomials
A power function has the form . For whole-number powers this is familiar: is a parabola, symmetric about the vertical axis, and rises steeply on the right and falls steeply on the left. Negative powers describe quantities that fall off with distance. The electrostatic energy of two charges varies as , the gravitational force as , and the repulsion between two atoms when their electron clouds overlap rises roughly as in the Lennard-Jones model. Fractional powers also appear: describes, for instance, how far a diffusing molecule typically travels in time .
Power functions have a scaling property that makes them special. If and you multiply by a factor , then is multiplied by , whatever the starting value of . Doubling the distance between two charges halves their energy, everywhere. This is why power laws describe phenomena that have no built-in length or time scale.
A sum of whole-number powers, , is a polynomial of degree . Polynomials are easy to evaluate, differentiate and integrate, and a polynomial of degree has at most real roots and at most turning points. They are the raw material of approximation: Taylor series build complicated functions from polynomials, and the harmonic approximation of a chemical bond replaces its true energy curve by a parabola near the minimum.
Families of functions and what their parameters do
Loading the interactive figure…
Exponential functions
Suppose a quantity changes at a rate proportional to how much of it there is. A population of bacteria with plenty of food grows at a rate proportional to the number of bacteria; a sample of radioactive nuclei decays at a rate proportional to the number of nuclei left; the light passing through an absorbing liquid loses intensity at a rate proportional to the intensity. All of these are described by the exponential function:
The defining feature of an exponential is that adding a fixed amount to the input multiplies the output by a fixed factor. For a straight line, each step of one unit in adds to ; for an exponential, each step multiplies by . As a result, an exponential always has a fixed doubling time (for growth) or half-life (for decay), equal to . Carbon-14 has a half-life of about 5730 years: after 5730 years half of the original nuclei remain, after 11 460 years a quarter, after 17 190 years an eighth, and so on, regardless of how much you started with. The golden dots in the figure above mark these successive halvings when you select the exponential family.
Why the strange base ? Any base could be used, since , and are all exponentials and each can be converted into the others. The number is chosen because it makes the mathematics of change simplest: the slope of at any point equals its height. This is proved in the chapter on derivatives, and it is why nature’s exponentials, which arise from rates proportional to amounts, appear with base .
Exponentials are the most important functions in statistical mechanics. The probability that a molecule has energy at temperature is proportional to the Boltzmann factor , and the rate of a chemical reaction with activation energy follows the Arrhenius law . Both are decaying exponentials of energy: each additional of energy makes a state times less likely. These ideas are developed in the Boltzmann distribution.
Logarithms
The logarithm undoes the exponential. If , then , the natural logarithm of . More generally, is the power to which the base must be raised to give , so because . Since exponentials only produce positive numbers, logarithms are only defined for positive inputs.
Three rules follow directly from the rules for powers, and they are used constantly:
Before electronic calculators, these rules made logarithms the standard tool for multiplying large numbers: look up two logarithms, add them, and look up the number whose logarithm is the sum. Today their importance is different. Logarithms compress enormous ranges into manageable ones. The acidity of a solution spans more than fourteen orders of magnitude in hydrogen-ion concentration, and the pH scale, , turns this into numbers between about 0 and 14. Sound intensity in decibels and earthquake magnitudes are logarithmic for the same reason. In statistical mechanics, the entropy is the logarithm of a count of microstates that is itself astronomically large, and the free energy is the logarithm of a sum of Boltzmann factors.
A logarithm grows without limit, but extraordinarily slowly: reaches 10 only when exceeds 22 000, and 100 only when exceeds . Each multiplication of by adds exactly one to , which is the logarithmic version of the exponential’s constant doubling time.
Logarithmic axes and laws from data
The rules of logarithms give a powerful way of discovering laws in data. Take the logarithm of both sides of a power law, :
This is a straight line, not in against but in against , with slope . Plotting data on log–log axes, where both axes are spaced logarithmically, turns every power law into a straight line, and the slope of the line reveals the power. Similarly, taking the logarithm of an exponential, , gives , which is a straight line on semi-logarithmic axes with only the vertical axis logarithmic.
The figure below contains real data on the orbits of the eight planets: the size of each orbit (its semi-major axis, in units of the Earth’s) and the time it takes to go round the Sun (in years). On ordinary axes the points form a curve. Switch to log–log axes and they fall on a straight line with slope 1.5. This is Kepler’s third law, , found by Kepler in 1619 by exactly this kind of search for a pattern in numbers, and explained seventy years later by Newton’s law of gravitation. The second data set is a simulated radioactive sample, whose counts fall on a straight line only on semi-log axes, as an exponential should. The third is the repulsive part of the Lennard-Jones potential, a pure power law with slope .
Straight lines hiding in curved data
Loading the interactive figure…
This technique is routine in research. The decay of a correlation function is plotted on semi-log axes to extract a relaxation time; the mean-squared displacement of a diffusing particle is plotted on log–log axes to check that it grows linearly with time; the error of a numerical method is plotted against its step size on log–log axes to measure its order of accuracy, as you will see in the chapter on derivatives.
Periodic functions
Many phenomena repeat: vibrations of atoms, alternating currents, the seasons, waves of light. The basic repeating functions are the sine and cosine. Imagine a point moving anticlockwise at a steady rate around a circle of radius 1 centred on the origin. If the angle it has turned through, measured from the positive horizontal axis, is , then its height is and its horizontal position is . As the point goes round and round, its height rises and falls forever, repeating every full turn of radians (360°).
A general oscillation has an amplitude, a frequency and a phase:
Angles in science are measured in radians, defined so that an angle of radians cuts off an arc of length on a circle of radius 1. A full turn is radians. Radians are not an arbitrary convention: as with the base for exponentials, they are the unit for which the derivative of is exactly , with no awkward conversion factor.
Sinusoids describe any system that is pulled back towards equilibrium with a force proportional to its displacement, such as a mass on a spring or an atom vibrating in a molecule, as the chapter on motion shows. A remarkable theorem of Fourier says that essentially any periodic signal, however jagged, can be written as a sum of sines and cosines of different frequencies, which is why vibrational spectra, X-ray diffraction and much of signal processing are analysed in terms of sinusoids.
The Gaussian
The last family in this chapter is the bell-shaped Gaussian,
Choose the bell curve in the families figure: the shaded band covers and the teal bar marks the full width at half maximum. The Gaussian is an exponential of a negative square, so it falls to zero much faster than an ordinary exponential. It is the shape of the distribution of velocities of molecules in a gas, of the spread of random measurement errors, of a spectral line broadened by thermal motion, and of the smearing functions used to turn atomic positions into smooth densities in machine-learning descriptors. The chapter on probability explains why it is so common: the sum of many small independent random effects always tends to a Gaussian.
Combining functions
New functions are built from old ones in a few standard ways. They can be added, subtracted, multiplied and divided. They can also be composed: feeding the output of one function into another, written . The Gaussian is a composition: first square the input, then multiply by , then exponentiate. The Lennard-Jones energy of two atoms, , is a difference of two power laws that together produce a potential well with a steep repulsive wall and a gentle attractive tail. Recognising how a complicated function is assembled from simple pieces is usually the key to understanding its graph.
A function that undoes another is its inverse, written . The logarithm is the inverse of the exponential, and the square root (on non-negative numbers) is the inverse of squaring. The graph of an inverse is the mirror image of the original graph in the diagonal line , since inverting a function simply swaps the roles of input and output. A function only has an inverse if it never gives the same output for two different inputs.
Finally, many quantities depend on more than one input. The potential energy of a molecule depends on the positions of all its atoms, and the loss of a neural network on millions of weights. A function of two variables, , can be drawn as a surface or as a contour map, and most of the mathematics of this chapter carries over. The chapter on gradients develops these functions of many variables.
Check yourself
- Which of these rules is not a function of x?For x = 4 there are two such numbers, 2 and −2, so the rule does not give exactly one output.
- A sample has a half-life of 3 hours. What fraction remains after 12 hours?12 hours is four half-lives, so the sample is halved four times: (1/2)⁴ = 1/16.
- Data plotted on log–log axes fall on a straight line of slope −2. What law do they follow?log y = n log x + const is a power law y ∝ xⁿ, here with n = −2, like the inverse-square law of gravity.
- The graph of f(x − 3) compared with f(x) is…The output that f gave at x = 0 is now given at x = 3, so every feature moves 3 units to the right.
- What is ln(e⁵ × e²)?ln(ab) = ln a + ln b = 5 + 2 = 7.
References and further reading
- J. Stewart, Calculus: Early Transcendentals, 8th ed., Cengage Learning (2015), chapter 1 (functions and models) and chapter 6 (inverse functions, exponentials and logarithms).
- K. F. Riley, M. P. Hobson and S. J. Bence, Mathematical Methods for Physics and Engineering, 3rd ed., Cambridge University Press (2006), chapter 1.
- M. L. Boas, Mathematical Methods in the Physical Sciences, 3rd ed., Wiley (2006), chapters 1–2.
- J. Kepler, Harmonices Mundi, Linz (1619), book V, where the third law is stated.
- S. Strogatz, Infinite Powers: How Calculus Reveals the Secrets of the Universe, Houghton Mifflin Harcourt (2019). A non-technical history of the ideas in this subject.