Lab report
Lab report
Purpose
This prompt turns a table of measurements (CSV, Excel, or values written by hand) and your lab notes into a university lab report. Python does the calculations and the figure, LaTeX does the typesetting, and every number in the text is pulled in from the analysis output. Nothing is copied by hand, so when a value changes, the whole report changes with it.
The AI does the calculations, uncertainties, figure, table, wording, and typesetting. It does not add values you did not measure or steps you did not perform. If the result disagrees with theory, it does not write it up as agreement. It states how far off the result is and what could explain it.
Input
- Required: the raw data (measurements for each condition) and the name of the experiment. If either is missing, ask one thing only: "Please send your measurements as a table or a file."
- Helpful: the aim, the equipment and the resolution of each instrument, procedure notes, number of repeats, the reference value and its source, course, group, names, date of the experiment, page limit, and any template you were given.
- If your school or instructor gave you a template, that template comes first. Move the content into it and keep its section names, fonts, and margins. The skeleton below is only for when there is none.
- If an instrument's resolution is unknown, ask once. If there is no answer, leave that uncertainty out and list it under "Points to check".
- If the reference value has no source, use the value and put `[source needed]` in the reference list. Never invent a source.
- Do not fill in missing measurements. Drop that condition from the calculation and say so in one line under Results.
- Other unknown details (date, group number) become `[check needed]`. A sentence the user says to keep as is stays word for word.
Output
1. `data.csv` (the raw data you sent, cleaned up), `analyze.py`, `report.tex`, the compiled `report.pdf`, and the figure `fig_fit.pdf`.
2. In the chat, only "Points to check", 3 to 7 lines: final value ± uncertainty, difference from the reference value, uncertainty sources left out, values that are estimates, dropped measurements, page count.
3. If Python or LaTeX cannot run where you are, hand over the three files and the commands to run them. Do not say a PDF or a figure was produced when it was not. Label any numbers "hand-calculated, not yet run".
Rules
1. Steps
1) Put the raw data in `data.csv`. One row per condition, repeats as columns. Put the unit in the column name (`L_m`, `t10_1_s`).
2) Write the target quantity and its equation in one line: "g from the slope of T² = (4π²/g)·L".
3) Run `analyze.py` to get means, uncertainties, the fit, the figure, and `results.tex`.
4) Read the one-line output (value ± uncertainty, χ²/dof, difference from the reference). If anything looks off, stop here and find the cause. Check unit conversions and divisions such as the number of oscillations first.
5) Fill in `report.tex` and compile twice. No reference may show as `??`.
6) Look at every page of the PDF and go through section 9.
2. Report skeleton
Abstract → 1. Aim → 2. Theory → 3. Method → 4. Results → 5. Analysis → 6. Conclusion → References. Long raw data goes to an appendix.
- Abstract: one sentence on what was measured and how, the value ± uncertainty, one sentence comparing it with the reference. 3 to 4 lines.
- Aim: the quantity and the method in one or two sentences. No "to understand the principle of ...".
- Theory: only the equations the calculation uses. Show one step of a derivation and cite the rest.
- Method: equipment and resolution, what was measured and how many times, how each uncertainty was set. Enough for someone else to repeat it.
- Results: table → fit → final value. No interpretation yet.
- Analysis: give the difference from the reference as a multiple of the uncertainty. List each source you left out, with its size.
- Conclusion: the final value again, the largest remaining source, one thing to change next time.
3. Uncertainty
- Repeated measurements: standard error of the mean (Type A) = sample standard deviation ÷ √n.
- Instrument uncertainty (Type B) comes from the smallest scale division. Say in Method how you set it.
- Derived quantities use propagation. For products and quotients, add relative uncertainties in quadrature. For powers, multiply by the exponent: y = T² gives u(y) = 2T·u(T).
- Weight the fit by the uncertainties. If χ²/dof is well above 1, the uncertainties are too small or the model is wrong. If it is well below 1, the uncertainties are too large. Say which in Analysis.
- Effects you did not measure, such as reaction time, get no number. Say in Method that they were left out.
- An uncertainty on the x axis can be compared with the y uncertainties as a·u(x). If it is of the same size and the fit ignores it, say so.
4. Numbers and units
- Round the uncertainty to one significant figure, or two if the first digit is 1. Round the value to the same decimal place: 9.83 ± 0.02, 4.015 ± 0.010.
- Write units with `siunitx`: `\SI{9.83 \pm 0.02}{m/s^2}`. A space between number and unit, units upright.
- Compare with the reference in two ways: relative difference (%) and the difference as a multiple of the uncertainty.
- Replace "small error" and "almost the same" with numbers. Within 2 uncertainties, write "consistent with". Beyond 3, write "disagrees with" and look for the cause.
- Never type a number into the text. Call it by its name from `results.tex` (`\gValue`).
5. Figures
- Axis labels give the quantity and the unit: `$T^2$ (s$^2$)`. No title inside the figure. The caption does that job.
- Data as open circles with error bars, the fit as a solid line. Do not rely on color. The figure must read in black and white.
- Transform the variables so the relation is a straight line (plot T², not T). Put a residual panel (measured − fit) under the fit to show any trend.
- Ticks inside, on all four sides. Legend without a frame. Width 55 to 65 % of the text width.
- Save as vector PDF.
6. Tables
- Three `booktabs` rules only. No vertical lines.
- Quantity and unit in the header row. The same number of decimals within a column.
- Caption above a table, below a figure. Refer to every table in the text at least once ("Table 1 lists ...").
- `analyze.py` writes the table rows into `\dataRows`. Do not `\input` a file inside `tabular`. It breaks before `\bottomrule`.
7. Writing
- Past tense for what was done, present tense for what the results show. One point per sentence.
- Say who did what and how many times, with numbers.
- Before → after
- "There was some error, but the result was almost the same as the theoretical value." → "g is 0.36 % above the reference value, a difference of 1.5 standard uncertainties."
- "Possible sources of error include measurement error and air resistance." → "Not included: locating the ball's center by eye. The 1 mm length uncertainty is worth 0.004 s² on the T² axis, as large as u(T²), and the fit ignores it."
- "Through this experiment, we were able to understand the principle of the simple pendulum." → "T² was proportional to L, and the slope gave g = 9.83 ± 0.02 m/s²."
- "Measurements were taken." → "At each length, the time for 10 oscillations was measured five times."
8. The files
The attachments below were run end to end on a hypothetical case: finding g with a simple pendulum. For another experiment, change parts 1) and 2) of `analyze.py` and the text of `report.tex`.
- `analyze.py`: raw data → means and uncertainties → weighted linear fit → figure → `results.tex`. Run: `python analyze.py`
- `report.tex`: run `pdflatex report.tex` twice. It uses standard packages only, so it compiles with Overleaf's default compiler (pdfLaTeX) without changing any setting. For US Letter paper, change `a4paper` to `letterpaper`.
- `data.csv`: the hypothetical input. Six lengths, five timings of 10 oscillations each. Replace it with your own data and keep the column names.
- The hypothetical run gives g = 9.83 ± 0.02 m/s², χ²/dof = 0.3/4, +0.36 % from the reference value (1.5 standard uncertainties), 3 pages.
9. Final check
- Do the abstract, results, and conclusion give the same value (all from `\gValue`)?
- Does every number have a unit and an uncertainty? Are the digits as in section 4?
- Is every figure, table, and equation referred to in the text at least once? Is there any `??` left?
- Does the reference value have a source, or `[source needed]`?
- Is there any step not performed, or any value not measured, in the text?
- Is the compile log free of errors and `Overfull` boxes? Did you say whether you actually compiled, or only wrote the files?
- If the school or instructor gave a template, does the report follow it?
Attachment 1 · analyze.py (Python)
```python
analyze.py — raw data (data.csv) -> calculation -> figure (fig_fit.pdf) -> LaTeX numbers (results.tex)
Every number in the report comes from this file. Never type a number into the text by hand.
import csv
import math
import matplotlib
matplotlib.use("Agg")
import matplotlib.pyplot as plt
import numpy as np
N_OSC = 10 # oscillations timed in one trial
U_L = 0.001 # standard uncertainty of the length (m): tape resolution 1 mm
G_REF = 9.7966 # reference value (m/s^2); give its source in the report
1) Raw data: one row per condition, repeats as columns
rows = list(csv.DictReader(open("data.csv", encoding="utf-8")))
L = np.array([float(r["L_m"]) for r in rows])
t = np.array([[float(v) for k, v in r.items() if k.startswith("t10_")] for r in rows])
T = t.mean(axis=1) / N_OSC
uT = t.std(axis=1, ddof=1) / math.sqrt(t.shape[1]) / N_OSC # Type A: standard error of the mean
y, uy = T**2, 2 * T * uT # T^2 and its propagated uncertainty
2) Weighted linear fit y = a x + b (weights 1/uy^2)
(a, b), cov = np.polyfit(L, y, 1, w=1 / uy, cov="unscaled")
ua, ub = np.sqrt(np.diag(cov))
g = 4 * math.pi**2 / a
ug = g * ua / a # same relative uncertainty as the slope
chi2 = float(np.sum(((y - (a * L + b)) / uy) ** 2))
dof = len(L) - 2
dev = (g - G_REF) / G_REF * 100 # relative difference from the reference (%)
z = abs(g - G_REF) / ug # difference in standard uncertainties
uLy = a * U_L # u(L) seen on the T^2 axis (s^2), not in the weights
def pm(v, u):
"""(value, uncertainty) strings: uncertainty to 1 significant figure (2 if it starts with 1)."""
e = math.floor(math.log10(u))
if round(u / 10**e) == 1 or f"{u / 10**e:.1f}"[0] == "1":
e -= 1
d = max(0, -e)
return f"{round(v, d):.{d}f}", f"{round(u, d):.{d}f}"
3) Figure: units on the axes, error bars, fit line, readable in black and white
plt.rcParams.update({"font.size": 10, "axes.linewidth": 0.8, "font.family": "serif", "font.serif": ["cmr10"],
"mathtext.fontset": "cm", "axes.formatter.use_mathtext": True}) # cmr10 ships with matplotlib
fig, (ax, rx) = plt.subplots(2, 1, figsize=(4.6, 4.4), sharex=True, gridspec_kw={"height_ratios": [3, 1], "hspace": 0.08})
xx = np.linspace(L.min() - 0.05, L.max() + 0.05, 100)
ax.errorbar(L, y, yerr=uy, xerr=U_L, fmt="o", ms=4, mfc="white", mec="black", ecolor="black", elinewidth=0.8, capsize=2, label="measured")
ax.plot(xx, a * xx + b, "-", color="black", lw=1, label="weighted linear fit")
ax.set_ylabel(r"$T^2$ (s$^2$)")
ax.legend(frameon=False, loc="upper left")
rx.axhline(0, color="black", lw=0.8)
rx.errorbar(L, (y - (a * L + b)) * 1e3, yerr=uy * 1e3, fmt="o", ms=4, mfc="white", mec="black", ecolor="black", elinewidth=0.8, capsize=2)
rx.set_xlabel(r"$L$ (m)")
rx.set_ylabel(r"residual ($10^{-3}$ s$^2$)")
for s in (ax, rx):
s.tick_params(direction="in", top=True, right=True)
fig.savefig("fig_fit.pdf", bbox_inches="tight")
4) Numbers for LaTeX: the text calls them only by name, e.g. \gValue
gv, gu = pm(g, ug)
av, au = pm(a, ua)
bv, bu = pm(b, ub)
with open("results.tex", "w", encoding="utf-8") as f:
f.write(f"\\newcommand{{\\gValue}}{{{gv}}}\n\\newcommand{{\\gUnc}}{{{gu}}}\n")
f.write(f"\\newcommand{{\\slopeValue}}{{{av}}}\n\\newcommand{{\\slopeUnc}}{{{au}}}\n")
f.write(f"\\newcommand{{\\interValue}}{{{bv}}}\n\\newcommand{{\\interUnc}}{{{bu}}}\n")
f.write(f"\\newcommand{{\\chiSq}}{{{chi2:.1f}}}\n\\newcommand{{\\dof}}{{{dof}}}\n")
f.write(f"\\newcommand{{\\gRef}}{{{G_REF}}}\n\\newcommand{{\\gDev}}{{{dev:+.2f}}}\n\\newcommand{{\\gZ}}{{{z:.1f}}}\n")
f.write(f"\\newcommand{{\\uLy}}{{{uLy:.1g}}}\n")
Table rows go in the same file (\input inside tabular breaks before \bottomrule)
table = ""
for Li, Ti, uTi, yi, uyi in zip(L, T, uT, y, uy):
tv, tu = pm(Ti, uTi)
yv, yu = pm(yi, uyi)
table += f"{Li:.3f} & {tv} & {tu} & {yv} & {yu} \\\\ "
with open("results.tex", "a", encoding="utf-8") as f:
f.write(f"\\newcommand{{\\dataRows}}{{{table}}}\n")
print(f"g = {gv} ± {gu} m/s^2, chi2/dof = {chi2:.1f}/{dof}, {dev:+.2f} % from reference ({z:.1f} sigma)")
```
Attachment 2 · report.tex (LaTeX)
```latex
% report.tex — lab report skeleton. Compile: pdflatex report.tex (twice). Overleaf's default compiler works as is.
% Every number comes from results.tex, which analyze.py writes.
\documentclass[11pt,a4paper]{article} % US Letter: change a4paper to letterpaper
\usepackage[margin=25mm]{geometry}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{amsmath,graphicx,booktabs,siunitx,caption,float}
\sisetup{separate-uncertainty=true,range-phrase={--},range-units=single}
\captionsetup{font=small,labelfont=bf}
\linespread{1.15}
\setlength{\emergencystretch}{2em}
\input{results.tex}
\title{\vspace{-12mm}\textbf{Measuring $g$ from the Period of a Simple Pendulum}}
\author{General Physics Lab I, Group 3 \quad Alex Kim\\ \small Experiment: 20 Nov 2026 \quad Submitted: 27 Nov 2026}
\date{}
\begin{document}
\maketitle
\vspace{-8mm}
\begin{abstract}\noindent
The period $T$ of a simple pendulum was measured at six string lengths $L$ from \SIrange{0.30}{0.80}{m}, and the
gravitational acceleration was found from the slope of the $T^2$--$L$ line. The result is
$g = \SI{\gValue \pm \gUnc}{m/s^2}$. It differs from the reference value \SI{\gRef}{m/s^2} by \SI{\gDev}{\percent},
or \gZ{} standard uncertainties, so the two are consistent.
\end{abstract}
\section{Aim}
To measure how the period of a simple pendulum depends on its length, and to find the local gravitational
acceleration $g$ with its uncertainty from that relation.
\section{Theory}
For small amplitudes, a simple pendulum of length $L$ has the period
\begin{equation}
T = 2\pi\sqrt{\frac{L}{g}} \quad\Longrightarrow\quad T^2 = \frac{4\pi^2}{g}\,L . \label{eq:T2}
\end{equation}
A plot of $T^2$ against $L$ is a straight line through the origin, and its slope $a$ gives $g = 4\pi^2/a$.
\section{Method}
\begin{itemize}\setlength\itemsep{0pt}
\item Equipment: steel ball (diameter \SI{25}{mm}), cotton string, stand, tape measure (resolution \SI{1}{mm}),
stopwatch (resolution \SI{0.01}{s}).
\item $L$ is the distance from the pivot to the center of the ball, measured once with the tape.
Its standard uncertainty was set to \SI{1}{mm}.
\item The amplitude was kept below \ang{5}. At each length, the time for 10 oscillations was measured five times.
\item The uncertainty of $T$ is the standard error of the mean of the five trials (Type A).
Human reaction time was not added separately.
\end{itemize}
\section{Results}
Table~\ref{tab:data} lists the period at each length. The raw timings are in the attached \texttt{data.csv}.
\begin{table}[H]\centering
\caption{Period at each string length (hypothetical data). $u$ is the standard uncertainty.}\label{tab:data}
\begin{tabular}{ccccc}\toprule
$L$ (m) & $T$ (s) & $u(T)$ (s) & $T^2$ (s$^2$) & $u(T^2)$ (s$^2$)\\ \midrule
\dataRows \bottomrule
\end{tabular}
\end{table}
A straight line $T^2 = aL + b$, weighted by the uncertainties, was fitted to the data (Figure~\ref{fig:fit}):
\[
a = \SI{\slopeValue \pm \slopeUnc}{s^2/m}, \qquad b = \SI{\interValue \pm \interUnc}{s^2}, \qquad \chi^2/\text{dof} = \chiSq/\dof .
\]
From Eq.~\eqref{eq:T2},
\[
g = \frac{4\pi^2}{a} = \SI{\gValue \pm \gUnc}{m/s^2}, \qquad u(g) = g\,\frac{u(a)}{a} .
\]
\begin{figure}[H]\centering
\includegraphics[width=0.58\linewidth]{fig_fit.pdf}
\caption{$T^2$ against $L$ with the weighted linear fit (top) and the residuals (bottom), hypothetical data.
Error bars are standard uncertainties.}\label{fig:fit}
\end{figure}
\section{Analysis}
\begin{itemize}\setlength\itemsep{0pt}
\item The intercept $b$ is about one $u(b)$ from zero. This agrees with the line through the origin
predicted by Eq.~\eqref{eq:T2}.
\item $g$ is \SI{\gDev}{\percent} above the reference value~\cite{ref}, a difference of \gZ{} $u(g)$.
The measurement is consistent with the reference.
\item $\chi^2$ is below the degrees of freedom. With only five trials per length, $u(T)$ may be overestimated.
\item Not included: locating the center of the ball by eye, stretch of the string, air drag.
The length uncertainty is worth $a\,u(L) = \SI{\uLy}{s^2}$ on the $T^2$ axis, the same size as $u(T^2)$,
but the fit weights use $u(T^2)$ only.
\end{itemize}
\section{Conclusion}
$T^2$ was proportional to $L$, and the slope gave $g = \SI{\gValue \pm \gUnc}{m/s^2}$, consistent with the reference
value within the uncertainty. The length measurement is the largest remaining source. Next time, the ball diameter
should be measured with a vernier caliper to locate its center.
\begin{thebibliography}{9}\small
\bibitem{ref} [source needed] Reference value of $g$ at the lab site (e.g.\ national gravity survey: agency, year, URL).
\end{thebibliography}
\end{document}
```
Attachment 3 · data.csv (CSV)
```csv
L_m,t10_1_s,t10_2_s,t10_3_s,t10_4_s,t10_5_s
0.300,10.98,10.98,11.03,11.00,11.05
0.400,12.69,12.70,12.65,12.74,12.69
0.500,14.15,14.18,14.20,14.20,14.22
0.600,15.55,15.58,15.51,15.51,15.56
0.700,16.73,16.77,16.81,16.78,16.82
0.800,17.92,17.93,17.99,17.96,17.92
```
Connect ChatGPT or Claude and use this prompt now · More prompts