---
title: "Virial Theorem Observatory Interactive Lab | Sandbox Physics"
description: "When does the virial theorem actually hold? Only for bound motion, and only after a long time."
canonical_url: "https://sandboxphysics.com/labs/virial-theorem-observatory/"
language: "en"
page_type: "lab"
alternate_languages:
  zh-CN: "https://sandboxphysics.com/zh/labs/virial-theorem-observatory/"
last_modified: "2026-10-27"
---

M047 · Energy averages

# Virial Theorem Observatory

**When does the virial theorem actually hold?** Only for bound motion, and only after a long time. Over any finite stretch, twice the average kinetic energy differs from the average radial-force term by a boundary term: the change in position times momentum, divided by the elapsed time. That gap is real physics, not numerical error. A bound orbit keeps it finite, so it fades as time grows; an escaping one need not.

Follow bound and escaping orbits in power-law and logarithmic potentials. Compare the running averages of kinetic energy and of the radial-force term, keep the boundary term that a finite time window leaves, and check the relation again from raw sensor readings.

> Interactive simulation: open this page in a web browser to change the parameters and run the model.

The Newtonian radial field is prescribed in advance. Numerical errors are shown, and the limits of each approximation are stated.

Physics tutorial

## Finite-time virial, before the limit

**Background** In this Lab the force always points along the radius, and the chosen source sets how its strength changes with distance.

**Why it matters** Link what you see in the scene to the computed trajectory and to sensor readings taken separately.

Start with the essentials

- **Focus question**: When does the virial theorem actually hold?
- **One-sentence intuition**: Over a finite time, the boundary term is real physics, not numerical error.

### Core mathematical model

#### Attractive radial potentials

$$
\begin{aligned}U(r)&=\frac A n\left(\frac r{r_0}\right)^n\quad(n\ne0)\\U_{\log}(r)&=A\ln\left(\frac r{r_0}\right)\end{aligned}
$$

The logarithmic potential is a separate choice, and the energy zero of the power-law potentials is not shifted to match it. The test mass is one kilogram.

#### The virial identity at each instant

$$
\frac{d(\mathbf r\cdot\mathbf p)}{dt}=2K-W,\qquad W=-\mathbf r\cdot\mathbf F
$$

The signs follow from a radius that points outward and a force that points inward.

#### The identity averaged over a finite time

$$
2\langle K\rangle_T-\langle W\rangle_T=\frac{(\mathbf r\cdot\mathbf p)(T)-(\mathbf r\cdot\mathbf p)(0)}{T}
$$

Over a short interval the physical boundary term can be large, and the identity still holds accurately.

#### The virial term for each potential

$$
\begin{aligned}W&=nU\quad(n\ne0)\\W_{\log}&=A\end{aligned}
$$

The familiar long-time energy relation follows only when the boundary term goes to zero.

#### Conserved quantities

$$
\begin{aligned}E&=\frac12m|\mathbf v|^2+U(r)\\L_y&=m(zv_x-xv_z)\end{aligned}
$$

The orbit lies in the horizontal plane. Errors in energy and angular momentum are reported separately from the virial residual.

### Common difficulties

#### What the model assumes

**Typical misconception** An ideal model like this automatically describes a real planet or a relaxed star cluster.

**Better mental model** The source is fixed in advance, the test particle does not pull back on it, and the effects left out are listed.

### Run the experiment

1. 01

   #### Compare potentials

   Try Kepler ellipse, Harmonic well, Quartic confinement and Logarithmic potential.

   **What to observe:** When the force law changes, the running averages change with it.

2. 02

   #### Keep the boundary term

   Compare Short observation with a longer duration, and drag the selected time.

   **What to observe:** The gap between the averages tracks the physical boundary term. What remains after subtracting it measures numerical error.

3. 03

   #### Test the assumption

   Raise the Kepler launch speed above escape speed and watch the boundary term.

   **What to observe:** An escaping particle breaks the assumption of bounded motion, and observing for longer need not restore the relation.

4. 04

   #### Take readings, then refine the step

   Acquire the computed trajectory, look at the raw estimates, then halve the integration step.

   **What to observe:** Resampling and sensor noise affect the raw estimate, separately from the numerical average taken at every step.

Physical conclusion

Check that the assumptions hold, not just that the numbers agree.

Motion & dynamics · Starter path

## From a falling ball to an orbit

Start by measuring gravity and splitting motion into components. Then add contact forces and collisions, and follow the same laws all the way to an orbit.

[Start here → **Free Fall & Measuring Gravity** Capture a few drops and fit the camera positions to estimate gravitational acceleration. Then add air damping and watch the fit drift from the truth. Observe · 14 min](https://sandboxphysics.com/labs/free-fall/)

1. [1 Free Fall & Measuring Gravity](https://sandboxphysics.com/labs/free-fall/)
2. [2 Projectile Flight Designer](https://sandboxphysics.com/labs/projectile-flight/)
3. [3 Inclined Plane & Friction](https://sandboxphysics.com/labs/inclined-plane/)
4. [4 One-Dimensional Collision Bench](https://sandboxphysics.com/labs/collision-bench/)
5. [5 Mass–Spring Oscillator](https://sandboxphysics.com/labs/mass-spring/)
6. [6 How Orbits Take Shape](https://sandboxphysics.com/labs/orbit/)

[View the full path →](https://sandboxphysics.com/topics/mechanics/#starter-path)
