A Byte of PhysicsLogo

Damped oscillations

Damping transfers mechanical energy out of an oscillator. In the common linear viscous model, damping force is proportional to velocity and points against it. The decay should emerge from the force law and state evolution, not from multiplying an undamped picture by an arbitrary shrinking envelope.

Linear viscous damping

For mass \(m\), stiffness \(k\), and viscous damping coefficient \(c\), the forces are

\[F_{\mathrm s}=-kx\qquad F_{\mathrm d}=-c\dot x\]

Newton's second law becomes

\[m\ddot x+c\dot x+kx=0\]

The coefficient \(c\) has SI units newton-seconds per meter, equivalent to kilograms per second. Positive \(c\) ensures the damping force opposes motion.

import numpy as np

mass, stiffness, damping = 1.0, 4.0, 0.4
x, v = 1.0, 0.0
spring_force, damping_force = -stiffness * x, -damping * v
print("Acceleration (m/s^2):", (spring_force + damping_force) / mass)

At a turning point velocity is zero, so viscous damping force is momentarily zero even though the spring force is largest. Damping grows after the mass begins moving.

Natural scales and damping ratio

The undamped natural angular frequency is

\[\omega_0=\sqrt{\frac{k}{m}}\]

Define the decay-rate parameter

\[\gamma=\frac{c}{2m}\]

and dimensionless damping ratio

\[\zeta=\frac{c}{2\sqrt{mk}}=\frac{\gamma}{\omega_0}\]

The critical damping coefficient is

\[c_{\mathrm c}=2\sqrt{mk}\]

These derived quantities classify three regimes. They do not replace solving the initial- value problem.

Underdamped motion

When \(0<\zeta<1\), motion crosses equilibrium repeatedly with decreasing amplitude. The damped angular frequency is

\[\omega_{\mathrm d}=\sqrt{\omega_0^2-\gamma^2}=\omega_0\sqrt{1-\zeta^2}\]

and the solution has form

\[x(t)=Ae^{-\gamma t}\cos(\omega_{\mathrm d}t+\phi)\]

The amplitude envelope decays as \(e^{-\gamma t}\). Because energy is proportional to amplitude squared, its smooth envelope decays as \(e^{-2\gamma t}\).

The actual energy oscillates relative to this envelope because kinetic and potential energy exchange while dissipation depends on velocity. A fitted decay rate should state whether it comes from amplitude peaks or energy.

Critical damping

When \(\zeta=1\), the repeated root of the characteristic equation gives

\[x(t)=(C_1+C_2t)e^{-\omega_0t}\]

Critical damping returns toward equilibrium without oscillation and, among the ideal nonoscillatory linear cases, does so as rapidly as possible. Depending on initial velocity, a trajectory may still cross equilibrium once; “no oscillation” is more precise than “never crosses.”

Critical damping is a parameter condition, not a visual judgment from a coarse trace. Calculate \(c_{\mathrm c}\) from mass and stiffness and compare with the actual coefficient.

Overdamped motion

When \(\zeta>1\), two negative real decay rates appear:

\[r_{1,2}=-\gamma\pm\sqrt{\gamma^2-\omega_0^2}\]

and

\[x(t)=C_1e^{r_1t}+C_2e^{r_2t}\]

The slower exponential controls late-time return. Adding more damping can make this slow mode even slower, which is why overdamping does not mean fastest settling.

Mechanical-energy ledger

Mechanical energy is

\[E_{\mathrm{mech}}=\frac12m\dot x^2+\frac12kx^2\]

Differentiate and use the equation of motion:

\[\frac{dE_{\mathrm{mech}}}{dt}=-c\dot x^2\leq0\]

This is also damping power \(P_{\mathrm d}=F_{\mathrm d}\dot x\). It is zero at an instantaneous turning point and most negative when speed is large.

If transferred energy is counted positively in a reservoir,

\[E_{\mathrm{mech}}(t)+E_{\mathrm{reservoir}}(t)=E_{\mathrm{mech}}(0)\]

for the ideal closed combined model. Saying mechanical energy is “lost” means it has become unresolved heat, sound, or another form; total energy is not destroyed.

times = np.linspace(0, 10, 10001)
beta = damping / (2 * mass)
omega_d = np.sqrt(stiffness / mass - beta**2)
positions = np.exp(-beta * times) * (
    np.cos(omega_d * times) + beta / omega_d * np.sin(omega_d * times)
)
velocities = (
    -(stiffness / mass) / omega_d * np.exp(-beta * times) * np.sin(omega_d * times)
)
mechanical = 0.5 * mass * velocities**2 + 0.5 * stiffness * positions**2
heat = np.trapezoid(damping * velocities**2, times)
print("Energy ledger residual (J):", mechanical[-1] + heat - mechanical[0])

Numerical quadrature of power introduces its own error, so the ledger residual should converge as the time step is reduced.

State evolution

Write the ODE as

\[\dot x=v\qquad\dot v=-\frac{k}{m}x-\frac{c}{m}v\]
def derivative(state):
    x, v = state
    return np.array([v, (-stiffness * x - damping * v) / mass])


print("State derivative:", derivative([0.2, -0.1]))

Use an integrator appropriate to the stiffness and accuracy target. A coarse explicit step can add energy despite positive physical damping, or it can add excessive numerical damping. Both effects contaminate a fitted decay rate.

Compare numerical position and velocity with the analytic linear solution at shared times. Repeat with a smaller step. Regime classification should come from parameters, while trace shape and decay rate test the solver.

Phase-space view

An underdamped trajectory spirals inward toward the origin in position-velocity phase space because mechanical energy decreases. Critical and overdamped paths approach the origin without repeated loops. Axes and units matter: changing velocity scaling changes the visual shape but not the physical regime.

The inward spiral is appropriate only for positive damping and no external drive. An outward spiral indicates negative damping, energy input, or numerical error. A closed ellipse belongs to the ideal undamped oscillator.

Settling measures

“Settled” needs a threshold. One useful condition requires both position and velocity to stay within tolerances for a specified duration. Checking position alone near a zero crossing can falsely declare settling while speed is large.

inside = (abs(positions) < 0.1) & (abs(velocities) < 0.2)
# A settling time needs the entire remaining record to stay inside both bands.
remaining_inside = np.logical_and.accumulate(inside[::-1])[::-1]
indices = np.flatnonzero(remaining_inside)
print("Settling time within this record:", times[indices[0]] if len(indices) else None)

Report threshold, duration, and sample rate with settling time.

Other damping laws

Linear viscous damping is accurate for some devices and limited flow regimes. Quadratic drag has magnitude proportional to speed squared and still opposes velocity. Dry friction has nearly constant magnitude away from zero and requires a sticking rule. Structural loss can depend on frequency, while viscoelastic materials carry memory and internal state.

These models have different late-time behavior and energy transfer. Do not tune \(c\) to match one observation and assume the law is valid everywhere. Measure decay at several amplitudes or frequencies.

Reliability checks

With zero damping, recover the undamped oscillator. At zero velocity, instantaneous viscous force and power must be zero. For positive damping, power must never be positive. Calculate damping ratio and verify the corresponding analytic regime.

Track mechanical energy, cumulative transfer, and residual; compare position, velocity, decay rate, and settling time under time-step refinement. Distinguish physical damping from algorithmic dissipation. Only then does a decaying curve support a physical claim.

Estimating damping from measured peaks

In an underdamped experiment, successive displacement peaks provide a convenient decay measurement because they occur at comparable phases. If peaks separated by one damped period have magnitudes \(A_n\) and \(A_{n+1}\), their logarithmic decrement is

\[\delta=\ln\frac{A_n}{A_{n+1}}\]

For the ideal linear model,

\[\delta=\gamma T_{\mathrm d}=\frac{2\pi\zeta}{\sqrt{1-\zeta^2}}\]

where damped period is \(T_{\mathrm d}=2\pi/\omega_{\mathrm d}\). Several peak pairs should give similar values if exponential viscous decay is a good model. Fit across multiple peaks rather than relying on one noisy ratio, and report peak detection and uncertainty.

The measured damped frequency and decay rate can be combined to estimate the undamped frequency because \(\omega_0^2=\omega_{\mathrm d}^2+\gamma^2\). If mass is known, stiffness and damping coefficient follow from

\(k=m\omega_0^2\)

and \(c=2m\gamma\).

This inference assumes linear stiffness and linear viscous damping over the measured range. If logarithmic decrement changes systematically with amplitude, the discrepancy may indicate nonlinear drag, friction, or sensor limits rather than random noise.

Distinguishing decay from a shifted equilibrium

A constant external force shifts the equilibrium position but does not by itself create damping. Analyze displacement relative to the new equilibrium. Otherwise a trace that settles to a nonzero position may be fitted with the wrong amplitude envelope.

Likewise, slowly changing stiffness or support position can make the baseline drift. Detrend only when the physical reason is understood; blindly subtracting a fitted curve can remove real low-frequency motion. Save raw measurements, calibration, and the transformation used to define equilibrium.

A worked Python notebook

Track the exponential envelope of an underdamped oscillator with decay rate 0.2 per second. The question for this calculation is precise: how does amplitude envelope change when we change time, while keeping the other choices fixed? The earlier sections explain the physical relationship. Here we turn one part of that relationship into a calculation that you can run, inspect, and change in Google Colab.

The envelope is a bound on oscillation amplitude, not the instantaneous displacement. Keep that sentence beside the results. A formula can return a number outside its useful range, and a plotting library will usually draw that number without asking whether the physical assumptions still hold. The selected interval is from 0 to 10 s. It gives us a specific domain to discuss instead of leaving the graph's range to a software default.

Use the notebook link above the lesson, run the setup cell, and then run the cells in order. The code below is also included there. NumPy handles the arrays of numerical values, SymPy keeps the equation symbolic, and Matplotlib draws the results. If these libraries or notebook cells are unfamiliar, start with Your first physics notebook.

State the relationship before choosing a graph

In this small example, q stands for time, expressed in s. The output is amplitude envelope, expressed in m. The equation below uses the numerical values in those units. Any fixed coefficients therefore carry the units needed to make the relation consistent. A value supplied in another unit must be converted before it enters this expression.

\[f(q) = e^{- 0.2 q}\]

This is a function of one changing input. It is not a statement that the physical system has only one variable. We deliberately hold the other inputs fixed so that one cause of variation is visible. Changing several inputs at once would make it harder to tell which change produced the output difference. Write down the held-fixed choices before trying a different experiment.

At 5 s, the expression gives 0.367879 m. This is our reference calculation. It is a prediction of the stated example, not a new measurement. Its displayed digits help us compare implementations. They should not be read as a claim that physical inputs are known to six significant figures.

import numpy as np
import sympy as sp
import matplotlib.pyplot as plt

q = sp.Symbol("q", real=True)
expression = sp.sympify("exp(-0.2*q)", locals={"q": q})
reference_input = 5.0
reference_output = float(expression.subs(q, reference_input))
print("Input:", reference_input, "s")
print("Predicted amplitude envelope:", reference_output, "m")

sp.Symbol declares a mathematical symbol. It does not assign a numerical measurement to that symbol. subs then replaces the symbol with our chosen input, and float converts the resulting symbolic number into a standard Python numerical value. Keeping these steps separate lets us inspect the equation before numerical substitution. It also prevents a later plot from becoming the only surviving record of the model.

Compare a few cases you can explain

Before drawing hundreds of points, calculate three. The lower endpoint gives 1 m. The midpoint, at 5 s, gives 0.367879 m. The upper endpoint gives 0.135335 m. Read these together with the assumptions: they describe different choices of time within the same example, with the other inputs held fixed.

These three values are a useful first check, but they do not establish the shape between them. Two endpoints can be equal even when the curve bends or oscillates in between. Likewise, a large change between endpoints does not tell us whether the relationship is linear. We need the equation and intermediate samples to answer those questions.

evaluate = sp.lambdify(q, expression, modules="numpy")
inputs = np.array([0.0, 5.0, 10.0])
outputs = np.asarray(evaluate(inputs), dtype=float)
outputs = np.broadcast_to(outputs, inputs.shape)
for input_value, output_value in zip(inputs, outputs):
    print(f"{input_value:.6g} s -> {output_value:.6g} m")
assert np.all(np.isfinite(outputs))

lambdify turns the symbolic expression into a numerical function. We explicitly select NumPy as its numerical backend so it can accept an array. The same expression now has two useful forms: one for algebra and one for calculating many cases. The assertion checks that the chosen inputs produce finite outputs. It would catch an infinity or an undefined numerical result, but a finite value can still be physically inappropriate.

Make a graph that answers the question

The horizontal axis shows time; the vertical axis shows amplitude envelope. Every plotted point is a prediction of the same expression. We mark the reference case separately so that a reader can connect the earlier printed value to its place on the curve. The axis labels include units because a shape without a scale cannot tell us the size of a physical effect.

input_grid = np.linspace(0.0, 10.0, 301)
output_grid = np.asarray(evaluate(input_grid), dtype=float)
output_grid = np.broadcast_to(output_grid, input_grid.shape)
fig, ax = plt.subplots(figsize=(7, 4))
ax.plot(input_grid, output_grid, label="Stated model")
ax.scatter([reference_input], [reference_output], label="Reference case", zorder=3)
ax.set_xlabel("Time (s)")
ax.set_ylabel("Amplitude envelope (m)")
ax.legend()
ax.grid(alpha=0.25)
fig.tight_layout()
plt.show()

Look for a sign change, a turning point, or a region where the curve becomes steep. Connect each feature to the expression rather than to the colour of the line. If the curve has a minimum or maximum, changing the input in opposite directions may have similar effects on the output near that point. If it is nearly straight over a short interval, a local linear approximation may be useful even when the complete expression is nonlinear.

Increasing the number of samples makes the line smoother and may reveal features that a coarse grid missed. It does not improve the physical inputs or enlarge the model's validity range. For quantities that can take only discrete values, use the line as a guide to the relationship and interpret only the allowed input values. A plotting function does not enforce such restrictions for you.

Measure the local sensitivity

A derivative asks a more specific question than the whole graph: how quickly does amplitude envelope change near the reference input? Its units are the output unit divided by the input unit. For this calculation, the derivative at 5 s is -0.0735759 in those ratio units. Locally, the output decreases as the input increases. This statement is local; the sign or size of the slope can be different elsewhere on the curve.

\[f'(q) = - 0.2 e^{- 0.2 q}\]

For a small input change, multiply the derivative by that change to estimate the output change. Then compare that estimate with a fresh evaluation of the full expression. The distinction between these two calculations matters: the derivative gives a tangent approximation, while substitution evaluates the chosen expression at the new point.

slope_expression = sp.diff(expression, q)
slope_at_reference = float(slope_expression.subs(q, reference_input))
changed_input = 5.05
linear_prediction = reference_output + slope_at_reference * (
    changed_input - reference_input
)
full_prediction = float(evaluate(changed_input))
print("Symbolic derivative:", slope_expression)
print("Tangent prediction:", linear_prediction, "m")
print("Full expression:", full_prediction, "m")
print("Approximation difference:", full_prediction - linear_prediction, "m")

Here the changed input is 5.05 s. The tangent estimate is 0.364201 m, while the full expression gives 0.364219 m. If the two values are close, it means the chosen input change is small enough for this local approximation at this point. It does not mean the entire model is linear. If the slope is zero, a quadratic or higher-order term may supply the leading change instead.

This is also the beginning of uncertainty propagation. If the input has a small stated standard uncertainty, the magnitude of the slope times that uncertainty estimates one contribution to output uncertainty. Do not automatically use the same rule for a wide interval, a discontinuity, a turning point with zero first derivative, or several correlated uncertain inputs. Those situations need more of the model than one slope.

Check the derivative with numerical differences

We can estimate the same slope from values on either side of the reference point. Subtract the lower output from the upper output and divide by twice the input step. Parentheses are essential: the entire output difference must be divided by the entire input interval. Without them, Python can execute a different mathematical expression while still producing a plausible number.

The calculation below uses three decreasing step sizes. Each estimate is compared with the symbolic derivative, so the reference is independent of the numerical difference formula. Near an endpoint, it is acceptable here to evaluate a small extension only because the displayed mathematical expression is smooth there; such a check does not assert that extrapolated values describe additional physical cases.

input_span = 10.0
for fraction in [1e-2, 1e-3, 1e-4]:
    step = input_span * fraction
    upper = float(evaluate(reference_input + step))
    lower = float(evaluate(reference_input - step))
    numerical_slope = (upper - lower) / (2 * step)
    difference = numerical_slope - slope_at_reference
    print(f"step={step:.6g}: slope={numerical_slope:.6g}, difference={difference:.6g}")

For a smooth function, reducing the step often reduces the approximation error at first. Very small steps can eventually make subtraction of nearly equal floating-point values less reliable. Therefore “smaller” is not an unlimited guarantee of “better.” Compare the observed behaviour over a useful range of steps instead of choosing the smallest number the computer can represent.

An absolute slope difference is useful when the expected slope is near zero. A relative difference would divide by a very small reference and could look enormous even when the absolute discrepancy is tiny. Away from zero, a relative difference can help compare quantities with very different scales. The tolerance should reflect the question and the numerical method, rather than a universal decimal threshold copied into every test.

Change the example and preserve the reasoning

Make one copy of the reference calculation before editing it. Choose a second value of time inside the stated interval, predict whether amplitude envelope will rise or fall, and then evaluate the expression. Place the prediction and the result in a text cell. If they disagree, identify whether the mistake was in the sign, the unit conversion, the algebra, or the assumption about how the curve behaves.

Next choose a shorter plotting interval around the reference point. Compare the local curve with its tangent approximation. Then widen the interval again. The difference shows why a useful local estimate need not describe the whole range. Keep the axis labels and numerical scale visible when comparing the plots; automatic axis limits can make two different effects appear equally large.

Finally, return to the physical limit stated at the start: The envelope is a bound on oscillation amplitude, not the instantaneous displacement. Describe one change to the setup that would violate that limit. State what new input, equation, or observation would be needed before trusting an answer in the changed situation. This last step connects the Python experiment to the physics instead of treating successful execution as the only criterion for a useful result.

Before saving, restart the runtime and run all cells in order. A result that depends on an earlier, now-deleted input cell is not reproducible from the saved notebook. Keep unrounded values for later calculations, round only the reported output, and label any new data as measured, assumed, or generated. The graph and printed values should remain traceable to the same expression and the same choices of inputs.

Recover the output change by integrating the slope

There is another way to check that the expression and its derivative describe the same relationship. Add up the small output changes predicted by the slope across the chosen input interval. In the continuous limit, this integral equals the output at the upper endpoint minus the output at the lower endpoint. The result has units of m: the input unit in the integration cancels the input unit in the denominator of the slope.

This statement is about the mathematics of this particular relationship. It does not assign a new physical meaning to an arbitrary area under a graph. For example, an area under force versus distance represents work, while an area under a different pair of quantities may represent something else or have no standard name. Always carry the axis units through the calculation before naming an integral.

slope_function = sp.lambdify(q, slope_expression, modules="numpy")
endpoint_change = float(evaluate(10.0) - evaluate(0.0))
for points in [101, 201, 401]:
    grid = np.linspace(0.0, 10.0, points)
    slopes = np.asarray(slope_function(grid), dtype=float)
    slopes = np.broadcast_to(slopes, grid.shape)
    integrated_change = np.trapezoid(slopes, grid)
    print(
        points,
        "integrated change:",
        integrated_change,
        "endpoint change:",
        endpoint_change,
    )

The trapezoidal rule joins neighbouring slope samples with straight segments and adds their signed areas. A negative contribution remains negative; replacing every slope by its magnitude would calculate a different quantity. Increasing the sample count provides a practical refinement check. If the values do not settle toward the endpoint difference, first inspect the interval, singularities, and array ordering.

Do not conclude that two agreeing calculations prove the model is physically complete. Both use the same selected relationship, so an omitted effect would be omitted from both. Their agreement is evidence that the numerical tools implement that relationship consistently. Comparing with an independent experiment or a more appropriate physical model is a separate test.

Keep this comparison in the notebook when you change the expression. It is particularly useful after adding a coefficient, changing a sign convention, or converting an input unit. A code cell that produces a smooth graph can conceal these mistakes; a second calculation of the same output change gives you another place to notice them.

Sources


Share to: