All guides

Mean and standard deviation in LaTeX

Updated:

In a lab report you usually give the mean of a series of measurements and its uncertainty. The bar over the mean symbol is \bar{x}, and the root of a sum of squares combines \sqrt and \sum.

Try it with your own values

Edit the code and the preview updates as you type.

xˉ=1n∑i=1nxi,s=1n−1∑i=1n(xi−xˉ)2,u(xˉ)=sn\bar{x} = \frac{1}{n} \sum_{i=1}^{n} x_i, \quad s = \sqrt{\frac{1}{n-1} \sum_{i=1}^{n} (x_i - \bar{x})^2}, \quad u(\bar{x}) = \frac{s}{\sqrt{n}}
\bar{x} = \frac{1}{n} \sum_{i=1}^{n} x_i
xˉ=1n∑i=1nxi\bar{x} = \frac{1}{n} \sum_{i=1}^{n} x_i

The mean is the estimate of the true value from n repeated measurements. Define it once like this, then refer to it in the text simply as \bar{x}.

Got a series of measurements? The calculator gives the mean, type A and type B uncertainty and the final result, no account needed. Type A, type B and expanded uncertainty calculator

s = \sqrt{\frac{1}{n-1} \sum_{i=1}^{n} (x_i - \bar{x})^2}
s=1n−1∑i=1n(xi−xˉ)2s = \sqrt{\frac{1}{n-1} \sum_{i=1}^{n} (x_i - \bar{x})^2}

n - 1 in the denominator gives the sample standard deviation, the one expected in lab work. The whole fraction sits under a single \sqrt, which stretches to its height.

u(\bar{x}) = \frac{s}{\sqrt{n}}
u(xˉ)=snu(\bar{x}) = \frac{s}{\sqrt{n}}

It shrinks with the square root of n, so ten measurements give an uncertainty about three times smaller than a single one.

T = (1.42 \pm 0.02)\,\mathrm{s}
T=(1.42±0.02) sT = (1.42 \pm 0.02)\,\mathrm{s}

Give the value and its uncertainty in one bracket with the unit after it. Round the uncertainty to one or two significant figures and the value to the same decimal place.

u_c = \sqrt{u_A^2 + u_B^2}
uc=uA2+uB2u_c = \sqrt{u_A^2 + u_B^2}

The spread of the results (type A) and the instrument accuracy (type B) are independent, so they add in quadrature under one square root.

\frac{u(x)}{x} \cdot 100\%
u(x)x⋅100%\frac{u(x)}{x} \cdot 100\%

The percent sign must be written as \%. A bare % starts a comment in LaTeX and silently hides the rest of the line.

\begin{aligned}
\bar{d} &= \frac{12.02 + 12.05 + 12.03 + 12.06 + 12.04}{5}\,\mathrm{mm} = 12.040\,\mathrm{mm} \\
s &= \sqrt{\frac{1}{4} \sum_{i=1}^{5} (d_i - \bar{d})^2} = 0.0158\,\mathrm{mm} \\
u_A &= \frac{s}{\sqrt{5}} = 0.0071\,\mathrm{mm} \\
u_B &= \frac{0.01\,\mathrm{mm}}{\sqrt{3}} = 0.0058\,\mathrm{mm} \\
u_c &= \sqrt{u_A^2 + u_B^2} = 0.0091\,\mathrm{mm} \\
U &= 2\,u_c = 0.0183\,\mathrm{mm} \to 0.019\,\mathrm{mm}
\end{aligned}
dˉ=12.02+12.05+12.03+12.06+12.045 mm=12.040 mms=14∑i=15(di−dˉ)2=0.0158 mmuA=s5=0.0071 mmuB=0.01 mm3=0.0058 mmuc=uA2+uB2=0.0091 mmU=2 uc=0.0183 mm→0.019 mm\begin{aligned} \bar{d} &= \frac{12.02 + 12.05 + 12.03 + 12.06 + 12.04}{5}\,\mathrm{mm} = 12.040\,\mathrm{mm} \\ s &= \sqrt{\frac{1}{4} \sum_{i=1}^{5} (d_i - \bar{d})^2} = 0.0158\,\mathrm{mm} \\ u_A &= \frac{s}{\sqrt{5}} = 0.0071\,\mathrm{mm} \\ u_B &= \frac{0.01\,\mathrm{mm}}{\sqrt{3}} = 0.0058\,\mathrm{mm} \\ u_c &= \sqrt{u_A^2 + u_B^2} = 0.0091\,\mathrm{mm} \\ U &= 2\,u_c = 0.0183\,\mathrm{mm} \to 0.019\,\mathrm{mm} \end{aligned}

The deviations are -0.02, 0.01, -0.01, 0.02 and 0 mm, so the sum of squares is 0.0010 mm². The final arrow is rounding up, the step the CamteX calculator prints too, and the result reads d = (12.040 ± 0.019) mm with k = 2.

u_B = \frac{\Delta}{\sqrt{3}}, \quad \Delta = 0.01\,\mathrm{mm} \;\Rightarrow\; u_B = 0.0058\,\mathrm{mm}
uB=Δ3,Δ=0.01 mm  ⇒  uB=0.0058 mmu_B = \frac{\Delta}{\sqrt{3}}, \quad \Delta = 0.01\,\mathrm{mm} \;\Rightarrow\; u_B = 0.0058\,\mathrm{mm}

Take Δ from the instrument manual, or the smallest scale division if there is none. A digital meter quoted as ±(0.5 % + 2 digits) reading 12.00 V with 0.01 V resolution gives Δ = 0.06 + 0.02 = 0.08 V before you divide by the root of three.

U = k\,u_c, \quad k = 2, \qquad d = (12.040 \pm 0.019)\,\mathrm{mm} \quad (k = 2)
U=k uc,k=2,d=(12.040±0.019) mm(k=2)U = k\,u_c, \quad k = 2, \qquad d = (12.040 \pm 0.019)\,\mathrm{mm} \quad (k = 2)

k = 2 covers roughly 95 percent of likely values when the result is close to a normal distribution. Write k next to the result: a reader comparing two labs cannot otherwise tell whether the number after ± is u_c or U.

U = 0.018257\ldots\,\mathrm{mm} \to 0.019\,\mathrm{mm}, \qquad \bar{d} = 12.0400\ldots\,\mathrm{mm} \to 12.040\,\mathrm{mm}
U=0.018257… mm→0.019 mm,dˉ=12.0400… mm→12.040 mmU = 0.018257\ldots\,\mathrm{mm} \to 0.019\,\mathrm{mm}, \qquad \bar{d} = 12.0400\ldots\,\mathrm{mm} \to 12.040\,\mathrm{mm}

Keep two significant figures in the uncertainty and round it up, because rounding down claims a better measurement than you made. Then cut the value at the same decimal place. The trailing zero of 12.040 stays: it tells the reader the thousandths were measured.

\begin{aligned}
V &= \frac{\pi \bar{d}^3}{6} = 913.9\,\mathrm{mm^3} \\
\frac{u_c(V)}{V} &= 3\,\frac{u_c(d)}{\bar{d}} = 3 \cdot \frac{0.0091}{12.040} = 0.0023 \\
U(V) &= 2\,u_c(V) = 4.2\,\mathrm{mm^3}
\end{aligned}
V=πdˉ36=913.9 mm3uc(V)V=3 uc(d)dˉ=3⋅0.009112.040=0.0023U(V)=2 uc(V)=4.2 mm3\begin{aligned} V &= \frac{\pi \bar{d}^3}{6} = 913.9\,\mathrm{mm^3} \\ \frac{u_c(V)}{V} &= 3\,\frac{u_c(d)}{\bar{d}} = 3 \cdot \frac{0.0091}{12.040} = 0.0023 \\ U(V) &= 2\,u_c(V) = 4.2\,\mathrm{mm^3} \end{aligned}

For a power, the relative uncertainty is multiplied by the exponent, so the cube triples the relative uncertainty of the diameter. The result is V = (913.9 ± 4.2) mm³, with the uncertainty again rounded up to two significant figures.

|\bar{d} - d_0| = |12.040 - 12.000|\,\mathrm{mm} = 0.040\,\mathrm{mm} > U = 0.019\,\mathrm{mm}
∣dˉ−d0∣=∣12.040−12.000∣ mm=0.040 mm>U=0.019 mm|\bar{d} - d_0| = |12.040 - 12.000|\,\mathrm{mm} = 0.040\,\mathrm{mm} > U = 0.019\,\mathrm{mm}

The ball is sold as 12 mm, and the difference is more than twice the expanded uncertainty, so the two disagree. Before blaming the ball, check the micrometer zero: a zero error shifts every reading by the same amount and type A analysis cannot see it.

\sigma_n = \sqrt{\frac{1}{n} \sum_{i=1}^{n} (d_i - \bar{d})^2} = 0.0141\,\mathrm{mm}, \qquad s = \sqrt{\frac{n}{n-1}}\,\sigma_n = 0.0158\,\mathrm{mm}
σn=1n∑i=1n(di−dˉ)2=0.0141 mm,s=nn−1 σn=0.0158 mm\sigma_n = \sqrt{\frac{1}{n} \sum_{i=1}^{n} (d_i - \bar{d})^2} = 0.0141\,\mathrm{mm}, \qquad s = \sqrt{\frac{n}{n-1}}\,\sigma_n = 0.0158\,\mathrm{mm}

Greek σ and μ belong to a whole population where every value is known; Latin s and x̄ to a sample. Calculators label the two buttons σn and σn-1 or σx and sx. For the five diameters, dividing by n gives a value about 11 percent smaller than s.

M = 4.21, \quad \mathit{SD} = 0.83, \quad \mathit{SE} = \frac{\mathit{SD}}{\sqrt{n}} = 0.17, \quad n = 24
M=4.21,SD=0.83,SE=SDn=0.17,n=24M = 4.21, \quad \mathit{SD} = 0.83, \quad \mathit{SE} = \frac{\mathit{SD}}{\sqrt{n}} = 0.17, \quad n = 24

APA style writes the mean as an italic M and the standard deviation as SD. In math mode a bare SD is two italic variables multiplied together; \mathit{SD} sets it as one word. Say whether a ± after a mean is SD or SE: here the SD is almost five times larger.

Work it out from your own measurements: Type A, type B and expanded uncertainty calculator

Formulas from this guide on their own pages: Mean value, Standard deviation, Type A uncertainty, Combined uncertainty.

Common mistakes and fixes

WrongRightWhy
d = (12.04 \pm 0.018257)\,\mathrm{mm}d = (12.040 \pm 0.019)\,\mathrm{mm}Two significant figures in the uncertainty, rounded up, and the value cut at the same decimal place.
d = 12.040 \pm 0.019\,\mathrm{mm}d = (12.040 \pm 0.019)\,\mathrm{mm}Without the brackets the unit formally belongs to the uncertainty only.
u_c = u_A + u_Bu_c = \sqrt{u_A^2 + u_B^2}Independent uncertainties add in quadrature; a plain sum overstates the result.
u(\bar{x}) = \frac{s}{\sqrt{n-1}}u(\bar{x}) = \frac{s}{\sqrt{n}}The n - 1 is already inside s; dividing by \sqrt{n-1} again makes the uncertainty of the mean too large.
\sigma = 0.0158\,\mathrm{mm}s = 0.0158\,\mathrm{mm}\sigma names the standard deviation of a whole population; a value worked out from your readings with n - 1 is s.

See also

Don't want to memorize commands?

Draw a formula or paste a screenshot, and CamteX turns it into ready LaTeX.

Try it free