Solving the 1D Wave Equation

Christopher Lum
lum@uw.edu

This document accompanies the YouTube video at https://youtu.be/lMRnTd8yLeY.

Step 2: Satisfying the Boundary Conditions

(*Input (Subscript[λ, n]) and (Subscript[u, n])(x,t)*)
λn[n_]=c n π/L;

un[x_,t_,n_]=(Bn Cos[λn[n] t]+Bnstar Sin[λn[n] t]) Sin[((n π)/L) x]

Recall the 1D wave equation

	(((∂^2)u)/(∂ (t^2)))=(c^2)(((∂^2)u)/(∂ (x^2)))

(*Verify that this satisfies the 1D wave equation*)
D[un[x,t,n],{t,2}]== (c^2) D[un[x,t,n],{x,2}]//Simplify

Recall the BCs

	u(0,t)=0		(left side fixed)
	u(L,t)=0		(right side fixed)

un[0,t,n]==0   (*check left side*)
Simplify[un[L,t,n]==0,n∈Integers]   (*check left side*)

Verify that superposition holds

	(Subscript[u, super])=2 (Subscript[u, 2])(x,t)-3 (Subscript[u, 3])(x,t)+π (Subscript[u, 23])(x,t)

uSuper[x_,t_]=2 un[x,t,2]-3 un[x,t,3]+π un[x,t,23]

D[uSuper[x,t],{t,2}]== (c^2) D[uSuper[x,t],{x,2}]//Simplify

uSuper[0,t]==0   (*check left side*)
Simplify[uSuper[L,t]==0]   (*check left side*)

Numerical Example (Animate the Scenario)

LGiven=3.5;
cGiven=200;

unGiven[x_,t_,n_]=un[x,t,n]/.{L->LGiven,c->cGiven,Bn->1,Bnstar->1}

Animate the scenario

tMax=0.04;

Manipulate[
Plot[unGiven[x,t,n],{x,0,LGiven},
(*Plotting option*)
PlotRange->{{0,LGiven},{-1.5, 1.5}}],
{t,0,tMax},
{n,1,5,1}
]

Step 3: Solution to the Entire Problem Via Fourier Analysis

(*Print values of c and L to ensure we have them entered into Mathematica*)

cGiven
LGiven

(*Define the coefficients Bn*)

BnComputed[n_,q_]=((32 q Cos[((n π)/4)] ((Sin[((n π)/4)])^3))/((n^2) (π^2)))

(*check that un is still defined*)

un[x,t,n]

(*Define a partial sum of the total solution with Nmax terms*)
Nmax=15;
qGiven=2.5;
uN[x_,t_]=Sum[un[x,t,n]/.{Bn->BnComputed[n,qGiven],Bnstar->0},{n,1,Nmax}]/.{c->cGiven,L->LGiven}

(*Visualize*)
Manipulate[
Plot[uN[x,t],{x,0,LGiven},
(*Plot options*)
PlotRange->{{0,LGiven},{-3,3}}],
{t,0,tMax}]