Wave equation#
What you will learn
Wave Equation Overview: The wave equation, a partial differential equation (PDE), fully describes the spatial and temporal evolution of waves.
Linearity of the Wave Equation: The wave equation is linear, meaning that any linear combination of solutions is also a solution. This allows the most general solution to be expressed as a linear combination of all possible solutions.
Boundary and Initial Conditions: To solve the wave equation for a specific physical system, boundary conditions must be specified. These include the values the wave function takes at the physical boundaries (e.g., \(x = 0\) and \(x = L\)). Initial conditions with respect to time (e.g., at \(t = 0\)) may also be required.
Solution Method for 1D Guitar String: For a 1D guitar string, the wave equation is solved by separating variables, solving the resulting ordinary differential equations, and then applying boundary conditions at the two ends of the string.
Periodic Solutions: The solution for a 1D guitar string results in an infinite number of periodic solutions, which are parameterized by an integer \(n\).
Classical Wave equation#
Wave equation is an example of a second order PDE (partial differential equation). This PDE governs behavior of displacement \(u(x,t)\) in time and space.
Fig. 40 Classical wave equation can describe any complicated wave in space and time given the intitial conditions.#
Applications of the Classical Wave Equation: To illustrate the applications of the classical wave equation, we will solve it for a 1D guitar string. This provides a comprehensive mathematical description of the string’s behavior.
Predicting Evolution: By specifying arbitrary initial conditions, the wave equation allows us to precisely predict the evolution of the string over time and space.
Fig. 41 Classical wave equation can describe any complicated wave in space and time given the intitial conditions.#
Solving Wave Equation: The big picture#
1. Boundary Conditions: To solve the wave equation for a specific physical situation, such as a guitar string fixed at both ends, we need to specify two boundary conditions. Mathematically, these are:
where \(u(x, t)\) represents the displacement of the string at position \(x\) and time \(t\).
2. Separation of Variables: A common method to solve such equations is the technique of separation of variables. This technique assumes that \(x\) and \(t\) vary independently of each other, allowing us to express \(u(x, t)\) as a product of two functions, each depending on only one variable. This allows us to decompose PDE into Ordinary Differnetial Equations ODEs.
3. Principle of superposition: The wave equation is linear which you can see by \(u\) terms appearing with first order on both side. Linearity means that linear combination of two solutions \(u_1\) and \(u_2\) is also a solution. If you have \(n\) particular solutions than you write general solution as linear combination of n terms.
Step 1: Plug the Product of Univariate Functions into the Wave Equation#
Start with the 1D wave equation that can describe 1D guitar string:
Substitute \(u(x, t) = X(x)T(t)\) into the wave equation:
After rearranging, we get:
Thus, we obtain two separate ordinary differential equations (ODEs) from the original partial differential equation (PDE):
where \(K\) is a constant.
Step 2: Solving Each Ordinary Differential Equation#
After decomposing the PDE into ODEs, we solve each ODE separately:
Solving simple liner and homogenuous ODEs
Going from ODE to algebraic equations
To solve linear (no powers of y) and homogenuous (no constants, right hand side is zero) ODEs we plug exponential function, e.g \(y(x) \rightarrow e^{kx}\).
What this does to ODE is turn it into simple algebraic equation where the only variable is\(k\).
In our case of second order wave equation we will be dealing with simple quadratic equations:
The solutions of which are given as:
The most general solution is then written in terms of linear combination. We need extra info to determine c_1 and c_2 (e.g boundary or initial conditions)
Example ODE
For instnace if we plug \(y=e^{kx}\) in the following equation and cancel exponents on both sides we will get algebraic equation in terms of k.
We get two solutions (could be complex real, repeated) which we then use to write general solution in the form of a superposition.
Solving the spatial part: when \(K > 0\)
If \(K > 0\), we specify \(K = \beta^2\), where \(\beta\) is a constant. The general solution for \(X(x)\) is represented as linar combination of particular solutions (principle of superposition):
\[ X(x) = c_1 e^{\beta x} + c_2 e^{-\beta x} \]Applying the boundary conditions \(X(0) = X(L) = 0\) leads to \(c_1 = c_2 = 0\). Since a non-trivial linear combination of two exponential functions cannot be zero everywhere, this results in the trivial solution:
\[ X(x) = 0 \]This implies that the string does not move—no music!
Solving the spatial part: when \(K < 0\)
If \(K < 0\), we specify \(K = -\beta^2\), where \(\beta\) is a constant. The general solution for \(X(x)\) is:
\[ X(x) = c_1 e^{i \beta x} + c_2 e^{-i \beta x} \]Using Euler’s formula, this can be rewritten as:
\[ X(x) = c_1 (\cos(\beta x) + i \sin(\beta x)) + c_2 (\cos(\beta x) - i \sin(\beta x)) \]Simplifying further:
\[ X(x) = (c_1 + i c_2) \cos(\beta x) + (c_1 - i c_2) \sin(\beta x) \]Let \(A = c_1 + i c_2\) and \(B = c_1 - i c_2\):
\[ X(x) = A \cos(\beta x) + B \sin(\beta x) \]Applying the boundary conditions \(X(0) = 0\) and \(X(L) = 0\):
At \(x = 0\): \(A \cdot 1 + B \cdot 0 = 0\), so \(A = 0\).
At \(x = L\): \(X(L) = B \sin(\beta L) = 0\).
For a non-trivial solution, \(\sin(\beta L) = 0\), which implies:
\[ \beta L = n \pi \quad \text{where} \quad n = 1, 2, 3, \ldots \]Hence:
\[ \beta = \frac{n \pi}{L} \]\[ X(x) = B \sin \left(\frac{n \pi}{L} x \right) \]
Solving temporal part
Having identified \(K<0\) conditions through solution of spatial part we can now solve for \(T(t)\):
Substitute \(K = \beta^2\):
The solution is:
Solution for spatial part#
Becasue of boundary conditions (\(X(x)=X(L)=0\)) imposed at the ends of guitar string we found infinite number of solutions indexed by an integer number \(n\). These terms are called normal modes and are visualized below.
Fig. 42 The first seven solutions (normal modes) of spatial part of the wave equation on a length \(L\) with two amplitudes (one positive and one negative).#
Show code cell source
import numpy as np
import matplotlib.pyplot as plt
# Parameters
L = 1.0
B = 1.0
ns = [1, 2, 3, 4]
x = np.linspace(0, L, 800)
# 2x2 subplot
fig, axes = plt.subplots(2, 2, figsize=(8, 6))
for ax, n in zip(axes.ravel(), ns):
Xn = B * np.sin(n * np.pi * x / L)
ax.plot(x, Xn, color="C0")
ax.axhline(0, color="black", linewidth=0.8)
ax.set_title(f"n = {n}")
ax.set_xlabel("x")
ax.set_ylabel("X(x)")
ax.set_xlim(0, L)
fig.suptitle("Normal modes of a fixed–fixed string")
fig.tight_layout(rect=[0, 0, 1, 0.96])
Solution for temporal part#
For temporal part since we do not have boundary conditions! Time is allowed to march forward into infinity. We find solution in the form of linear combination of sine and cosine functions with \(\omega_n = \beta v = \frac{n \pi v}{L}\) and \(n = 1, 2, 3, \ldots\) represents the normal modes.
In the second line we esing trig identity to express sum of cosine and sine in terms of cosine. Still we have two constantst o determine
The constants \(A_n\) \(\phi_n\) in temporal part are determined by initial codnitions E.g what should be the amplitude and phase of wave at starting time \(t=0\).
Step 3 Full solution: A linear combination of normal modes#
After solving ODEs for spatial and tempoeral parts we now combine them into a full solution.
The complete description of any vibrational motion of the guitar string is given by the sum of the normal modes, \(X_n(x)\).
While the terms involving time, \(T_n(t)\), depend on how and where the string is plucked, the normal modes \(X_n(x)\) remain the same for a given string.
About nodes#
Places where guitar string is at the resting position at 0 are called nodes. We notice that number of nodal points increases with n.
For \(n = 1\): There are 0 nodes (excluding the endpoints). This is called the fundamental frequency or first harmonic.
For \(n = 2\): There is 1 node. This is known as the first overtone or second harmonic.
For \(n = 3\): There are 2 nodes. This is called the second overtone or third harmonic.
Note that the general solution to wave equation is expressed as a linear combination of all normal modes
Show code cell source
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
from IPython.display import HTML
# Parameters (reduced frames for faster export)
L = 1.0
v = 1.0
B = 1.0
A = {1: 1.0, 2: 1.0, 3: 1.0}
phi = {1: 0.0, 2: 0.0, 3: 0.0}
x = np.linspace(0, L, 600)
def X(n, x):
return np.sin(n * np.pi * x / L)
def T(n, t):
omega_n = n * np.pi * v / L
return np.cos(omega_n * t + phi[n])
def u_mode(n, x, t):
return B * X(n, x) * T(n, t)
def u_sum(modes, x, t):
s = np.zeros_like(x)
for n in modes:
s += A[n] * X(n, x) * T(n, t)
return s
omega1 = np.pi * v / L
T1 = 2 * np.pi / omega1
tmax = 2 * T1
frames = 120 # fewer frames
ts = np.linspace(0, tmax, frames)
fig, axes = plt.subplots(2, 2, figsize=(8, 6))
axes = axes.ravel()
titles = ["n = 1", "n = 3", "n = 1 + 2", "n = 1 + 2 + 3"]
lines = []
for ax, title in zip(axes, titles):
ax.set_xlim(0, L)
ax.set_ylim(-1.6, 1.6)
ax.set_xlabel("x")
ax.set_ylabel("u(x,t)")
ax.set_title(title)
ax.axhline(0, linewidth=0.8)
line, = ax.plot([], [])
lines.append(line)
fig.suptitle("Standing waves on a fixed–fixed string")
def init():
for line in lines:
line.set_data([], [])
return lines
def update(idx):
t = ts[idx]
lines[0].set_data(x, u_mode(1, x, t))
lines[1].set_data(x, u_mode(3, x, t))
lines[2].set_data(x, u_sum([1, 2], x, t))
lines[3].set_data(x, u_sum([1, 2, 3], x, t))
return lines
ani = FuncAnimation(fig, update, frames=frames, init_func=init, blit=True, interval=1000*(tmax/frames))
plt.close(fig) # Prevents static display of the last frame
HTML(ani.to_jshtml())
2D Membrane Vibrations#
The wave function of a 2D membrane with fixed edges depends on two independent spatial variables, \(x\) and \(y\). By applying the method of separation of variables, we decompose the wave function into three ordinary differential equations.
For the spatial components \(X(x)\) and \(Y(y)\), there are boundary conditions that must be satisfied at the fixed edges: Boundary condition along the \(X\)-axis: \(X(0) = X(L) = 0\) and Boundary condition along the \(Y\)-axis: \(Y(0) = Y(L) = 0\)
The 2D normal mode is the product of two 1D mode. Since dimensions are independent we get integer numbers \(n\) for the \(x\)-direction and \(m\) for the \(y\)-direction:
The angular frequency \(\omega_{nm}\) depends on the geometry of the membrane (with dimensions \(a\) and \(b\)) and the mode numbers \(n\) and \(m\):
Where:
\(v\) is the wave speed,
\(n\) and \(m\) are the mode numbers,
\(a\) and \(b\) are the dimensions of the membrane.
Fig. 43 Vibrations of 2D membrane.#
Full derivation of 2D rectangular membrane problem
To extend the solution of the 1D guitar string problem to 2D, you can analyze a 2D vibrating membrane, such as a rectangular or circular drumhead. Here’s a step-by-step solution for a 2D rectangular membrane:
Solution for a 2D Rectangular Membrane
Consider a rectangular membrane with dimensions \(L_x\) and \(L_y\), fixed along its edges. The wave equation for the membrane is:
where \(c\) is the wave speed.
Separation of Variables
Assume the solution can be written as a product of functions, each depending on only one variable:
Substitute this into the wave equation:
This simplifies to:
Divide through by \(X(x) Y(y) T(t)\):
Since the left side depends only on \(t\) and the right side depends only on \(x\) and \(y\), each side must equal a constant, which we denote as \(-\lambda\):
Solving for \(T(t)\)
The ODE for \(T(t)\) is:
This has the general solution:
where \((\omega = \sqrt{\lambda} c)\).
Solving for \(X\) and \(Y\)
To solve the spatial part, we need to separate the problem into two parts:
Assume:
where \((\lambda = \alpha^2 + \beta^2)\).
So, we have:
Boundary Conditions:
For a rectangular membrane with boundaries \(x = 0\), \(x = L_x\), \(y = 0\), and \(y = L_y\), we apply:
The solutions for \(X(x)\) and \(Y(y)\) are:
where \(n\) and \(m\) are positive integers, and:
So, the general solution for \(u(x, y, t)\) is:
where:
This solution describes the vibration modes of a 2D rectangular membrane, with each mode characterized by different integer values of \(n\) and \(m\).
Show code cell source
import numpy as np
import matplotlib.pyplot as plt
import ipywidgets
from ipywidgets import interact, interactive, Dropdown
from matplotlib.animation import FuncAnimation
from IPython.display import HTML
import plotly.graph_objects as go
from plotly.subplots import make_subplots
def membrane2d_mode(n=1, m=1, t=0):
"""
Calculates the 2D grid of points (X, Y) and the normal mode displacement (Z) of a vibrating
rectangular membrane at a specific time t.
Parameters:
n (int): Mode number along the x-direction. Default is 1.
m (int): Mode number along the y-direction. Default is 1.
t (float): Time at which to evaluate the normal mode. Default is 0.
Returns:
X, Y, Z (numpy arrays): Grid of points in the X-Y plane and the corresponding
membrane displacement Z(X, Y, t).
"""
# Constants
Lx, Ly = 1.0, 1.0 # Dimensions of the rectangular region
v = 0.1 # Wave speed
omega = v * np.pi / Lx * (n**2 + m**2) # Angular frequency for the normal mode
# Create a spatial grid
Nx, Ny = 100, 100 # Number of grid points in each dimension
x, y = np.linspace(0, Lx, Nx), np.linspace(0, Ly, Ny)
X, Y = np.meshgrid(x, y)
# Compute the spatial part of the normal mode
Z = np.sin(m * np.pi * X / Lx) * np.sin(n * np.pi * Y / Ly) * np.cos(omega * t)
return X, Y, Z
def viz_membrane2d_plotly(n=1, m=1, t=0):
"""
Visualizes the 2D normal modes of a vibrating membrane on a square geometry using Plotly.
This function displays both a 2D contour plot and a 3D surface plot of the membrane displacement.
Parameters:
n (int): Mode number along the x-direction. Default is 1.
m (int): Mode number along the y-direction. Default is 1.
t (float): Time at which to evaluate the normal mode. Default is 0.
"""
# Get the membrane displacement at time t
X, Y, Z = membrane2d_mode(n, m, t)
# Create a Plotly subplot with 2 views: 2D contour and 3D surface
fig = make_subplots(
rows=1,
cols=2,
subplot_titles=('2D Contour Plot', '3D Surface Plot'),
specs=[[{"type": "contour"}, {"type": "surface"}]]
)
# Add 2D contour plot to the left side
fig.add_trace(
go.Contour(x=X.flatten(), y=Y.flatten(), z=Z.flatten(), colorscale='RdBu'),
row=1, col=1
)
# Add 3D surface plot to the right side
fig.add_trace(
go.Surface(x=X, y=Y, z=Z, colorscale='RdBu'),
row=1, col=2
)
# Update the layout for better visualization
fig.update_layout(
title_text="2D Contour and 3D Surface Plots of Membrane Vibrational Normal Modes",
width=1000,
height=500
)
# Show the figure
fig.show()
interact(viz_membrane2d_plotly, n=(1,1), m=(2,3), t=(0,100))
<function __main__.viz_membrane2d_plotly(n=1, m=1, t=0)>
The sound of music.#
Music produced by musical instruments is a combination of sound waves with frequencies corresponding to a superposition of normal modes (in music they call harmonics, overtones) of those musical instruments.
Learn more from this series.
Fig. 44 The size of the musical instrument reflects the range of frequencies over which the instrument is designed to function. Smaller size implies higher frequencies, larger size implies lower frequencies.#
Example Problems#
Problem 1: Simple Harmonic Oscillator#
Solve the ODE:
where \(\omega\) is a constant.
Solution:
The characteristic equation is:
Solving for \(r\):
Thus, the general solution is:
where \(C_1\) and \(C_2\) are constants determined by initial conditions.
Problem 2: Damped Oscillator#
Solve the ODE:
where \(\beta\) and \(\omega\) are constants. Consider cases of \(\beta^2 < \omega^2\), \(\beta^2 > \omega^2\) and \(\beta^2 = \omega^2\)
Solution:
The characteristic equation is:
Solving for \(r\) using the quadratic formula:
Depending on the discriminant \(\beta^2 - \omega^2\), we have three cases:
Underdamping (\(\beta^2 < \omega^2\)):
\[ y(t) = e^{-\beta t} [C_1 \cos(\omega_d t) + C_2 \sin(\omega_d t)] \]where \(\omega_d = \sqrt{\omega^2 - \beta^2}\).
Critical Damping (\(\beta^2 = \omega^2\)):
\[ y(t) = (C_1 + C_2 t) e^{-\beta t} \]Overdamping (\(\beta^2 > \omega^2\)):
\[ y(t) = C_1 e^{r_1 t} + C_2 e^{r_2 t} \]where \(r_1\) and \(r_2\) are the distinct real roots found from the quadratic formula.
Problem 3: ODE with Constant Coefficients#
Solve the ODE:
Solution:
The characteristic equation for this ODE is:
Solving for \(r\):
Thus, the general solution is:
where \(C_1\) and \(C_2\) are constants determined by initial conditions.
Problem 4: Simple 2nd order ODE#
Solve the ODE:
Solution:
The characteristic equation for this ODE is:
Solving for \(r\):
Thus, the general solution is:
where \(C_1\) and \(C_2\) are constants determined by initial conditions.
Problem 5: When ODE gives repeated roots#
Solve the ODE:
Solution:
The characteristic equation for this ODE is:
Factoring:
Thus:
The general solution for repeated roots is:
where \(C_1\) and \(C_2\) are constants determined by initial conditions.