MASSACHUSETTS INSTITUTE OF TECHNOLOGY
DEPARTMENT OF MECHANICAL ENGINEERING
CAMBRIDGE, MASSACHUSETTS 02139
2.29 / 2.290 NUMERICAL FLUID MECHANICS — SPRING 2021
Problem Set 3
Issued: Thursday, March 18, 2021 Due: Tuesday, April 6, 2021
Notes: Please provide a hard-copy (handwritten/printed) of your solutions. Please do not print your codes
in your hard-copy solutions. Codes should be submitted via Stellar. The bulk of the grades will be given to
detailed explanations and to numerical schemes that capture the essence of the problems. We know that
successful coding of numerical schemes can be time-consuming and prone to small errors. Such small errors
or omissions in a code will not be heavily penalized.
Problems 3.e), 4d), and 5d-f) are not required for the 2.290 undergraduate version of the course.
Problem 1 (Modified from Chapra and Canale, Problem 23.19)
Compare the second-order forward, backward and centered finite-difference approximations of
the first-derivatives of the following three functions:
e −2 x − x , f 2 ( x ) =
f1 ( x ) = e2 x − x , f 3 ( x ) =
sin(4 x ) − x
a) Determine the exact value of the three derivatives at x = 2.
b) Evaluate the centered finite-difference approximation of the first-derivative for these three
functions, using a grid size ∆x =0.5 . Repeat this evaluation, decreasing ∆x in successive
increments of 0.01 down to a value of ∆x =0.01 .
c) Carry out b) for the second-order forward and backward finite-differences (these computations
can be completed in the same loop as that of b).
d) Plot the error as a function of ∆x for the estimate of the derivatives of the three functions.
Compare/discuss the results, using the remainder of the three different Taylor Series expansions.
Problem 2: Gradient Methods for Solving Linear Systems
Consider the following system of linear algebraic equations:
0.8 x1 − 0.4 x2 =
41
−0.4 x1 + 0.8 x2 − 0.4 x3 =
25
−0.4 x2 + 0.8 x3 =
105
a) Construct the equivalent optimization problem for the given system of linear algebraic
equations. Identify the objective function in this optimization.
b) Use the steepest descent gradient method to solve for x in the above optimization problem. Use
x = 0 as the initial guess. How many iterations are required to obtain a solution that is accurate up
to 2 decimal places?
c) Compute the solution using the conjugate gradient method. Again, use x = 0 as the initial guess.
How many iterations are required to obtain the exact solution?
Page 1 of 5
Problem 3 (Modified from Prob. 12.39 in Chapra and Canale):
The steady-state distribution of temperature on a heated plate can be modeled by the Laplace
equation:
∂ 2T ∂ 2T O T=0 b
=0 + y
∂x 2 ∂y 2
If the plate is represented by a series of
nodes, centered finite differences can be ∆x
substituted for the second derivatives,
∆y
which results in a system of linear T=0
T=80
algebraic equations. Boundary
conditions are as in the similar heated
plate Problem of Problem Set 1.
a) Substitute into the Laplace equation
the centered finite differences for this a
two-dimensional problem in both the x
and y directions. What are the x T=0
coefficients in front of each term? You
can provide your answer in terms of a
“computational cell” or, in other words, in a table similar to the following:
y − ∆y y y + ∆y
x − ∆x a10
x a01 a11 a21
x + ∆x a12
This gives the coefficients to will be used to fill in the A matrix for the interior nodes.
b) The boundary condition contributions are added to the right-hand-side vector. Identify the
interior nodes that use boundary values and state the equations used for these nodes.
c) Write a function, (mk_Laplace.m) that constructs the A matrix and the right-hand-side vector
for the discretized Laplace equation. Start with the provided skeleton code, mk_Laplace_skel.m,
and i) enter the coefficients you obtained in parts a) and b), ii) complete the section for the right-
hand-side domain boundary.
d) Let’s now solve the heated plate problem with Nx=39, Ny=31, a=5, b=4 (same values used for
the similar problem in problem set 1) and Nx=19, Ny=15, a=5, b=4. Start with the provided
skeleton script (Heated_Plate_skel.m), and create a Node numbering reference matrix (refer to
the Node_Ordering_Numbering document provided on Stellar). When completed, your own
Heated_Plate.m (based on Heated_Plate_skel.m) uses your mk_Laplace.m of part c) to solve the
heated plate problem at the indicated resolutions. It also calculates the rates of convergence.
[Note, Nx and Ny refer to the number of interior points in the grid. Also, Heated_Plate_skel.m
calls the scripts Plate_Plots.m, formatplot.m and AnalyticHeatedPlate.m that we provide].
Comment on the results. What order of convergence do you obtain? Is this what you expected?
Page 2 of 5
e) OPTIONAL (Bonus): Try setting je = Ny (line 21 of Heated_Plate_skel.m). Do you still get
the same convergence as in part d)? Explain.
Note: Observe that in line 31 of the MATLAB script mk_Laplace_skel.m (that was provided to
you), we initialize a matrix A as
A = spalloc(TotalNodes, TotalNodes, 9*TotalNodes);
This defines a sparse matrix that would have 9 non-zero diagonals. In our particular problem, we
require only 5 non-zero diagonals (part (a)). This was to allow for higher order schemes later
(although hard coding is not an encouraged practice). Moreover, MATLAB allocates less memory
than you define. It will allocate more memory as the computation progresses.
Problem 4 (Modified from Lomax et al, Prob. 3.1-3.2):
a) Derive a third-order finite-difference approximation to a first derivative in the form
∂u 1
=
∂x j ∆x
( a u j−2 + b u j−1 + c u j + d u j+1 )
b) Derive a finite-difference approximation to a first derivative in the form
∂u 1 ∂u
=
∂x j ∆x
( a u j −1 + b u j + c u j +1 ) + d
∂x j −1
c) Compare the leading truncation error terms for a) and b).
d) Assuming all the u values are known, briefly compare the compactness of the two
numerical schemes and explain how one would implement the finite difference schemes
obtained in a) and b) to compute the first derivative field over a finite domain ( x0 ≤ x ≤ x1 ).
Problem 5: Solving a Wave Equation
∂u ∂u
The 1D Sommerfeld wave radiation equation is governed by: +c = 0
∂t ∂x
This linear equation is one of the most studied for the derivation of finite difference schemes. It
corresponds to a constant speed advection. Travelling waves in the form of u ( x, t ) = ei ( kx-ωt ) are
solutions of this equation if ω = c k which implies that the waves travel at constant amplitudes at
fixed phase speed ω / k = c (non-dispersive waves).
a) Discretize this equation using only explicit finite-difference schemes, solving for
uˆ ik +1 = uˆ ( i ∆x, (k + 1) ∆t ) :
i) Use first-order backward difference in space and first-order forward difference in time.
ii) As i), but use second-order central difference in space.
b) Using the two discretization schemes obtained in a), we wish to solve the Sommerfeld
equation for the following conditions. The wave-speed, c, is set to 1 m/s, and the domain is 1 m
long. The total time of interest is 1 s. The initial and boundary conditions are as follows. The
initial condition u( x, 0) of the wave has the following shape:
Page 3 of 5
4( x − 0.25) 0.25 ≤ x ≤ 0.5
u( x,0) = .
0 elsewhere
At the left boundary, a pulse is generated starting every 1/4 of a second. That is, at t = [0, 0.25,
0.5, 0.75, 1] s, a pulse is generated with the following shape:
sin(ω (t − ts )) 0 ≤ t − ts ≤ 0.25
u(0, t ) = ,
0 otherwise
where ω = 4π and ts = [0, 0.25, 0.5, 0.75, 1] s. The duration of each pulse is 0.25 s.
Using MATLAB (or your preferred software), numerically solve for u( x, t ) using 100 nodes in
time (the first node at t=0 and the last node at t=1s) and 100 nodes in space (the leftist node at
x=0 and the rightest node at x=1m):
i) What time step ( ∆t ) and space step ( ∆x ) sizes do these choices correspond to?
ii) Implement and solve using the backward difference discretization in space from a)
iii) Implement and solve using the centered difference discretization in space from a). You can
use backward difference for the rightest node since we don’t have a node to the right of that
boundary node.
Plot the solution at time-step 50 for each case. One of the discretization has issues, why?
c) Using the acceptable discretization from b),
i) Plot the solutions at t = [0, 1/3, 2/3, 1] s (on the same graph) for velocities of c = [0.9, 1,
1.05] (on separate graphs). This will result in a total of 3 graphs, one graph for each
different velocity.
ii) Comment on the results. What happens when the value of c changes? What is the name of
the condition that your numerical scheme needs to satisfy? Two of the three solutions seem
fine, but one of these two does not maintain a key property of exact solutions, why? Hint:
Substitute c = 1 into your discretized equation. To better understand what’s happening,
download Waveanim.m from Stellar. If you save your solutions in a matrix such that
= U [u =( x, t 0),..., u
= ( x, t 1)] , where each u(x,t) is a column vector, then you can run the
file Waveanim(U) to create a movie!
d) If c is increased to 4.061 m/s, what would you do to ensure an acceptable scheme without
changing the total number of nodes? That is, you can change Nx and Nt under the constraint
Nx*Nt=10000.
e) What would happen if c became negative, i.e. c < 0? Would your discretization scheme still be
valid? What about the initial/boundary conditions, could they still be the same or would they
need to be changed?
f) For many realistic fields the background velocity fields (here denoted by c) will not be
constant in the domain of interest. Hence one cannot determine a priori the range of the proper
grid spacing for a stable solution: stability needs to be checked as the code is run and the solution
computed. In this part of the problem, we investigate what happens when the stability criterion is
violated. Let’s assume that the background velocity varies and is equal
= to c A sin(π t ) + 0.5 ,
where A is either 0.6 or 0.8.
Page 4 of 5
i) Implement this change in your code and plot the solution at t = [0, 1/3, 2/3, 1] s, for both
∆t
values of A = [0.6, 0.8]. Also plot the parameter C = c for both cases.
∆x
ii) Comment your results. What do they imply for realistic advective flows, i.e. c = u?
Page 5 of 5