# PS9 (now complete)

```MATH 333: Partial Differential Equations
Problem Set 9, Final version
Due Date: Tues., Nov. 29, 2011
Relevant sources:
• Farlow’s book: Lessons 9, 37–39
• MacCluer’s book: Chapter 3
?44 Show that the Poisson problem with Dirichlet BCs on a bounded domain Ω is stable.
Specifically, suppose that Ω ⊂ Rn is open, bounded and connected, and consider the
two (nearly identical—they both have the same forcing function f ) problems
∆u(x) = f (x),
x ∈ Ω,
subject to
u(x) = g1 (x), for x ∈ ∂Ω,
(1)
∆v(x) = f (x),
x ∈ Ω,
subject to
v(x) = g2 (x), for x ∈ ∂Ω.
(2)
and
If boundary data for the two problems are similar—that is, if
kg1 − g2 k∞ := max |g1 (x) − g2 (x)| : x ∈ ∂Ω
is small—show that the difference in solutions is small throughout Ω.
?45 Set up the BVP corresponding to the thermal equilibrium of a rectangular plate that
is insulated on two of its sides, has 0◦ at its top edge and 100◦ at the bottom edge.
Where do you expect the maximum temperature to be located? What is its value?
Can you find a formula for temperature inside the plate?
?46 [This problem gives a partial answer to the question of what forms harmonic functions
of 2 variables can take.] Find an harmonic function u(x, y) defined on the annulus
1
< kxk < 1 (where x = (x, y)) subject to the constant Dirichlet BCs u = a on kxk = 21
2
and u = b on kxk = 1. You may assume, as seems physically reasonable given
the BCs, that the solution is radially symmetric, so that u = u(r) is a function of
p
r = x2 + y2 alone (independent of θ), and so Laplace’s equation reduces to
∆u =
∂2 u 1 ∂u
+
= 0.
∂r2 r ∂r
Hint: Let v = ur and solve the 1st order ODE for v. Then find u.
MATH 333
Problem Set 9
2
?47 Find a series solution of the heat problem
ut = uxx , 0 < x < 1, t > 0,
subject to


BCs: u(t, 0) = 0,




u(t, 1) = sin t,




 IC:
u(0, x) = 0.
?48 Consider the Poisson problem with Dirichlet BCs in a square region of the plane
∆u = f (x, y),
0 < x < 1, 0 < y < 1,
subject to BCs


u(x, 0) = sin(πx),




u(x, 1) = e−2 sin(πx),




 u(0, y) = 0 = u(1, y).
where f (x, y) = (4 − π2 )e−2y sin(πx).
(a) Employing a finite difference scheme, solve this problem on a grid that uses
N = 4 interior values on the x-axis and M = 4 interior values on the y-axis to
obtain the steady-state temperature distribution. Graph the resulting approximate solution as a surface in 3D. I encourage you to rely heavily on my class
examples which used scripts like psset1.m, psset2.m, psset3.m, psset4.m,
http://www.calvin.edu/˜scofield/courses/m333/materials/octave/
Pay special attention to how a forcing function is implemented in psset4.m
(i.e., the form of its inputs and outputs). Hand in a printout of your code and
the graphs you produce, and send me electronic versions as well.
(b) Demonstrate that the true solution of the problem is u(x, y) = e−2y sin(πx), and
explain why the problem is, therefore, well-posed.
(c) Compare the values of the true solution with those from your approximate
solution in part (a). Among all interior grid points find both the maximum
error and the maximum relative error of the numerical solution.
(d) Redo parts (a) and (c), this time doubling N and M so that they are both 8.
PS9—Final version
MATH 333
Problem Set 9
3
Work with a partner and choose one problem pair from ?49A-B or ?50A-B to do.
?49A In class we considered Poisson’s equation with Dirichlet BCs
−∆u = f,
inside R = (x, y) | 0 < x < a, 0 < y < a ,
subject to u = g on ∂R.
We replaced the PDE with a linear system of difference equations
− u j−1,m − u j+1,m − u j,m−1 − u j,m+1 + 4u j,m = h2 f j,m ,
1 ≤ j ≤ N, 1 ≤ m ≤ M,
(3)
vectorized the unknowns
T
U = u1,1 u2,1 . . . uN,1 u1,2 u2,2 . . . uN,2 . . . u1,M u2,M . . . uN,M ,
and then determined the matrix A such that AU corresponds to the left-hand side
of Equation (3).
(a) Suppose, instead of Dirichlet BCs, we have periodic BCs. That is, as you
approach the right edge of the mesh of points (x j , ym ), you wrap around to the
left side; the top wraps around to the bottom (like in the classic video game
PacMan). For simplicity, assume there are only points (x j , ym ) for j = 1, 2, . . . , N,
m = 1, 2, . . . , M, so that (x1 , ym ) is to the immediate right of (xN , ym ) and (x j , y1 ) is
immediately above (x j , yM ). Determine the form of the matrix A (give a picture)
so that AU is the discrete Laplacian operator on u, taking into account these
periodic BCs. [Note: The size of the correct matrix should be NM rows by NM
columns.]
(b) Write an Octave function that, given inputs N and M, returns the matrix A of part
(a). The .m-file I wrote to generate the matrix A for class is discreteLaplacian.m,
and it actually contains two different ways to construct (my) A.
?49B Obtain a small black-and-white image file (say, something on the order of M = 60
pixels by N = 60 pixels, so NM isn’t horribly large), and place it in your working
directory. I’ve prepared the file testim.png which you may use, but you may substitute your own. (Most standard image formats are supported by Octave.) Read
this file into Octave, convert it to double precision, and then display it using the
commands
image = double ( imread ( ’ t e s t i m . png ’ ) ) / 2 7 0 ;
imshow ( image )
Now add some Gaussian noise to the image and display the result via a command
like:
PS9—Final version
MATH 333
Problem Set 9
4
nImage = image + . 0 5 ∗ randn ( s i z e ( image ) ) ;
figure ( 2 )
imshow ( nImage )
(If you have the ‘clean’ image displayed, the figure() command creates a 2nd figure
window so the two can be viewed side-by-side.) We will use diffusion to “smooth
out” the noise in the image. On a uniform spatial grid with ∆x = ∆y = h, one
discretization of the diffusion equation
ut (t, x, y) = ∆u(t, x, y)
is
u(t, x − h, y) + u(t, x + h, y) + u(t, x, y − h) + u(t, x, y + h) − 4u(t, x, y)
u(t + ∆t, x, y) − u(t, x, y)
=
,
∆t
h2
or
u(t + ∆t, x, y)
= u(t, x, y) +
∆t u(t, x − h, y) + u(t, x + h, y) + u(t, x, y − h) + u(t, x, y + h) − 4u(t, x, y) .
2
h
(4)
Here, consider t to be the current time (so values at time t refer to the current state of
the image, while those at time (t + ∆t) refer to the next state) and, relative to a pixel
at position (x, y), positions (x − h, y), (x + h, y), (x, y − h) and (x, y + h) are neighboring
pixels to the left, right, below and above, respectively.
You can vectorize the noisy image with a command like
U = nImage ( : ) ;
and return it to its original M-by-N shape with
reshape (U, M, N)
(k)
Now, if we call the vectorized form of your current image U , then Equation (4),
which describes the evolution of your image at the local level, can be turned into the
global (entire image at a time) scheme (where we have taken h = 1)
U(k+1) = U(k) + ∆tAU(k) .
Here, A, the matrix you found for the previous exercise, has periodic BCs built into
it.
Assuming U(0) is the starting noisy image, you could allow the image intensity values
to evolve up until, say, time t = 1 in just one step (so U(1) is the resulting image) by
taking ∆t = 1. You could also get to the same time via smaller steps, ∆t = 0.1 for
instance, so that the final image is U(10) .
PS9—Final version
MATH 333
Problem Set 9
5
(a) Implement this global evolution scheme in Octave or Matlab. Here is pseudocode for what you are to do:
1.
2.
3.
4.
Set U to be the vectorized form of the noisy image.
Build your matrix A of appropriate size.
Set the value of dt, and the number of time steps to carry out.
Begin loop
Let U = U + dt*A*U
Plot the current state of the image (reshaped U).
Pause briefly for the viewer to see the result.
End loop
You should hand in a hardcopy of your code and send me an electronic version
as well.
(b) Try out your code, independently altering the number of iterations to carry
out and the time step dt. Comparing your final image to the original ‘clean’
image, find a combination of these two settings that best pleases you in terms
of removing noise but not blurring the image too badly. The code you send for
part (a) should have these settings.
(c) Along with a tendency to become blurred in time, what do you notice about
the evolving image produced by your routine? Explain these observations.
?50A Consider the ordinary differential equation/BVP (a 1-dimensional version of the Poisson problem)
− y00 (x) = f (x),
subject to BCs
y(0) = 0,
y0 (1) = 1.
(5)
Let us subdivide the interval [0, 1] into n equally-spaced subintervals,
0 = x0 < x1 < . . . < xn = 1,
with each
xm − xm−1 = h :=
1
.
n
(a) If we use a centered difference approximation for y00 (x) then, writing ym as an
approximation to the value of y(xm ), derive the finite difference equation
− ym−1 + 2ym − ym+1 = h2 f (xm ) ,
(6)
holding for m = 1, 2, . . . , n − 1.
(b) While equation (6) provides most of the particulars for a finite difference scheme
to approximate the solution of Problem (5), we will not have a complete scheme
until we specify how to handle the Neumann boundary condition at x = 1. Consider two different schemes, based on the following two ways of dealing with
PS9—Final version
MATH 333
Problem Set 9
6
this Neumann condition. In the simpler of the two schemes S1 , we approximate
y0 (1) using a backward difference:
yn − yn−1
= 1.
h
In scheme S2 , we
• imagine there to be a ghost node xn+1 = 1 + h, outside the right end point
(where the Neumann condition occurs) of our interval [0, 1],
• require equation (6) to hold at the right end point xn (i.e., to hold with m = n,
which gives rise to an equation involving the ghost node xn+1 ), and
• introduce the constraint (approximate equation for y0 (1) = 1)
yn+1 − yn−1
= 1.
2h
Schemes S1 and S2 both may be turned into matrix problems A1 v1 = b1 and
A2 v2 = b2 , where v1 = (y1 , y2 , . . . , yn ) and v2 = (y1 , y2 , . . . , yn , yn+1 ) represent
the vector of unknowns. Determine the entries of the matrices A1 , A2 and the
right-hand sides b1 , b2 .
{c} This problem part is optional. Are the matrices A1 , A2 symmetric? positive
definite? (The definition of “the matrix A is positive definite” is that vT Av ≥ 0
for all vectors v of appropriate size, with equality only when v = 0.) If the
answers are not obvious, then you may resort to use of numerical evidence.
Be clear about what you know to be true (from numerical evidence), and what
you only guess at being true. Note: Positive definite matrices are always
nonsingular, making a problem like Av = b uniquely solvable.
(d) Let f (x) = −ex−1 , so that the resulting true solution of (5) is y(x) = e−1 (ex − 1).
Write algorithms to compute finite difference solutions (with this f ) both for
scheme S1 and S2 . Compute the maximum error between true and approximate
solutions (i.e, maximum difference |y(xm ) − ym | taken over all grid points x = xm )
using both schemes at several different choices of h (say, h = 0.1 and h = 0.05, at
the least). What can you say about the order of convergence for each scheme?
?50B (a) Derive an implicit scheme for the following Neumann problem:
ut = uxx , 0 < x < `, t > 0,
subj. to


BCs : ux (t, 0) = α(t), t > 0




ux (t, `) = β(t)




 IC :
u(0, x) = f (x), 0 < x < `
PS9—Final version











(7)
MATH 333
Problem Set 9
7
(b) Use your scheme to solve Problem (7) in the case where ` = 4, α(t) = 0,
β(t) = 100(1 − e−t ), and



 100, if 1 ≤ x ≤ 2,
f (x) = 

 0,
otherwise.
PS9—Final version
```