HW3 2023
HW3 2023
Homework 3
Discretisation errors
due February 8, 23:59
Guidelines:
• Use only a single pdf. Preferably scan your homework, if you take a photo, make sure it is sharp
and bright;
• Include all plots in the pdf in the right place;
• Do not present plots without commenting them: always write a (short) description of what the
plot tells you and what you can conclude from it;
• You can work in groups up to 3;
• If you work in groups:
– write the names of all group members at the beginning of the report;
– you can work and discuss together but each group member is required to submit an individual
report written with his/her own words; copy-paste reports will not be accepted
• Please use the following naming convention: “surname hwX.pdf ” and include all Matlab files
as a single separate archive: “surname hwX.zip”. X is the number of the homework.
On an equidistant grid, the finite-difference derivative of a Fourier mode eikx can be found by multiplying
the function value on each node with the so-called modified wavenumber k̃(k).
To better understand this concept, we compare the matrix representation and the modified wavenumber
representation of a finite-difference scheme. Let’s consider a periodic function
f (x + pm) = f (x), m ∈ Z.
where p is the period length. Let the vector f be the discrete representation of f (x) on the equidistant
grid where xj := j∆x, ∆x := p/N , j = 0, 1, . . . , N − 1,
where
fj+1 − fj
.δfj :=
∆x
Use MATLAB to assemble the system matrix D (remember that f0 = fN ). Include D in the
written report.
b) Consider f (x) = eikx and derive the expression for the modified wavenumber k̃ for the finite-
difference scheme. Non-dimensionalise the wavenumber with the grid spacing, i.e. derive the
expression for k̃∆x.
Computational Fluid Dynamics, SG2212 / SG3114, Spring 2023 2
c) From now on assume that k = 3 (i.e. consider a specific Fourier mode). Compute the derivative
in a discrete (δfj ) and analytical (f 0 (x)|x=xj ) manner at every grid point. Use the previously
defined D for the discrete derivative. Plot the real part for both the numerical and the analytical
derivative as a function of x, then comment on their differences. (Hint: use a higher value of N to
obtain smoother curves)
d) Compute the vector µ with the elements
δfj
µj :=
fj
and compare it with the complex number ik̃, where k̃ is the modified wavenumber for the right-
sided finite differences as derived in b). Does this result confirm that the finite-difference derivative
of a Fourier mode eikx can be found by multiplying the function by the modified wavenumber, i.e.
does ik̃f = D f hold?
In this task we will examine the dissipative and dispersion error introduced by a first-order and a second-
order numerical scheme. Let us consider the advection equation,
∂u ∂u
+c =0. (1)
∂t ∂x
Question 1: Discretise the advection equation employing the following schemes:
(Hint: What is the analytic solution for a generic initial condition? Use it for each Fourier mode).
Then, compute εA and εP for the upwind and the leapfrog scheme and use this result to discuss quali-
tatively how a single sinusoidal wave will be affected by the two discretisation schemes.
You can compare the behaviour of the amplitude and phase error for the first-order scheme and the
phase error for the second-order scheme with the solution given in Figure 1.
Computational Fluid Dynamics, SG2212 / SG3114, Spring 2023 3
Figure 1: (Left) Dissipative and (centre) dispersive error for the first-order scheme and (right) dispersive
error for the second-order scheme, as function of φ = k∆x for different values of σ = c∆t/∆x.