Posts in Category: Uncategorized

Test Post

Propagation of Error with Single and Multiple Independent Variables


Often it is necessary to calculate the uncertainty of derived quantities. This procedure and convention is called propagation of error. Calculating the propagation of error formula requires knowing how to take derivatives/ We give the propagation of error formulas for a single variable and multiple independent variable functions. We list some common error propagation formulas that work in most cases. Step by step error propagation can often be used as a shortcut to calculate the uncertainty.
If we know the error propagation formula we can find the terms that are causing the most uncertainty and try to reduce these dominant errors. It is useful to write a short MATLAB script to calculate error propagation, especially when the formula is complex or a lot of significant digits are involved.

How error propagates

As a math problem, I ask you to add 5.2 and 10.11. The result is straightforward 15.31. The numbers have different numbers of digits and precision. 5.2 is precise to the tenths while 10.11 is precise to the hundredths. This is not a problem in mathematics, but the situation is more subtle in error analysis. To see what is going on you need to look at the uncertainties.

Now, if I ask you to add 5.2 \pm 1.2 and 10.11 \pm 0.76 then what do you do? The first thing you want to ask yourself is if these numbers are properly reported measurements. After a quick check, we see there are two digits of uncertainty that match the precision of the measurement. In error analysis, you still add the numbers to find the sum, but to find the combined error we need a propagation of error formula. In this situation, the rule is

    \[{\sigma}_{A + B} = \sqrt{ {\sigma}_A^2 + {\sigma}_B^2 } = 1.4204\ldots\]

This chapter is all about finding the rules like this. We can now calculate the uncertainty {\sigma}_{A+B} = 1.4204 \to 1.4 and round to two significant digits. Then we match the precision of the calculated quantity to the uncertainty. Our final result is that

    \[(5.2 \pm 1.2) + (10.11 \pm 0.76) = 15.31 \pm 1.4204 \to 15.3 \pm 1.4\]

Notice that if you always start with uncertainties that have two significant digits, you get out a result that has two significant digits of uncertainty. You don’t have to worry that the first number 5.2 has only two significant digits, but the final result 15.3 has three significant digits. This comes about naturally by the golden rule of two significant digits of uncertainty.

There are error propagation rules for single variable functions and multiple variable functions. The single variable situation is not too complicated. You just need to understand differential calculus. For the situation with multiple variables functions, you have to worry if the variables are correlated or independent. In most cases, we don’t have to worry about correlations and the formulas are straightforward.

Rules of differential calculus refresher

We now do a little review of differentiation because we need derivatives for error propagation. Ordinary derivatives are needed for a single variable function, and partial derivatives are needed for multiple variable functions. The derivative is defined in calculus as

    \begin{align*} f'(x) = \cfrac{df}{dx} = \lim_{\Delta x \to 0} \cfrac{ f( x + \Delta x) - f(x)}{\Delta x} \end{align*}

The following list contains the basic formulas to master differential calculus.

    \[c' = 0 \qquad x' = 1 \qquad (x^n)' = nx^{n-1} \qquad |x|' = \cfrac{|x|}{x}\]

    \[(cu)' = cu' \qquad (c_1u +c_2 v)' = c_1u' + c_2v'\]

    \[(uv)' = u'v + uv' \qquad (1/u)' = -u'/u^2 \qquad (u/v)' = \cfrac{ u'v - uv'}{v^2}\]

    \[f(u(x))' = \cfrac{df}{du}\cfrac{du}{dx} = f'(u)u'(x)\]

    \[(e^x)' = e^x \qquad (a^x)' = a^x \ln a \qquad (\ln x)' = \cfrac{1}{x} \qquad (\log_a x)' = \cfrac{1}{x \ln a}\]

    \[\cfrac{d}{dx} \sin x = +\cos x \quad \cfrac{d}{dx} \tan x = +\sec^2 x \quad \cfrac{d}{dx} \sec x = +\sec x \tan x\]

    \[\cfrac{d}{dx} \cos x = -\sin x \quad \cfrac{d}{dx} \cot x = -\csc^2 x \quad \cfrac{d}{dx} \csc x = -\csc x \cot x\]

    \[\cfrac{d}{dx} \sinh x = +\cosh x \quad \cfrac{d}{dx} \tanh x = +\sech\!^2 x \quad \cfrac{d}{dx} \sech x = - \sech x \,\tanh x\]

    \[\cfrac{d}{dx} \cosh x =+\sinh x \quad \cfrac{d}{dx} \coth x = -\csch\!^2 x \quad \cfrac{d}{dx} \csch x = - \csch x \,\coth x\]

    \[\cfrac{d}{dx} \arcsin x = +\cfrac{1}{\sqrt{ 1 - x^2}} \quad \cfrac{d}{dx} \arctan x = +\cfrac{1}{1 + x^2} \quad \cfrac{d}{dx} \arcsec x = +\cfrac{1}{|x| \sqrt{ x^2-1}}\]

    \[\cfrac{d}{dx} \arccos x = -\cfrac{1}{\sqrt{ 1 - x^2}} \quad \cfrac{d}{dx} \arccot x = -\cfrac{1}{1 + x^2} \quad \cfrac{d}{dx} \arccsc x = -\cfrac{1}{|x| \sqrt{ x^2-1}}\]

    \[\cfrac{d}{dx} \arcsinh x = +\cfrac{1}{\sqrt{ x^2+1}} \quad \cfrac{d}{dx} \arctanh x = +\cfrac{1}{1-x^2} \quad \cfrac{d}{dx} \arcsech x = -\cfrac{1}{x \sqrt{ 1-x^2}}\]

    \[\cfrac{d}{dx} \arccosh x = +\cfrac{1}{\sqrt{ x^2-1}} \quad \cfrac{d}{dx} \arccoth x = +\cfrac{1}{1-x^2} \quad \cfrac{d}{dx} \arccsch x = -\cfrac{1}{|x| \sqrt{1+x^2}}\]

The partial derivative is like the normal derivative except you hold the other variables constant when you take it. Here is the definition

    \[\cfrac{ \partial f(x,y)}{ \partial x} = \lim_{\Delta x \to 0} \cfrac{f(x + \Delta x, y) - f(x,y)}{\Delta x}\]

    \[\cfrac{ \partial f(x,y)}{ \partial y} = \lim_{\Delta y \to 0} \cfrac{f(x, y+ \Delta y) - f(x,y)}{\Delta y}\]

For example, if we wanted to find all the partial derivatives of f(x,y,z) = xy^2z^3 we would use the power rule (x^n)' = nx^{n-1}.
There are three possible partial derivatives

    \[\cfrac{ \partial f}{ \partial x} = y^2 z^3 \quad \cfrac{ \partial f}{ \partial y} = 2xyz^3 \qquad \cfrac{ \partial f}{\partial z} = 3xy^2 z^2\]

Error propagation with one variable

If we have measured Q \pm \sigma_Q then the uncertainty in Q(A) is given by

    \[{\sigma}_Q = \left | Q'({A}) \right | {\sigma}_A\]

I assume you are familiar with differentiation. One can use a program like Mathematica or your graphing CAS calculator to find derivatives.

Example. The volume of a cube from error propagation.
Suppose a machinist has constructed a precise cube on a milling machine, and you want to find its volume. You repeatedly measure one of the sides to be

    \[s = 1.053 \pm 0.010 \, \mathrm{cm}\]

What is the volume and its uncertainty assuming the length, width, and height are identical?

We calculate the volume as V = s^3 and wait to round until we know the uncertainty.

    \[V = (1.053\, \mathrm{cm})^3 = 1.16757587\ldots \, \mathrm{cm}^3\]

To find the uncertainty we use the error propagation formula

    \begin{align*} {\sigma}_V &= |V'(s)| {\sigma}_s = 3s^2 {\sigma}_s \\ {\sigma}_V&= 3(1.053 \, \mathrm{cm})^2(0.010\, \mathrm{cm}) = 0.033502\, \mathrm{cm}^3 \end{align*}

After rounding we get V = 1.168(34)\, \mathrm{cm}^3.

Error propagation with multiple independent variables

Often we want to calculate some quantity that requires a series of individual measurements that must be combined. For example, if we wanted to calculate A/B we would first measure A then measure B and then we could calculate A/B. If we are doing error analysis, then to find the error in A/B we will need to apply a formula of error propagation. There is a significant simplification if the two quantities are thought to be independent like the charge and mass of an electron. The error propagation formula for multiple independent variables labeled a_1, a_2, \ldots, a_M is given by

    \[{\sigma}_f^2 = \sum_{j = 1}^M \left( \cfrac{ \partial f}{ \partial a_j}\right)^2 {\sigma}_{a_j}^2\]

We will often use the notation that a_1 = A \quad a_2 = B for simplification when we do calculations. Propagation of error for two independent variables is given by

    \[{\sigma}_f^2 = \left( \cfrac{ \partial f}{\partial A}\right)^2{\sigma}_A^2 + \left( \cfrac{ \partial f}{\partial B}\right)^2{\sigma}_B^2\]

Example. Show that {\sigma}_{A \pm B} = \sqrt{{\sigma}_A^2 + {\sigma}_B^2}.
Evaluating the partial derivatives

    \[\cfrac{ \partial (A \pm B)}{\partial A} = 1 \qquad \cfrac{\partial(A \pm B)}{\partial B} =\pm 1\]

Applying the error propagation formula we have

    \[{\sigma}_{A \pm B} = \sqrt{ (1)^2 {\sigma}_A^2 + (\pm 1)^2 {\sigma}_B^2 } = \sqrt{ {\sigma}_A^2 + {\sigma}_B^2 }\]

Example. Find the perimeter of a rectangle of l = 1.25(22) and w = 4.44(33).
The perimeter is equal to P = 2( l + w )
We can find the perimeter by plugging in the values
P = 2(1.25 + 4.44) = 11.3800\ldots
We can find the uncertainty by applying the propagation of error formula

    \[{\sigma}_P^2 = \left( \cfrac{\partial P}{\partial l}\right)^2 {\sigma}_l^2 + \left( \cfrac{\partial P}{\partial w}\right)^2 {\sigma}_w^2\]

    \[\sigma_P = \sqrt{ 4 \sigma_l^2 + 4 \sigma_w^2} = \sqrt{ 4\times 0.22^2 + 4\times 0.33^2} = 0.7932\ldots\]

    \[\sigma_P \to 0.79\]

Our final answer is P = 11.38 \pm 0.79

Example. If Q = AB, then show that

    \[{\sigma}_{AB} = |AB| \sqrt{\cfrac{{\sigma}_A^2}{A^2} + \cfrac{{\sigma}_B^2}{B^2}}\]

Evaluating the partial derivatives

    \[\cfrac{ \partial (AB)}{\partial A} = B \qquad \cfrac{\partial(AB)}{\partial B} = A\]

Applying the error propagation formula we have

    \[{\sigma}_{AB} = \sqrt{ B^2 {\sigma}_A^2 + A^2 {\sigma}_B^2 }\]

Divide both sides by |AB|.

    \[\cfrac{{\sigma}_{AB}}{|AB|} = \cfrac{1}{|AB|}\sqrt{ B^2{\sigma}_A^2 + A^2 {\sigma}_B^2 } =\sqrt{ \cfrac{{\sigma}_A^2}{A^2} + \cfrac{{\sigma}_B^2 }{B^2}}\]

Example. If Q = A/B, then show that

    \[{\sigma}_{AB} = |A/B| \sqrt{\cfrac{{\sigma}_A^2}{A^2} + \cfrac{{\sigma}_B^2}{B^2}}\]

Evaluating the partial derivatives

    \[\cfrac{ \partial (A/B)}{\partial A} = 1/B \qquad \cfrac{\partial(A/B)}{\partial B} =-A/B^2\]

Applying the error propagation formula we have

    \[{\sigma}_{A/B} = \sqrt{ (1/B)^2 {\sigma}_A^2 + (A^2/B^4) {\sigma}_B^2 }\]

Divide both sides by |A/B|.

    \[\cfrac{{\sigma}_{A/B}}{|A/B|} = \cfrac{1}{|A/B|}\sqrt{ (1/B)^2{\sigma}_A^2 + (A^2/B^4) {\sigma}_B^2 } =\sqrt{ \cfrac{{\sigma}_A^2}{A^2} + \cfrac{{\sigma}_B^2 }{B^2}}\]

Common error formulas

Q= A + B then

    \[{\sigma}_Q = \sqrt{ {\sigma}_A^2 + {\sigma}_B^2}\]

Q = A - B then

    \[{\sigma}_Q = \sqrt{ {\sigma}_A^2 + {\sigma}_B^2}\]

Q = AB then

    \[\cfrac{{\sigma}_Q}{|Q|} = \sqrt{ \cfrac{{\sigma}_A^2}{A^2} + \cfrac{{\sigma}_B^2}{B^2}}\]

Q = A/B then

    \[\cfrac{{\sigma}_Q}{|Q|} = \sqrt{ \cfrac{{\sigma}_A^2}{A^2} + \cfrac{{\sigma}_B^2}{B^2}}\]

Q = AB/C\ldots then

    \[\cfrac{{\sigma}_Q}{|Q|} =\sqrt{ \cfrac{{\sigma}_A^2}{A^2} + \cfrac{{\sigma}_B^2}{B^2} + \cfrac{{\sigma}_C^2}{C^2} + \ldots }\]

Q = A^aB^B/C^c\ldots then

    \[\cfrac{{\sigma}_Q}{|Q|} = \sqrt{ \cfrac{a^2{\sigma}_A^2}{A^2} + \cfrac{b^2{\sigma}_B^2}{B^2} +\cfrac{c^2{\sigma}_C^2}{C^2} + \ldots }\]

Many formulas in physics are of the last form. For example, F = GmM/r^2 or \omega = \sqrt{k/m}.

Error propagation step by step

Suppose we want to compute the error in the formula

    \[Q(A,B,C,D) = \cfrac{A + B}{C + D}\]

It is convenient to do it step by step. Find the uncertainty in the numerator and denominator individually then combine the results.
We can let Y = A + B and Z = C+D then find the uncertainties in Y and Z first.

    \[{\sigma}_Y = \sqrt{ {\sigma}_A^2 + {\sigma}_B^2} \qquad {\sigma}_Z = \sqrt{ {\sigma}_C^2 + {\sigma}_D^2}\]

We can then calculate the uncertainty for Y/Z which would be

    \[\cfrac{{\sigma}_Q}{|Q|} =\sqrt{ \cfrac{{\sigma}_Y^2}{Y^2} + \cfrac{{\sigma}_Z^2}{Z^2}}\]

You can check for yourself that you get the same result as if you did the calculation in one step.

If the formula was

    \[f = \cfrac{A-B}{A+B}\]

then we couldn’t do it step by step the same way because the numerator and the denominator contain the same variables that repeat. The partial derivatives of the numerator and denominator cannot be separated.

The dominant error

The error propagation formula tells you where you should focus your efforts if you want to reduce the uncertainty in a derived quantity.

Example. Suppose you are calculating g from experiments with a pendulum with small oscillations.

    \[\omega^2 =g/l \qquad g = 4\pi^2 \cfrac{l}{T^2}\]

If the fractional uncertainty in the length and period are both ten percent, then how should you proceed to improve the experimental determination of g?
The error propagation formula for this situation.
We can easily write down the error propagation formula

    \[\cfrac{{\sigma}_g}{g} = \sqrt{ \cfrac{{\sigma}_l^2}{l^2} + 4\cfrac{ {\sigma}_T^2}{T^2}}\]

If the fractional uncertainty in the length is 10 percent and the fractional uncertainty in the period is 10 percent then the expression in the square root is

    \[\sqrt{ 0.1^2 + 4\times 0.1^2 }\]

Clearly measuring the period more precisely will have the largest effect on reducing the dominant error in the uncertainty.

MATLAB examples

Example. Finding the uncertainty in e^N.
Let N = 3.2524(35) find Q(N) = e^N and the uncertainty.
We know that (e^x)' = e^x. So we easily calculate the uncertainty using

    \[{\sigma}_Q = |e^N| {\sigma}_N = e^N {\sigma}_N\]

Here is what the Matlab code looks like to calculate that.

format long;
N = 3.2524;
sigN = 0.0035;
f = exp(N)
sigf = exp(N)*sigN
>> f = 25.852311068629906
>> sigf = 0.090483088740205
We do the rounding and find f = 25.852(90)

Example. Finding the uncertainty in \sin(\theta).
What is the uncertainty in Q=\sin( \theta) when \theta = 30.0^\circ \pm 2.5 ^\circ?
First, we convert the numbers to radians. The error propagation formula is then

    \[{\sigma}_Q = | \cos \theta | {\sigma}_\theta\]

It is easy to do all these calculations in Matlab.

format long;
t = 30;
sigt = 2.5;
trad = 30 * pi/180;
sigtrad = 2.5 * pi/180;
df = cos(trad)*sigtrad
f = sin(trad)
>> 0.03778748675488
>> 0.50000000000000
So the answer is \sin \theta = 0.500(38).

Example. Finding the Stefan-Boltzmann constant and its uncertainty.
What is the value and uncertainty of the Stefan-Boltzmann constant

    \[\sigma = \cfrac{\pi^2 k_B^4}{60 \hbar^3 c^2}\]

It’s funny that the notation for the Stefan-Boltzmann constant is already \sigma, don’t get confused.
The propagation of error formula is a common one.

    \[{ {\sigma}_{\sigma}} = \sigma \sqrt{4^2\cfrac{ {\sigma}_{k_B}^2}{ k_B^2} + 3^2\cfrac{{\sigma}_{\hbar}^2}{\hbar^2}}\]

Since c is defined it has no uncertainty. Also constant factors like \pi or \sqrt{2} have no uncertainty.
A quick google for “NIST hbar”, “NIST c”, and “NIST Boltzmann’s constant” gives the necessary data.

format long;
hb = 1.054571800e-34;
shb = 0.000000013e-34;
c = 299792458;
kb = 1.38064852e-23;
skb = 0.00000079e-23;

SB = pi^2/60 * kb^4/(c^2*hb^3)
sigSB = SB*(16*skb^2/kb^2+9*shb^2/hb^2)^(0.5)
>> 5.670366818327269e-08
>> 1.297991325923970e-13

The uncertainty is 0.000013 \times 10^{-8} J m^{-2}s^{-1}K^{-4}. So the final result is

    \[\sigma = 5.670367(13) \times 10^{-8} \mathrm{Jm}^{-2}\mathrm{s}^{-1}\mathrm{K}^{-4}\]

This calculation agrees with the NIST 2016 value.


Reporting Measurements and Uncertainties, Significant Digits, and Rounding


In this lesson, we talk about the number of significant digits used to report measurements and uncertainties. There are conventional rules for the number of significant digits in a number. Experts find that the actual number of significant digits in a measurement is a function of how many significant digits in the uncertainty are used. The best practice is to use two significant digits of uncertainty and to match the precision of the measurement and the uncertainty. Reported measurements should be recorded as a value plus or minus another value, with parenthesis indicating the error in the last digits, or with scientific notation. For measurements that end in zero or zeros, there may be different conventions for indicating or calculating the number of significant digits. An alternative method is to use scientific notation, where all the digits are significant. Calculation of derived quantities from properly reported measurements and uncertainties also make new reportable quantities. Using two significant digits of uncertainty minimizes potential rounding errors.

Correctly Reporting Measurements and Scientific Notation

The best way to learn how to correctly report measurements and uncertainties is to see some examples.
It would be correct to write any of the following.

    \[57.91 \pm 0.46 \quad 57.91(46)\]

    \[(5.791 \pm 0.046) \times 10^1 \quad 5.791(46) \times 10^1\]

We have introduced here scientific notation. A number in scientific notation is of the form A \times 10^B where 1\le A < 10 and B is an integer. The two digits in parenthesis represent the uncertainty in the last two digits of the measurement. It would be incorrect to report any of these because the precision does match.

    \[10.47 \pm 0.022 \qquad 10.4 \pm 0.22 \qquad (1.047 \pm 0.22) \times 10^1\]

I would be very suspicious of the data analysis of any scientific report or book that makes this basic error.

Rules for significant digits

The classic rules for the significant digits in a number are as follows. All non-zero digits are significant. In 1204 1, 2, and 4 are significant for sure. All zeroes between non-zero digits are significant. In 1204, the 0 is also significant. Leading zeros are not significant. 0.012 has only two significant digits Trailing zeroes after the decimal point are significant. 12.0 and 0.0400 both have three significant digits. Trailing zeroes without a decimal point are not significant. 1000 has only one significant digit.

Keeping 2 significant digits

I see a lot of books that give the rule, only use one significant digit of uncertainty. Unfortunately, this is not what the professionals are doing. If you go to the NIST or CODATA website that reports the fundamental constants. They are all given with two digits of uncertainty. We should try to emulate their example.

There is in fact only one rule. Round to two significant digits of uncertainty and match the precision of the measurement by rounding. For example, if we have (4200 \pm 43) or (4200 \pm 1500) then we see that 4200 has a different number of significant digits in each instance. In the first case, 4200 has four significant digits, it just happens to end in two zeros. In the second case, 4200 has only two significant digits because the uncertainty has two significant digits and the precision must match. It would be incorrect to write (4212 \pm 1500). The digits 12 are insignificant in this instance and should be changed to zeros.

Rules for Rounding

We also do not write (671941.283962 \pm 1.56932). Although the precision does match, one cannot justify actually knowing that many digits of uncertainty. Such an expression can be fixed however and written as (671941.3 \pm 1.6). Notice some rounding is involved. The rules for rounding are as follows. Consider the last two digits of the number as xy. If y is 0, 1, 2, 3, or 4 keep x. If y is 5, 6, 7, 8, or 9 then add one to x. Either remove y or replace y with zero depending on the situation.

Rounding the uncertainty is easy (0.0445 \to 0.045), (0.0444 \to 0.44), (12.2 \to 12), (12.9 \to 13), (2501 \to 2500), (2555 \to 2600), (0.999 \to 1.0), and (99.64 \to 100). Notice that 100 still only has two significant digits the first 1 and the first 0. For example, we could write (145.32\pm 99.9921) as (150 \pm 100).

How to do the calculation?

In practice, we keep all the digits for our calculation but then do the rounding at the end. We will usually have an error propagation formula or a method to calculate the spread of our data determining the uncertainty. We then round this to two significant digits. Then we can match our calculator value of the measurement. For example, (4.221242 \pm 0.43412) \to 4.22(43) If you feel there is ever any ambiguity then use scientific notation to indicate your significant digits.

Uncertainty in derived quantities

If we wanted to add two numbers with uncertainty like (12.1 \pm 1.0) and (11.8 \pm 1.0) then we would get (23.9 \pm 1.4). The uncertainty is calculated as \sqrt{1.0^2 + 1.0^2} in this situation. We will learn this later using propagation of error. If we only used one significant digit there would be a major 41 percent rounding error, (\sqrt{2} = 1). This is one of the main reasons for using (at least) two significant digits. It is not necessary to keep an uncertainty to one part in a thousand by convention.

Exact quantities

Certain fundamental physical constants or mathematical constants are defined so you don’t consider their significant digits. They have no uncertainty. You can pretend they have an infinite number of significant digits. If you are working with the speed of light then plug into your calculator

    \[c = 299792458 \mathrm{\,ms}^{-1}\]

If you are calculating the area of a circle and your radius is 4.34 then you should use (\pi = 3.1416) just to have more digits than the number you are working with. You can use more digits but it won’t affect the rounding in the end.

Another example, where significant digits do not come into play, is conversion factors. The definition of an inch is that 25.4 mm equals one inch. This doesn’t mean that all your calculations have to come out with 3 significant digits. Keep using the methods that are outlined in this lesson.