18.303 Problem Set 9 Solutions Problem 1: (10+10+10)

advertisement
18.303 Problem Set 9 Solutions
Problem 1: (10+10+10)
n+1
n
u
−u
is centered around
(a) Exactly as in class, v should be discretized at timesteps (n + 0.5)∆t so that ∂u
∂t ≈
∆t
∂v
vn+0.5 −vn−0.5
n+0.5
n
v
, and so that ∂t ≈
is
centered
around
u
.
Also
as
in
class,
v
should
be discretized
x
∆t
at (mx + 0.5)∆x so that ∂u/∂x is centered around it, but it should be at integer my for the same reason.
Conversely, vy should be discretized at (mx ∆x, [my + 0.5]∆y) so that ∂u/∂y is centered around it. These lead
to the following difference equations where everythign is centered in both space and time:
n+0.5
n+0.5
n+0.5
n+0.5
n
vx;m
− vx;m
vy;m
− vy;m
un+1
∂vx
∂vy
∂u
mx ,my − umx ,my
x +0.5,my
x −0.5,my
x ,my +0.5
x ,my −0.5
≈
=
+
≈
+
,
∂t
∆t
∆x
∆y
∂x
∂y
n+0.5
n−0.5
vx;m
− vx;m
unmx +1,my − unmx ,my
∂vx
∂u
x +0.5,my
x +0.5,my
≈
=
≈
∂t
∆t
∆x
∂x
n+0.5
n−0.5
vy;m
− vy;m
unmx ,my +1 − unmx ,my
∂vy
∂u
x ,my +0.5
x ,my +0.5
≈
=
≈
.
∂t
∆t
∆y
∂y
(b) Plugging in the difference equations, we obtain:
n
n−1
un+1
∂2u
mx ,my − 2umx ,my + umx ,my
≈
=
∂t2
∆t2
n+0.5
n+0.5
−vx;m
vx;m
x +0.5,my
x −0.5,my
∆x
=
∆t
−
∆t
n−1
un
mx ,my −umx ,my
n+0.5
n+0.5
vy;m
−vy;m
x ,my +0.5
x ,my −0.5
∆y
∆t
−
n−0.5
n−0.5
vx;m
−vx;m
x +0.5,my
x −0.5,my
∆x
+
n−0.5
n−0.5
vy;m
−vy;m
x ,my +0.5
x ,my −0.5
∆y
∆t
n−0.5
n+0.5
−vx;m
vx;m
x +0.5,my
x +0.5,my
n+0.5
n−0.5
vx;m
−0.5,my −vx;mx −0.5,my
∆t
∆t
=
=
+
n+1
um
−un
mx ,my
x ,my
unmx +1,my − 2unmx ,my
∆x2
x
−
∆x
+ unmx −1,my
+
n−0.5
n+0.5
−vy;m
vy;m
x ,my +0.5
x ,my +0.5
n+0.5
n−0.5
vy;m
,my −0.5 −vy;mx ,my −0.5
∆t
∆t
+
unmx ,my +1 − 2unmx ,my + unmx ,my −1
∆y 2
x
−
∆y
2
∂ u ∂2u
≈
+ 2,
∂x2
∂y
which is just the sum of center differences in x and y, as one might have hoped.
(c) Performing a Von-Neumann analysis, we can use the fact as in class that un+1 − 2un + un−1 = −2 sin2 (ω∆t/2),
and similarly for other center differences, obtaining:
−2 sin2 (ω∆t/2)
−2 sin2 (kx ∆x/2) −2 sin2 (ky ∆y/2)
=
+
,
∆t2
∆x2
∆y 2
i.e. that
2
2
∆t2
−1 ∆t
2
2
ω=
sin
sin (kx ∆x/2) +
sin (ky ∆y/2) .
∆t
∆x2
∆y 2
In order to be stable, i.e to have real ω, the argument [· · · ] of the sin−1 must be ≤ 1 for all kx and ky . The
biggest the [· · · ] term can be is when the sin2 terms are both = 1, i.e when kx ∆x = π and ky ∆y = π. This gives
the condition:
∆t2
∆t2
+
≤ 1,
∆x2
∆y 2
or
1
∆t ≤ q
.
1
1
∆x2 + ∆y 2
1
1
t=0
0.8
0.1
0.2
0.3
0.4
0.6
0.4
u(x,t)
0.2
0
−0.2
−0.4
−0.6
0.7
−0.8
−1
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.6
0.9
1
x
Figure 1: Wave propagation of a Gaussian pulse on x ∈ [0, L] with c = 1 and Dirichlet (u = 0) boundary conditions,
showing u(x, t) for a few times t. The pulse bounces off the boundaries with the opposite sign.
Problem 2: (15+10)
(a) We will discretize u at M points u1 , u2 , u3 , . . . , uM with um corresponding to x = m∆x and the boundary conditions u0 = uM +1 = 0. Thus, ∆x = L/(M + 1), similar to pset 1 and different from the periodic boundary
conditions case: we now make M +1 correspond to x = L, not M , and no longer identify x = L with x = 0. Given
these points, plus the boundary conditions, we discretize v at M + 1 points v0.5 , v1.5 , . . . vM +0.5 corresponding
to (m + 0.5)∆x, so unlike the periodic case the u and v vectors have different lengths. To do the timestepping,
we need to compute um+1 − um to update vm+0.5 , which is accomplished by diff([0;u;0]), where we have
prepended and appended 0’s to u to give the boundary conditions. To do the timestepping of u, we need to
compute vm+0.5 − vm−0.5 to update um , which is just accomplished by diff(v) since the M + 1 vm+0.5 values
already bracket the um values in space, and there is no need for an explicit boundary condition on v. The
resulting code is given below, with the important changes marked with % CHANGED comments.
The graph of the wave animation for a few timesteps is shown in figure 1. What happens is that, when the
pulse hits the Dirichlet boundary, it reflects back with the opposite sign.
(b) One possible solution is
u(x, t) = f (x − ct) − f (−x − ct).
The first term f (x − ct) is a right-going wave, while the second term −f (−x − ct) is a left-going wave with the
opposite sign. This satisfies the boundary condition, since u(0, t) = f (−ct) − f (−ct) = 0. It also clearly satisfies
the wave equation, since both terms are d’Alembert solutions.
If f (x) was a pulse, starting somewhere at x < 0, then −f (−x) would be a negative pulse somewhere at
x > 0. As t increases, eventually the f (x − ct) pulse would reach x > 0 and the −f (−x − ct) pulse would reach
x < 0. If we only looked in Ω, i.e. only in x < 0, at this point it would appear that the initial pulse had reflected
off of the x = 0 boundary and had turned into a left-going pulse with the opposite sign. This exactly corresponds
2
to what we observed in part (a).
function [u,v,x] = animwave0(f, M, L, ct, cdtdx)
dx = L / (M+1); % CHANGED: point M+1 now corresponds to L
x = [1:M]’*dx; % CHANGED: don’t store u_0 and u_{M+1} ( = 0 )
u = feval(f, x);
umax = max(abs(u)) * 1.2; umin = -umax;
x1 = [0:M]’*dx; % CHANGED: v is at M+1 points x1 + 0.5*dx
v = -feval(f, x1 + 0.5*dx * (1 + cdtdx)); % CHANGED: use x1
nt = round(ct / (cdtdx * dx));
hold off;
for i = 1:nt
plot(x, u);
axis([0,L,umin,umax]);
legend(sprintf(’ct = %g’, (i-1)*cdtdx*dx));
drawnow;
v = v + cdtdx * diff([0;u;0]); % CHANGED: append u_0 = u_{M+1} = 0
u = u + cdtdx * diff(v); % CHANGED: no need for v boundary terms
end
3
Download