Professional Documents
Culture Documents
Assignment 04
Assignment 04
In one spatial dimension, the wave equation has the general form
∂2u 2
2∂ u
= a
∂t2 ∂x2
where, for simplicity, we will assume that a is constant. Observe that it is possible to rewrite
the wave equation as a system of coupled first-order PDE
∂r ∂s
= a
∂t ∂x
∂s ∂r
= a
∂t ∂x
∂u =
s
∂t
where
∂u ∂u
r=a and s= .
∂x ∂t
∂U ∂F (U )
+ = 0, (1)
∂t ∂x
where
" # " #
r 0 −a
U= and F (U ) = U.
s −a 0
We can apply the Lax-Friedrichs scheme to the solution of the wave equation through the
first-order system (1) and easily obtain
1 n ν
rjn+1 = n
(rj+1 + rj−1 ) + (snj+1 − snj−1 ),
2 2
1 n ν n
sn+1 = (s n
+ sj−1 ) + (rj+1 n
− rj−1 ).
j
2 j+1 2
where ν = ak/h. Once the value of sn+1
j has been calculated, the value for un+1
j can be com-
puted according to
un+1
j = unj + ksnj .
1
Master in Applied and Computational Mathematics Year 2022/2023
We can adapt the Leapfrog scheme to equations (1) for the solution of the wave equation in
one dimension, centring variables on appropriate half-mesh points
∂u n unj+1 − unj
n
rj+ 1 := a ≈ a , (2)
2 ∂x j+ 1 h
2
n+ 1
n+ 1 ∂u 2 un+1
j − unj
sj 2 := ≈ , (3)
∂t j k
n+1 n n+ 1 n+ 12
1 + ν(sj+1 − sj
2
rj+ 1 = rj+ ), (4)
2 2
n+ 12 n− 12 n n
sj = rj + ν(rj+ 1 − r ). (5)
2
j− 12
As in the previous scheme, the new value for the wave variable u is finally computed after
the integration in time of s. Here however, to preserve the second-order accuracy in time it is
necessary to average the time derivative s between n and n + 1 to obtain
k k n+ 1
un+1
j = unj + (sn+1
j + snj ) = unj + sj 2 + O(k 2 ).
2 2
A simple substitution of (2) and (3) into (4) and (5) shows how the Leapfrog representation
of the wave equation is nothing but its second-order differencing
un+1
j = ν 2 unj+1 + 2(1 − ν 2 )unj + ν 2 unj−1 − ujn−1 .
Note that by doing this, the Leapfrog scheme has been effectively recast into a “one-level”
scheme.
2
Master in Applied and Computational Mathematics Year 2022/2023
ν ν2 n
rjn+1 = rjn + (snj+1 − snj−1 ) + (rj+1 − 2rjn + rj+1
n
),
2 2
ν n ν2
sn+1
j = snj + (rj+1 n
− rj−1 ) + (snj+1 − 2snj + snj+1 ).
2 2
Again, to preserve the second-order accuracy in time it is necessary to average the time deriva-
tive s between n and n + 1 to obtain
k
un+1
j = unj + (sn+1 + snj ).
2 j
Question 1
(a) Which is the expected rate of convergence of each of the methods described above?
Hint: obtain the local truncation error.
(b) Calculate the corresponding stability conditions (or, at least, justify them).
Hint: use Von-Neumann analysis (or some of the arguments discussed in class)
Boundary conditions
Unavoidable and common to all the numerical schemes discussed so far is the problem of
treating the solution on the boundaries of the spatial grid as the time evolution proceeds.
Some boundary conditions of general interest are:
mimic the presence of a reflecting boundary, i.e., of a boundary with zero transmission
coefficient. Observe that this condition enforced at x0 leads to
u1 − u−1
= 0 =⇒ u1 = u−1 .
2h
3
Master in Applied and Computational Mathematics Year 2022/2023
1 h n+1 i a h n+1 i
(uj+1 + un+1
j ) − (un
j+1 + un
j ) = − (uj+1 + un
j+1 ) − (un+1
j + un
j )
2k 2h
and which leads to
un+1 n+1
j+1 (1 + ν) = −uj (1 − ν) + unj+1 (1 − ν) + unj (1 + ν).
un+1 n n+1
j+1 = uj − uj Q + unj+1 Q, (6)
(1 − ν)
where Q = . This equation will provide first-order accurate and stable bound-
(1 + ν)
ary conditions. Note, however, that this is a discrete representation of a physical condi-
tion which would transmit the wave without reflection. In practice, however, a certain
amount of reflection is always produced (the transmission coefficient is never exactly
one); the residual wave is then transmitted back in the numerical box. A few reflections
are usually sufficient to reduce the wave content to values below the machine accuracy.
Similarly, a scalar wave outgoing in the negative x-direction (or ingoing in the positive
one) described by ut − aux = 0, leads to
un+1
j = unj+1 − un+1 n
j+1 Q + uj Q, (7)
where Q is the same quantity as for the out-going wave. If we use equations (6) and (7)
to evolve the solution at time-step n + 1 at the boundary of our spatial grid, we are
guaranteed that our profile will be completely transported away, whatever integration
scheme we are adopting (Leapfrog, Lax-Wendroff, etc).
Question 2
4
Master in Applied and Computational Mathematics Year 2022/2023
(a) Implement each of the numerical schemes above to solve the PDE problem (8) with ho-
mogeneous Dirichlet boundary conditions. Integrate until T = 4 and use, for instance,
the command waterfall in MATLAB. You should obtain a graph similar to Figure 1.
Run experiments to prove convergence at the expected rate.
(b) Choose the Leapgrog scheme to solve the PDE problem (8) with boundary conditions:
(c) The initial condition ut (x, 0) = −ux (x, 0) corresponds to a left-moving Gaussian pulse
which can be approximated by
2
u(x, −k) = e−200(x−k) .
In all them, integrate until T = 4 and use the command waterfall as in Figure 1.