# Lecture 6 18.086

```Lecture 6
18.086
Info
•
Project proposals…!
Leapfrog scheme
•
Easiest numerical scheme for 2nd order problem: Leapfrog n t)
Notation: Uj,n = U (j x,CFL
criterion for Leapfrog scheme
Uj,n+1
•
2Uj,n + Uj,n 1 !&quot; 2!&quot;Uj+1,n
u
=0
Equation: =+ c
2
!t
!x
t
Stability: |r| ≤ 1 (equiv. CFL condition!)
Lecture
t
n+1!
Accuracy: 2nd order
n-2!
with
physical domain
of dependence
n!
n-1!
•
2Uj,n +nU
j 1,n
+1
= !in –1 – &quot; (!in+1 # !in–1 )
Scheme: !i
x2
numerical domain
of dependence
unstable
|uΔt/Δx|
&gt;1
c
stable
|uΔt/Δx|
≤1
c
Lecture / see Mathematica
notebook leapfrog_stability.nb
i-3!
i-2!
i-1!
i!
i+1!
i+2!
i+3!
x
Accuracy of FD schemes: Alternative way
(using modified equations)
•
Approach is general and gives GLOBAL error directly (not local error)
Using wave equation and leapfrog as an example:
•
Uj,n+1
2Uj,n + Uj,n
t2
1
=c
2 Uj+1,n
2Uj,n + Uj
x2
1,n
•
Plug in analytical u and expand in Taylor on LHS and RHS of FD equation E.g.:
1
uj,n+1 = u(x, t) + ux (x, t) t + utt (x, t) t2 + O( t3 )
2
•
Simplifying LHS and RHS gives
1
1
2
2
utt +
t utttt + . . . = c (uxx +
x2 uxxxx + . . .)
12
12
•
2
4
u
=
c
u
=
c
uxxxx , so the global error is
Note that tttt
ttxx
1 ⇥ 2 4
t c
12
x
2
⇤
uxxxx
=&gt; p=2 in time and space
Staggered grids
•
•
•
Remember:
@
Equivalent 1st order problem:
@t
with v1 = ut , v2 = cux
✓
v1
v2
◆
=
✓
0 c
c 0
◆
@
@x
✓
There are a number of “physical” wave equations that are of this form,
most importantly the Maxwell equations of electrodynamics (in vacuum):
Leads to a 1st order
system as above!
v1
v2
◆
correct typo in one-way LF scheme!
We could try this….
•
Discretize 1st order problem:
with 1st order “leapfrog”
@
@t
✓
v
w
◆
=
✓
0
c
c
0
◆
@
@x
✓
v
w
◆
This would give us 2nd order accuracy, because we use two centered
differences for space and time in leapfrog!
Uj,n+1 Uj,n
Uj+1,n Uj
=c
2 t
2 x
•
1way wave eq leapfrog:
•
1-way wave eq. leapfrog: dispersion-free |G|=1 for all k, as long as CFL condition r&lt;=1
•
Here:
Vj,n+1 Vj,n
Wj+1,n Wj 1,n
=c
2 t
2 x
Wj,n+1 Wj,n
Vj+1,n Vj 1,n
=c
2 t
2 x
1,n
Lecture: interesting
numerical “dispersion”!
1way-Leapfrog
•
“Coupled” equations decouple in current leapfrog formulation!
Diffusion and Advection (6.5)
•
The heat equation is another famous PDE
ut = Duxx
•
D is the diffusion constant (units length^2/time)
Dk2 t
•
Growth factor: G(k, t) = e
•
Solution to IV u(x,0) = δ(x) is given by:
x2
1
u(x, t) = p
e 4Dt
4⇡Dt
Numerical scheme (FD)
•
Heat equation is dissipative, so why not try Forward Euler:
Uj,n+1
Uj,n
t
•
•
•
•
=
Uj+1,n
2Uj,n + Uj
x2
1,n
Expected accuracy: O(Δt) in time, O(Δx2) in space.
t
1
Stability in the usual way gives R =

2
x
2
We can use previous ODE methods using the old method of lines, of course…
-2
Or implicit methods (see book, 6.5). Notice that matrix contains O(Δx ) terms and is stiff!
Incorporating boundary
conditions into FD matrices
•
Writing the heat equation using method of lines (with centered differences in x),
we have
position j=i
~ut = A~u
•
Away from boundaries, Ai = (0, . . . ,
•
Boundary conditions determine values of A near boundaries, e.g.
0
B
B
B
B
B
B
@
0
1
0
0
0
0
0
2
1
0
0
0
0
1
2
1
0
0
0
0
1
2
1
0
0
0
0
1
2
0
0
0
0
0
1
0
10
u0
u1
u3
...
CB
CB
CB
CB
CB
CB
A @ uN 1
uN
1
C
C
C
C
C
C
A
1, 2, 1, 0, . . . , 0)
BCs: u(0,t)=v1
u(X,t)=v2
see book, 1.2
```