← Projects

Generalized Uncertainty Propagation

CompletePHYS 159February 2025GitHub ↗

Why

In PHYS 159 labs, every quantity we calculated from measured values carried those values’ uncertainty. Propagating it by hand for each new formula was tedious and easy to get wrong, so I wrote a MATLAB live script that does it for any function.

The theory

A function yy of measured quantities x1,…,xnx_1, \dots, x_n, each with uncertainty δxi\delta x_i, has uncertainty

δy=∑i(∂y∂xi δxi)2\delta y = \sqrt{\sum_i \left(\frac{\partial y}{\partial x_i}\, \delta x_i\right)^2}

All of those partial derivatives fit neatly into the Jacobian:

Jy=[∂y1∂x1⋯∂y1∂xn⋮⋱⋮∂ym∂x1⋯∂ym∂xn]\mathbf{J_y} = \begin{bmatrix} \frac{\partial y_1}{\partial x_1} & \cdots & \frac{\partial y_1}{\partial x_n} \\ \vdots & \ddots & \vdots \\ \frac{\partial y_m}{\partial x_1} & \cdots & \frac{\partial y_m}{\partial x_n} \end{bmatrix}

For this tool, the Jacobian is just a way to pull all the derivative information out of a function and put it in one matrix.

How it works

You give it a symbolic function, the measured values and their uncertainties. It computes the Jacobian with the Symbolic Math Toolbox, evaluates it at the measurements, and combines each partial derivative with its uncertainty using the formula above. The comments in the script go through each step.

Stack

MATLAB Live Script (.mlx) · Symbolic Math Toolbox