A wave can carry energy across a system while the material itself merely oscillates around equilibrium. A pulse travels along a string, but a marked piece of the string moves mainly up and down. Sound transports energy through repeated compression and expansion, not by moving the same parcel of air from speaker to listener. To describe this precisely, we need both an energy stored per unit length and a signed rate at which energy crosses a chosen position.
Let \(y(x,t)\) be the small transverse displacement of a string. Let \(\mu\) be its mass per unit length and \(T\) its approximately constant tension. The local energy per unit length is
\[u(x,t)=\frac12\mu\left(\frac{\partial y}{\partial t}\right)^2+\frac12T\left(\frac{\partial y}{\partial x}\right)^2\]The first term is kinetic energy per unit length. A short piece of string of length \(dx\) has mass \(\mu dx\) and transverse speed \(\partial y/\partial t\). The second term is elastic potential energy per unit length associated with the string's slope. This approximation assumes small slopes, so higher-order geometric terms can be neglected.
The units provide a quick check. The kinetic term has units \((\mathrm{kg/m})(m/s)^2=\mathrm{J/m}\). The slope is dimensionless, so the tension term also has units \(\mathrm{N}=\mathrm{J/m}\). Integrating over a segment gives its energy:
\[E_{[a,b]}(t)=\int_a^b u(x,t)\,dx\]Energy density tells us where energy is stored; it does not by itself say which way energy is moving. With positive power defined as transport toward increasing \(x\), the instantaneous power crossing position \(x\) is
\[P(x,t)=-T\frac{\partial y}{\partial x}\frac{\partial y}{\partial t}\]The minus sign follows from the chosen direction convention. It can be understood as the rate at which the transverse component of the tension does work on the string to one side of the cut. A source may use the opposite convention, but then every boundary-ledger sign must change consistently.
For an ideal string with no source or damping, density and flux obey the local conservation law
\[\frac{\partial u}{\partial t}+\frac{\partial P}{\partial x}=0\]Integrating this equation from \(a\) to \(b\) gives
\[\frac{dE_{[a,b]}}{dt}=P(a,t)-P(b,t)\]Thus positive rightward power entering at the left raises domain energy, while positive rightward power leaving at the right lowers it. Energy leaving an open domain is not numerical loss if the measured boundary flux accounts for it.
Consider a right-moving sinusoid
\[y(x,t)=A\cos(kx-\omega t)\]where \(A\) is amplitude, \(k\) is wave number, and \(\omega\) is angular frequency. Its derivatives are
\[\frac{\partial y}{\partial x}=-Ak\sin(kx-\omega t),\qquad \frac{\partial y}{\partial t}=A\omega\sin(kx-\omega t)\]Their signs make \(P\ge 0\) for this ideal right-moving wave. Averaging over one cycle, and using the string speed \(v=\sqrt{T/\mu}=\omega/k\), gives
\[P_{\mathrm{avg}}=\frac12T k\omega A^2=\frac12\mu v\omega^2A^2\]Average power is proportional to amplitude squared and frequency squared when \(\mu\) and \(v\) are held fixed. Doubling amplitude therefore multiplies average power and total wave energy by four, not two. Doubling frequency at fixed amplitude and medium also multiplies average power by four.
For a left-moving wave, the derivative signs yield negative \(P\) under this convention. The magnitude still describes the transported power; the sign identifies direction.
Displacement obeys linear superposition, but energy is quadratic. If \(y=y_1+y_2\), squaring the derivatives produces cross terms. It is generally false that the energy density of the sum equals the separate densities added point by point.
This explains why complete displacement cancellation at one place does not destroy energy. Interference redistributes energy in space and time. For two incoherent sources, cross terms may average to zero over a sufficiently long measurement, but that conclusion depends on their phase statistics and the averaging interval.
An ideal standing wave illustrates the same idea. Its two equal traveling components carry equal average powers in opposite directions, so net average power is zero. Yet the standing wave stores nonzero energy, alternating locally between kinetic and elastic forms. “No net transport” is not the same as “no energy.”
Compare sinusoidal string waves at fixed frequency 10 hertz, wave speed 10 metres per second, and linear density 0.01 kilogram per metre. The question for this calculation is precise: how does average transmitted power change when we change wave amplitude, 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 small-slope linear-string approximation and a travelling wave are assumed. 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.0001 to 0.005 m. 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.
In this small example, q stands for wave amplitude, expressed in m. The output is
average transmitted power, expressed in W. 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.
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 0.001 m, the expression gives 0.000197392 W. 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("0.5*0.01*10*(20*pi)**2*q**2", locals={"q": q})
reference_input = 0.001
reference_output = float(expression.subs(q, reference_input))
print("Input:", reference_input, "m")
print("Predicted average transmitted power:", reference_output, "W")
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.
Before drawing hundreds of points, calculate three. The lower endpoint gives 1.97392e-06 W. The midpoint, at 0.00255 m, gives 0.00128354 W. The upper endpoint gives 0.0049348 W. Read these together with the assumptions: they describe different choices of wave amplitude 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.0001, 0.00255, 0.005])
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} m -> {output_value:.6g} W")
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.
The horizontal axis shows wave amplitude; the vertical axis shows average transmitted power. 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.0001, 0.005, 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("Wave amplitude (m)")
ax.set_ylabel("Average transmitted power (W)")
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.
A derivative asks a more specific question than the whole graph: how quickly does average transmitted power change near the reference input? Its units are the output unit divided by the input unit. For this calculation, the derivative at 0.001 m is 0.394784 in those ratio units. Locally, the output increases as the input increases. This statement is local; the sign or size of the slope can be different elsewhere on the curve.
\[f'(q) = 40.0 \pi^{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 = 0.0010245
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, "W")
print("Full expression:", full_prediction, "W")
print("Approximation difference:", full_prediction - linear_prediction, "W")
Here the changed input is 0.0010245 m. The tangent estimate is 0.000207064 W, while the full expression gives 0.000207183 W. 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.
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 = 0.0049
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.
Make one copy of the reference calculation before editing it. Choose a second value of wave amplitude inside the stated interval, predict whether average transmitted power 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 small-slope linear-string approximation and a travelling wave are assumed. 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.
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 W: 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(0.005) - evaluate(0.0001))
for points in [101, 201, 401]:
grid = np.linspace(0.0001, 0.005, 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.
A driven boundary can add or remove energy depending on the phase between its force and velocity. A damper transfers organized wave energy into microscopic thermal energy. A partially transmitting boundary divides incident energy among reflected, transmitted, and dissipated parts.
For a domain with sources and losses, use a finite-interval ledger such as
\[E(t_2)-E(t_1)=E_{\mathrm{in}}-E_{\mathrm{out}}+W_{\mathrm{source}}-E_{\mathrm{dissipated}}+R\]The residual \(R\) is what remains after every modeled transfer is included. It should shrink under numerical refinement for a consistent method. Folding a known damping loss or outgoing flux into \(R\) hides physics inside apparent error.
On a uniform grid, velocity and spatial slope may live at different positions or time levels. State that convention. One simple cell-centered estimate averages neighboring point velocities and uses face differences for slope. More sophisticated schemes can preserve a discrete energy exactly.
import numpy as np
x = np.linspace(0, 1, 1001)
linear_density, tension = 0.01, 1.0
speed = np.sqrt(tension / linear_density)
amplitude, k = 0.001, 2 * np.pi
displacement = amplitude * np.sin(k * x)
velocity = -amplitude * speed * k * np.cos(k * x)
slope = amplitude * k * np.cos(k * x)
energy_density = 0.5 * linear_density * velocity**2 + 0.5 * tension * slope**2
energy = np.trapezoid(energy_density, x)
print(f"Energy in one metre: {energy:.8f} J")
Do not combine a velocity from one time level with displacement from an unrelated time level without documenting the interpolation. In leapfrog-like solvers, velocities may be stored half a step away from displacements. Comparing an unstaggered analytic formula to staggered state can create a false oscillating residual.
The boundary flux calculation should use the same sign convention as the ledger:
boundary_power = -tension * velocity * slope
left_power, right_power, dt = boundary_power[0], boundary_power[-1], 0.01
expected_change = (left_power - right_power) * dt
assert abs(expected_change) < 1e-12
print("Net boundary transfer (J):", expected_change)
All quantities here represent energy over one update. If boundary power varies strongly during the step, integrate it with a time rule consistent with the solver rather than using a single endpoint sample.
Begin with a pure traveling sinusoid and confirm the sign of power reverses when its direction reverses. Scale displacement and velocity together by two and verify that the energy estimate scales by four. In a reflecting, undamped domain, require total energy to remain bounded and for drift to decrease with refinement. At an outgoing boundary, compare lost domain energy with accumulated outward flux.
Also test dimensional consistency and zero cases. A motionless, perfectly straight string has zero wave energy relative to equilibrium. A displaced string instantaneously at rest has elastic but not kinetic energy. A straight string passing through equilibrium can have kinetic but not elastic energy at that instant.
The formulas here assume a one-dimensional string with small slopes, constant tension, constant linear density, and negligible longitudinal motion. Other media have different energy densities and fluxes. Dispersion, stiffness, nonlinear strain, multidimensional geometry, damping, and moving boundaries require additional terms. The conservation-ledger method remains useful, but its entries must come from the actual governing model.