Numerical approximation of the wave equation
Grado en Ing. Civil y Territorial
(Univ. Polit´ecnica de Madrid)
The wave equation
Consider a string of lengthL.
Letu(x,t) be the displacement at the pointx∈ string, and time
t>0.
The following equation describes the small displacements of the string
∂2u
∂t2(x,t)− ∂2u
∂x2(x,t) = 0, x∈(0,L), t>0,
or, abreviated
To obtain a unique solution, we have to include:
1 Boundary conditions at the extremes (ex. fixed)
u(0,t) = 0, t>0, u(L,t) = 0, t >0,
2 Initial conditions
u(x,0) =u0(x), x∈(0,L)
ut(x,0) =v0(x), x ∈(0,L),
The complete system of equations is given by
utt −uxx = 0, x ∈(0,L), t >0,
u(0,t) = 0, t >0, u(L,t) = 0, t >0,
u(x,0) =u0(x), x ∈(0,L), ut(x,0) =v0(x), x∈(0,L).
The Fourier method to obtain solutions
We search for solutions of the form,
u(x,t) =ϕ(x)T(t)
RemarkIfϕ(x) is solution of the eigenvalue problem
ϕ00(x) +λϕ(x) = 0, ϕ(0) = 0, ϕ(L) = 0,
for someλ, then
u(x,t) =ϕ(x) cos(
√
λt) and u(x,t) =ϕ(x) sin(
√
λt)
are solutions of the wave equationutt −uxx = 0 and the boundary
The eigenvalues of this problem areλk = k
2π2
L2 with k = 1,2,3, ...
and the associated eigenfunctions are
ϕk = sin(
kπx L ).
Therefore, all these functions are solutions of the heat equation and boundary conditions
uk(1)(x,t) = cos(kπ
L t) sin( kπx
L )
u(2)k (x,t) = sin(kπ
L t) sin( kπx
first eigenfunction second eigenfunction third eigenfunction
first eigenfunction second eigenfunction third eigenfunction
Matlab code
dx=1/100; % space mesh step
x=0:dx:1; % space mesh
dt=1/100;% time mesh step
t=0:dt:2; % time mesh
k=3; % number of eigenvalue
[xx,tt]=meshgrid(x,t); % (x,t) coordinates of the mesh
Initial conditions
Assume that we can write the initial conditionsu0(x) andv0(x) as
u0(x) =
N X
k=1 cksin(
kπx L ), v
0(x) =
N X
k=1 dksin(
kπx L ),
for some coefficientsck,dk ∈R. Then
u(x,t) =
N X
k=1
ckcos(
kπ L t) sin(
kπx L ) +
Ldk
kπ sin( kπ
L t) sin( kπx
L )
,
As we know, anyL2(0,1)-function can be approximated with a
finite number of terms of the Fourier series and this allows to find approximations of wave solutions.
initial displacement solution of wave equation
Main drawback: Eigenfunctions are only easily computed in few
initial displacement solution of wave equation
Finite differences approximation
utt −uxx = 0, x ∈(0,L), t >0,
u(0,t) = 0, t >0, u(L,t) = 0, t >0,
u(x,0) =u0(x), x ∈(0,L). ut(x,0) =v0(x), x∈(0,L).
Two steps:
1 Space discretization.
Space discretization
Take a partition of [0,L]
with steph. Defineun(t)∼u(xn,t),and replace
−uxx(x,t) by
−un−1(t) + 2un(t)−un+1(t) h2
Then, we have the system
un00(t) +−un−1(t)+2un(t)−un+1(t)
h2 = 0, n= 1,2, ...,N t >0, u0(t) = 0, t >0,
uN+1(t) = 0, t>0,
un(0) =u0(xn), n = 1,2, ...,N−1,
Matrix formulation
U00(t) +KU(t) = 0, U(0) =U0
where
K = 1
h2
2 −1 0 0 ... 0 0
−1 2 −1 0 ... 0 0
... ... ... ... ... ... ...
0 0 0 0 ... −1 2
, U =
u1 u2 ... uN−1
U0 =
u0(x1) u0(x2) ... u0(xN−1)
, V0 =
v0(x1) v0(x2) ... v0(xN−1)
Time discretization
U00(t) +KU(t) = 0, U(0) =U0, U0(0) =V0
Chose a time mesh{tj}J
j=0 with time step ∆t and any method for
initial value systems:
1 Euler (∆t/h≤1 for stability!),
U0 =V
V0 =−KU U(0) =U
0, V(0) =V0
Uj+1 =Uj + ∆tVj,
Vj+1 =Vj−∆t KUj+1, j = 0,1, ...,J−1
Newmark method
U0, V0
Uj+1 =Uj+ ∆tVj −h2 βKUj+1+ (12 −β)KUj,
Vj+1 =Vj−∆t(γKUj+1+ (1−γ)KUj), j = 0, ...,J−1,
In matrix form,
I+ ∆t2βK 0
∆tγK I
Uj+1 Vj+1
=
Uj + ∆tVj −j2(1/2−β)KUj
Vj −∆t(1−γ)KUj
Solution with Euler method
Matlab code for Euler explicit
L = 1; dx=1/40; N=L/dx; % space mesh
K = 2*diag(ones(1,N-1))-diag(ones(1,N-2),1)-diag(ones(1,N-2),-1); K = (1/dx2)∗K; % matrix formulation−uxx
x=dx:dx:L-dx; U=max(0,(1-8*abs(x-1/2)))’; V=0*x’;% initial datum
mu=1; T=2;dt =mu∗dx; t=0:dt:T; % time mesh
sol(1,:)=[0 U’ 0]; % solution at time t=0
for j=1:length(t)-1 % time loop
U =U+dt∗V;
V =V −dt∗K ∗U;
sol(j+1,:)=[0 U’ 0]; % save solution in ’sol’ variable
end % time loop
x1=0:dx:L;
[xx,tt]=meshgrid(x1,t); % (x,t) coordinates of the mesh