Lab Resources - Error Analysis

Table of Contents

The experiments you will perform in this course are never going to be perfect. The magnitude of the error is determined We will need to develop some machinery for calculating what error is present in a calculation. Fortunately, these calculations can be easily performed by applying a bit of calculus. I wish to introduce some special notation which will be used in this lab. A capital E followed by square braces, \(E[~]\), is defined to be the error operator, which can be either measured (\(E[\ell] = 0.01~m\)) or calculated using a theoretical expression.

1. Partial derivatives

Partial derivatives are wonderful things! You will study this type of derivative extensively in Calc III. I will give you a brief overview here.

Partial derivatives are used in multivariate calculus to find the gradient (slope) of a multidimensional function. Lets think about a function with two dimensions as a mountain range (x and y directions are independent variables), and the height is the z direction, z(x,y). If you take a partial derivative, you will find the slope of this function in only one of these directions. The rate of change of \(z\) in the \(x\) direction would be written as:

$$\frac{\partial z}{\partial x}

The reason I say these derivatives are wonderful is because they are normally somewhat easy to evaluate. You simply take a normal derivative (as seen in calc I) while assuming all other variables are held constant. This means any \(y\) you see in the function can be treated as a constant and can be treated as a constant number number.

The error calculation you use below will use partial derivitives of a function of many variables and you will have to calculate the derivative with respect to each and every independent variable. This can seem daunting, but derivatives are usually fairly easy to calculate with normal calculus rules (dont forget the chain rule!). The final reason these derivatives are wonderful, is a computer can calculate them for us!

2. Propagation of error and reporting experimental values

The experiments you will perform in this course are never going to be perfect. The magnitude of the error is determined We will need to develop some machinery for calculating what error is present in a calculation. Fortunately, these calculations can be easily performed by applying a bit of calculus. I wish to introduce some special notation which will be used in this lab. A capital E followed by square braces, \(E[~]\), is defined to be the error operator, which can be either measured (\(E[\ell] = 0.01~m\)) or calculated using a theoretical expression.

  • \(A\): a variable which you have measured
  • \(E[A]\): the error in the measured variable
  • \(f\): the theoretical expression you are using to calculate
  • \(E[f]\): the error in the calculated function

Given any function \(f\) with arguments \(A,B,\ldots\) The procedure for calculating error in the function \(E[f]\) is given by the following expression:

\begin{equation} E[ f(A,B,\ldots)] = \sqrt{\left( \frac{\partial f}{\partial A} E[A] \right)^2+\left( \frac{\partial f}{\partial B} E[B] \right)^2+\cdots} \end{equation}

Therefore, we need to calculate the partial derivatives of the function f with respect to each independent variable.

3. Evaluation with a computer

3.1. Example: Volume and surface area of a cylinder

Lets calculate the error of some properties of a physical object, namely a cylinder.Lets assume we have measured a cylinder and found the following dimensions: * \(r = 2.47 \pm 0.01 ~ m\) * \(h = 0.27 \pm 0.01 ~ m\)

The radius \(r=2.47~m\) is measured with a meter stick and the error is estimated to be \(E[r] = 1~cm\). (The error of the radius is estimated by the experimenter and based on the accuracy of the measurement device)

The volume of a cylinder is

\[V = \pi r^2 h\]

The error in the volume would then be the result of the following equation:

\[E[V] = \sqrt{ \left( \frac{\partial V}{\partial r} E[r] \right)^2 + \left( \frac{\partial V}{\partial h} E[h] \right)^2}\]

Lets use python to calculate this derivative and substitute the measured values in to arrive at the final volume calculation:

import numpy as np
import sympy
sympy.init_printing(use_latex='mathjax')
import matplotlib as mpl
import matplotlib.pyplot as plt

# initialize all symbolic variables the equation
sympy.var('eqn, error, r, E_r, h, E_h')

# Function to perform error propogation on (must be symbolic)
eqn = sympy.pi * r**2 * h

# list of measured values (note: double ==)
measure=[
      (sympy.pi,3.14159), # pi
      (r,2.47), # radius in meters
      (E_r,0.01), # error of radius measurement
      (h,1.73), # height in meters
      (E_h,0.01) # error of height measurement
     ]

#The error formula: E[eqn]
error = sympy.sqrt(
            (sympy.diff(eqn,r) * E_r)**2 +
            (sympy.diff(eqn,h) * E_h)**2
)

# display the equation and its error
display(eqn)
display(error.simplify())
# substitute measurements into eqn and error functions
print(eqn.subs(measure),"+-",error.subs(measure))

\(\displaystyle \pi h r^{2}\)

\(\displaystyle \pi \sqrt{r^{2} \left(E_{h}^{2} r^{2} + 4 E_{r}^{2} h^{2}\right)}\)

  33.1580907256300 +- 0.329879688527488

The volume is calculated to be \(V = 33.15 \pm 0.33 ~ m^3\). This is a result that you could quote in an abstract (the result has: value, error and units).

3.2. Exercise 1: Surface area of a cylinder

The surface area of a cylinder is

\[A = 2 \pi r (r+h) \]

Try to edit above code to calculate the surface area and its associated error. (Answer: \(A = 65.18 \pm 0.45 ~ m^2\))

# Calculate surface area error here. Please reuse the code from above!

3.3. Exercise 2: Universal law of gravitation

The Universal law of gravitation states the acceleration due to gravity is

\[a = G \frac{m}{r^2}\]

Where G the universal gravitation constant, m is the mass of the earth, and r is the radius of earth

\(G =(6.67408 \pm 0.00030 ) \times 10^{-11} ~m^3kg^{−1}s^{−2}\)

\(m = (5.9722 \pm 0.0006) \times 10^{24}~ kg\)

\(r = (6.368 \pm 0.011) \times 10^6~m\)

(Answer: \(g =9.829 +- 0.034~m/s^2\) which includes our normally used value of \(g=9.8~m/s^2\))

import numpy as np
import sympy
sympy.init_printing(use_latex='mathjax')
# Calculate surface area error here. Please reuse the code from above!

# initialize all symbolic variables the equation
sympy.var('eqn, error, G, E_G, m, E_m, r, E_r')

# Function to perform error propogation on (must be symbolic)
eqn = G*m/r**2

# list of measured values (note: double ==)
measure=[
      (G,6.67408e-11),
      (E_G,0.00030e-11),
      (m,5.9722e24),
      (E_m,00.0006e24),
      (r,6.368e6),
      (E_r,0.011e6)
     ]

#The error formula: E[eqn]
error = sympy.sqrt(
            (sympy.diff(eqn,G) * E_G)**2 +
            (sympy.diff(eqn,m) * E_m)**2 +
            (sympy.diff(eqn,r) * E_r)**2
)

# display the equation and its error
display(eqn)
display(error.simplify())
# substitute measurements into eqn and error functions
print(eqn.subs(measure),"+-",error.subs(measure))

\(\displaystyle \frac{G m}{r^{2}}\)

\(\displaystyle \sqrt{\frac{4 E_{r}^{2} G^{2} m^{2} + r^{2} \left(E_{G}^{2} m^{2} + E_{m}^{2} G^{2}\right)}{r^{6}}}\)

  9.82923326588975 +- 0.0339750064834568

Please note that the above calculation is entirely algorithmic. You will still need to edit a portion of the code when you are entering your functions, but the complicated parts of the calculation (the derivatives) are handled by the computer.

The final value for the acceleration is then quoted in your report as: \(a = 9.829 \pm 0.034 ~ m/s^2\). This range includes the cannonical value of acceleration due to gravity \(9.81~ m/s^2\).

3.4. Error propagation for ball launcher

The propagation formula for experiment 2 (ball launcher) is much longer (but not all that much harder) to calculate. Lets let the computer do all of this work for us! I want to find the error in the ball velocity which was measured in the last experiment.

Recall you launched a ball horizontally from the table. You used the following equations to find the initial velocity of the ball:

\[ y_f = y_i + v_{iy}~t + \tfrac12 a~t^2\]

Solving this equaiton for t yields:

\[t = \sqrt{\frac{2(y_f-y_i)}{a}}\]

Your first task is to calculate the error in this time measurement:

import numpy as np
import sympy
sympy.init_printing(use_latex='mathjax')
# initialize all symbolic variables the equation
sympy.var('eqn, error, y, Ey, y_i, Ey_i, a, Ea')

# Function to perform error propogation on (must be symbolic)
eqn = sympy.sqrt(2*(y - y_i)/a)

# list of measured values (note: double ==)
measure=[(y,.5),
         (Ey,0.02),
         (y_i,0),
         (Ey_i,0),
         (a,9.829),
         (Ea,0.033)
        ]

#The error formula: E[eqn]
error = sympy.sqrt(
            (sympy.diff(eqn,y) * Ey)**2 +
            (sympy.diff(eqn,y_i) * Ey_i)**2 +
            (sympy.diff(eqn,a) * Ea)**2
)

# display the equation and its error
display(eqn)
display(error.simplify())
# substitute measurements into eqn and error functions
print(eqn.subs(measure),"+-",error.subs(measure))

\(\displaystyle \sqrt{\frac{2 y - 2 y_{i}}{a}}\)

\(\displaystyle \frac{\sqrt{2} \sqrt{\frac{\frac{Ea^{2} \left(y - y_{i}\right)}{a^{2}} + \frac{Ey^{2} + Ey_{i}^{2}}{y - y_{i}}}{a}}}{2}\)

  0.318966690612383 +- 0.00640176600131754

After calculating the time it took for the ball to reach the ground, you then were able to use the x-direction to solve for the velocity of the ball coming out of the launcher. Your task is to use the error above to find the error in the velocity of the ball. The equation of motion to solve for velocity in the x-direction is:

\[x_f = x_i + v_{xi}~t + \tfrac12 a_x ~t^2\]

Solving this equaiton for \(v_{xi}\) yields:

\[ v_{xi} = \frac{x_f - x_i}{t}\]