Home
Explore
Exams
Login
Get started
Home
Numerical Methods 2 Test
Numerical Methods 2 Test
0.0
(0)
Rate it
Studied by 0 people
Call Kai
Learn
Practice Test
Spaced Repetition
Match
Flashcards
Knowt Play
Browsing
1/54
There are no tags or description
Looks like no tags are added yet.
55 Terms
View all (55)
Star these 55
1
New cards
What does 'n-th order accurate' mean?
Error
โ
h
n
\propto h^n
โ
h
n
. Halve
h
h
h
and the error drops by
2
n
2^n
2
n
: 1st order halves it, 2nd order quarters it, 4th order divides it by 16. [In notes: Note 1]
2
New cards
Forward and backward difference for
f
โฒ
f'
f
โฒ
, and their order?
Forward
f
j
+
1
โ
f
j
h
\frac{f_{j+1}-f_j}{h}
h
f
j
+
1
โ
โ
f
j
โ
โ
, backward
f
j
โ
f
j
โ
1
h
\frac{f_j-f_{j-1}}{h}
h
f
j
โ
โ
f
j
โ
1
โ
โ
. Both 1st order,
O
(
h
)
O(h)
O
(
h
)
. [In notes: Note 1]
3
New cards
Central difference for
f
โฒ
f'
f
โฒ
, and its order?
f
j
+
1
โ
f
j
โ
1
2
h
\frac{f_{j+1}-f_{j-1}}{2h}
2
h
f
j
+
1
โ
โ
f
j
โ
1
โ
โ
. 2nd order,
O
(
h
2
)
O(h^2)
O
(
h
2
)
. [In notes: Note 1]
4
New cards
Central difference for
f
โฒ
โฒ
f''
f
โฒโฒ
, and its order?
f
j
+
1
โ
2
f
j
+
f
j
โ
1
h
2
\frac{f_{j+1}-2f_j+f_{j-1}}{h^2}
h
2
f
j
+
1
โ
โ
2
f
j
โ
+
f
j
โ
1
โ
โ
. 2nd order. Exact (zero error) for polynomials up to
x
3
x^3
x
3
. [In notes: Note 1]
5
New cards
Three-point backward difference for
f
โฒ
f'
f
โฒ
?
3
f
j
โ
4
f
j
โ
1
+
f
j
โ
2
2
h
\frac{3f_j-4f_{j-1}+f_{j-2}}{2h}
2
h
3
f
j
โ
โ
4
f
j
โ
1
โ
+
f
j
โ
2
โ
โ
. 2nd order. Lesson: the number of points is NOT the order. [NOT in notes: memorise]
6
New cards
Quick way to find the order of any finite difference formula?
Apply it at
x
=
0
x=0
x
=
0
to
x
2
x^2
x
2
, then
x
3
x^3
x
3
, then
x
4
x^4
x
4
... The first power that gives a wrong (non-zero) answer is order + 1. Or compare errors at
h
h
h
and
h
/
2
h/2
h
/2
. [NOT in notes: memorise]
7
New cards
Why is the error the first dropped Taylor term?
Taylor writes
f
f
f
as powers of
h
h
h
, each much smaller than the last. A formula keeps some terms, so the error is roughly the first term left over. Its power of
h
h
h
is the order. [In notes: Note 1 (truncation error)]
8
New cards
Modified wavenumber of the central difference for
d
d
x
\frac{d}{dx}
d
x
d
โ
?
Exact derivative of
e
i
ฮบ
x
e^{i\kappa x}
e
iฮบ
x
uses
ฮบ
\kappa
ฮบ
; the scheme behaves as if it were
ฮบ
โ
=
sin
โก
(
ฮบ
h
)
h
\kappa^*=\frac{\sin(\kappa h)}{h}
ฮบ
โ
=
h
s
i
n
(
ฮบh
)
โ
. Compare
ฮบ
โ
\kappa^*
ฮบ
โ
with
ฮบ
\kappa
ฮบ
to judge accuracy. [In notes: Note 1 p.6-7, Note 6 p.34]
9
New cards
What does
ฮบ
โ
=
sin
โก
(
ฮบ
h
)
h
\kappa^*=\frac{\sin(\kappa h)}{h}
ฮบ
โ
=
h
s
i
n
(
ฮบh
)
โ
tell you?
Small
ฮบ
h
\kappa h
ฮบh
(long waves):
ฮบ
โ
โ
ฮบ
\kappa^*\approx\kappa
ฮบ
โ
โ
ฮบ
, accurate. Larger
ฮบ
h
\kappa h
ฮบh
: always underestimates. At
ฮบ
h
=
ฯ
\kappa h=\pi
ฮบh
=
ฯ
:
ฮบ
โ
=
0
\kappa^*=0
ฮบ
โ
=
0
, zero derivative. Expansion
ฮบ
โ
=
ฮบ
โ
ฮบ
3
h
2
6
\kappa^*=\kappa-\frac{\kappa^3h^2}{6}
ฮบ
โ
=
ฮบ
โ
6
ฮบ
3
h
2
โ
(the expansion is not in the notes). [Partly in notes: formula and 'small k good, large k bad' in Note 1 p.7]
10
New cards
The model problem and the amplification factor
ฯ
\sigma
ฯ
?
Apply the method to
y
โฒ
=
ฮป
y
y'=\lambda y
y
โฒ
=
ฮป
y
; each step gives
y
n
+
1
=
ฯ
y
n
y_{n+1}=\sigma y_n
y
n
+
1
โ
=
ฯ
y
n
โ
, so
y
n
=
ฯ
n
y
0
y_n=\sigma^n y_0
y
n
โ
=
ฯ
n
y
0
โ
. Stable when
โฃ
ฯ
โฃ
โค
1
|\sigma|\le 1
โฃ
ฯ
โฃ
โค
1
. [In notes: Note 2]
11
New cards
Stable or not:
ฯ
=
โ
0.6
\sigma=-0.6
ฯ
=
โ
0.6
?
ฯ
=
โ
1.4
\sigma=-1.4
ฯ
=
โ
1.4
?
Judge the SIZE, not the sign.
โฃ
โ
0.6
โฃ
=
0.6
โค
1
|-0.6|=0.6\le1
โฃ
โ
0.6โฃ
=
0.6
โค
1
: stable (flips sign each step while shrinking).
โฃ
โ
1.4
โฃ
=
1.4
>
1
|-1.4|=1.4>1
โฃ
โ
1.4โฃ
=
1.4
>
1
: unstable. [In notes: Note 2]
12
New cards
Explicit Euler:
ฯ
\sigma
ฯ
and step limit (real
ฮป
<
0
\lambda\lt0
ฮป
<
0
)?
ฯ
=
1
+
h
ฮป
\sigma=1+h\lambda
ฯ
=
1
+
hฮป
. Stable for
โ
2
โค
h
ฮป
โค
0
-2\le h\lambda\le0
โ
2
โค
hฮป
โค
0
, so
h
โค
2
โฃ
ฮป
โฃ
h\le\frac{2}{|\lambda|}
h
โค
โฃ
ฮป
โฃ
2
โ
. Remember the 1. Dividing by negative
ฮป
\lambda
ฮป
flips the inequality. [In notes: Note 2]
13
New cards
Explicit Euler with complex
ฮป
=
ฮป
R
+
i
ฮป
I
\lambda=\lambda_R+i\lambda_I
ฮป
=
ฮป
R
โ
+
i
ฮป
I
โ
?
โฃ
ฯ
โฃ
2
=
(
1
+
h
ฮป
R
)
2
+
(
h
ฮป
I
)
2
|\sigma|^2=(1+h\lambda_R)^2+(h\lambda_I)^2
โฃ
ฯ
โฃ
2
=
(
1
+
h
ฮป
R
โ
)
2
+
(
h
ฮป
I
โ
)
2
. Stable region: circle of radius 1 centred at
โ
1
-1
โ
1
. Purely imaginary
ฮป
\lambda
ฮป
:
โฃ
ฯ
โฃ
=
1
+
h
2
ฮป
I
2
>
1
|\sigma|=\sqrt{1+h^2\lambda_I^2}>1
โฃ
ฯ
โฃ
=
1
+
h
2
ฮป
I
2
โ
โ
>
1
, always unstable. [In notes: Note 2]
14
New cards
Size of a complex number / fraction?
โฃ
a
+
b
i
โฃ
=
a
2
+
b
2
|a+bi|=\sqrt{a^2+b^2}
โฃ
a
+
bi
โฃ
=
a
2
+
b
2
โ
. For a fraction: size of top divided by size of bottom. [In notes: Note 2]
15
New cards
Implicit (backward) Euler: update and
ฯ
\sigma
ฯ
?
y
n
+
1
=
y
n
+
h
f
(
y
n
+
1
,
t
n
+
1
)
y_{n+1}=y_n+hf(y_{n+1},t_{n+1})
y
n
+
1
โ
=
y
n
โ
+
h
f
(
y
n
+
1
โ
,
t
n
+
1
โ
)
. For the model problem
ฯ
=
1
1
โ
h
ฮป
\sigma=\frac{1}{1-h\lambda}
ฯ
=
1
โ
hฮป
1
โ
. Unconditionally stable for
ฮป
<
0
\lambda\lt0
ฮป
<
0
;
ฯ
โ
0
\sigma\to0
ฯ
โ
0
for big
โฃ
h
ฮป
โฃ
|h\lambda|
โฃ
hฮป
โฃ
(kills fast decay). 1st order. [In notes: Note 3 p.13]
16
New cards
Trapezoidal method: update and
ฯ
\sigma
ฯ
?
y
n
+
1
=
y
n
+
h
2
(
f
n
+
f
n
+
1
)
y_{n+1}=y_n+\frac{h}{2}\left(f_n+f_{n+1}\right)
y
n
+
1
โ
=
y
n
โ
+
2
h
โ
(
f
n
โ
+
f
n
+
1
โ
)
.
ฯ
=
1
+
h
ฮป
/
2
1
โ
h
ฮป
/
2
\sigma=\frac{1+h\lambda/2}{1-h\lambda/2}
ฯ
=
1
โ
hฮป
/2
1
+
hฮป
/2
โ
. 2nd order. [In notes: Note 3 p.15-16]
17
New cards
Trapezoidal stability region?
The whole left half-plane
R
e
(
h
ฮป
)
โค
0
\mathrm{Re}(h\lambda)\le0
Re
(
hฮป
)
โค
0
(A-stable). On the imaginary axis
โฃ
ฯ
โฃ
=
1
|\sigma|=1
โฃ
ฯ
โฃ
=
1
exactly. For very negative
h
ฮป
h\lambda
hฮป
,
ฯ
โ
โ
1
\sigma\to-1
ฯ
โ
โ
1
: stable but oscillates. [In notes: Note 3 p.16 ('unconditionally stable')]
18
New cards
RK2
ฯ
\sigma
ฯ
and step limit?
ฯ
=
1
+
h
ฮป
+
(
h
ฮป
)
2
2
\sigma=1+h\lambda+\frac{(h\lambda)^2}{2}
ฯ
=
1
+
hฮป
+
2
(
hฮป
)
2
โ
. Real axis limit
h
ฮป
โฅ
โ
2
h\lambda\ge-2
hฮป
โฅ
โ
2
. 2nd order. [In notes: Note 3 p.18]
19
New cards
RK4
ฯ
\sigma
ฯ
and step limit?
ฯ
=
1
+
h
ฮป
+
(
h
ฮป
)
2
2
+
(
h
ฮป
)
3
6
+
(
h
ฮป
)
4
24
\sigma=1+h\lambda+\frac{(h\lambda)^2}{2}+\frac{(h\lambda)^3}{6}+\frac{(h\lambda)^4}{24}
ฯ
=
1
+
hฮป
+
2
(
hฮป
)
2
โ
+
6
(
hฮป
)
3
โ
+
24
(
hฮป
)
4
โ
. Real axis limit
h
ฮป
โฅ
โ
2.79
h\lambda\ge-2.79
hฮป
โฅ
โ
2.79
. 4th order. [Partly in notes: RK4 steps in Note 3 p.18; sigma and limit NOT]
20
New cards
Why does every explicit method have a step limit?
Its
ฯ
\sigma
ฯ
is a polynomial in
h
ฮป
h\lambda
hฮป
; for big negative
h
ฮป
h\lambda
hฮป
the top power takes over and
โฃ
ฯ
โฃ
|\sigma|
โฃ
ฯ
โฃ
blows up. Implicit methods have
ฯ
\sigma
ฯ
as a fraction, which can stay small. [NOT in notes: memorise]
21
New cards
Explicit vs implicit?
Explicit: next
y
y
y
straight from known values (Euler, RK2, RK4). Implicit: next
y
y
y
on both sides, solve for it (backward Euler, trapezoidal). Implicit vs explicit decides stability, not accuracy. [In notes: Note 3]
22
New cards
Global order of each ODE method?
Explicit Euler 1, implicit Euler 1, trapezoidal 2, RK2 2, RK4 4. Euler's per-step error is
O
(
h
2
)
O(h^2)
O
(
h
2
)
but over
T
h
\frac{T}{h}
h
T
โ
steps it becomes
O
(
h
)
O(h)
O
(
h
)
. [In notes: Notes 2-3]
23
New cards
Euler by hand when
f
f
f
is not
ฮป
y
\lambda y
ฮป
y
?
No
ฯ
\sigma
ฯ
shortcut. Step:
y
n
+
1
=
y
n
+
h
f
(
y
n
,
t
n
)
y_{n+1}=y_n+hf(y_n,t_n)
y
n
+
1
โ
=
y
n
โ
+
h
f
(
y
n
โ
,
t
n
โ
)
with
t
n
t_n
t
n
โ
(start of the step). Number of steps
=
T
h
=\frac{T}{h}
=
h
T
โ
; the last step uses
t
=
T
โ
h
t=T-h
t
=
T
โ
h
. Recompute the slope every step. [In notes: Note 2]
24
New cards
'Use MATLAB ode45' questions?
ode45 is an accurate adaptive RK45 solver, so its answer equals the exact solution to 4 d.p. Solve exactly if you can. [NOT in notes: memorise]
25
New cards
What is a stiff problem?
Eigenvalues of very different size, e.g.
ฮป
=
โ
1
\lambda=-1
ฮป
=
โ
1
and
โ
1000
-1000
โ
1000
. The fast part dies almost at once, but explicit methods still need
h
โค
2
1000
h\le\frac{2}{1000}
h
โค
1000
2
โ
to stay stable. [In notes: Note 4 p.21-22]
26
New cards
Best method for stiff problems, and why?
Implicit Euler: no step limit, and
ฯ
=
1
1
โ
h
ฮป
โ
0
\sigma=\frac{1}{1-h\lambda}\to0
ฯ
=
1
โ
hฮป
1
โ
โ
0
crushes the fast part, so
h
h
h
is picked for the slow part. Trapezoidal is stable too but oscillates (
ฯ
โ
โ
1
\sigma\to-1
ฯ
โ
โ
1
), so it isn't always better. [In notes: Note 4 p.22]
27
New cards
Two ways to solve a BVP
y
โฒ
โฒ
=
f
y''=f
y
โฒโฒ
=
f
with
y
(
a
)
,
y
(
b
)
y(a),y(b)
y
(
a
)
,
y
(
b
)
given?
Shooting: guess the missing
y
โฒ
(
a
)
y'(a)
y
โฒ
(
a
)
, march as an IVP, check
y
(
b
)
y(b)
y
(
b
)
, improve the guess (secant). Direct: finite differences at every grid point, solve all the equations together. [In notes: Note 4 p.23]
28
New cards
Direct method,
N
N
N
subintervals: how many unknowns?
N
+
1
N+1
N
+
1
grid points, ends known from the BCs, so
N
โ
1
N-1
N
โ
1
unknowns and
N
โ
1
N-1
N
โ
1
equations (one per inside point). [NOT in notes: memorise]
29
New cards
Shortcut when
y
โฒ
โฒ
=
constant
y''=\text{constant}
y
โฒโฒ
=
constant
?
Then
y
y
y
is a quadratic and the central formula is exact, so the finite difference answer = exact answer. Integrate twice and apply the BCs. [NOT in notes: memorise]
30
New cards
Linear vs non-linear BVP?
Linear:
y
y
y
and its derivatives only to power 1 (e.g.
y
โฒ
โฒ
=
3
y
+
x
y''=3y+x
y
โฒโฒ
=
3
y
+
x
): one solution, secant hits it in one go. Non-linear (e.g.
y
โฒ
โฒ
=
โ
y
2
y''=-y^2
y
โฒโฒ
=
โ
y
2
): may have 0 or several solutions; shooting needs a good first guess. [NOT in notes: memorise]
31
New cards
Secant method for shooting?
Straight line through two (guess, end value) points, read off the guess giving the target
B
B
B
:
v
3
=
v
2
+
(
B
โ
u
2
)
v
1
โ
v
2
u
1
โ
u
2
v_3=v_2+(B-u_2)\frac{v_1-v_2}{u_1-u_2}
v
3
โ
=
v
2
โ
+
(
B
โ
u
2
โ
)
u
1
โ
โ
u
2
โ
v
1
โ
โ
v
2
โ
โ
. Only track the component that changes. [In notes: Note 5 p.25]
32
New cards
Notation
u
i
n
u_i^n
u
i
n
โ
?
i
i
i
= grid point in space,
n
n
n
= time level (a label, not a power).
u
i
+
1
n
u_{i+1}^n
u
i
+
1
n
โ
: next point right;
u
i
n
+
1
u_i^{n+1}
u
i
n
+
1
โ
: next time step. [In notes: Notes 5-6]
33
New cards
Semi-discretisation (method of lines)?
Discretise space only, keep time continuous, giving one ODE per grid point. Heat equation:
d
u
j
d
t
=
ฮฑ
ฮ
x
2
(
u
j
+
1
โ
2
u
j
+
u
j
โ
1
)
\frac{du_j}{dt}=\frac{\alpha}{\Delta x^2}\left(u_{j+1}-2u_j+u_{j-1}\right)
d
t
d
u
j
โ
โ
=
ฮ
x
2
ฮฑ
โ
(
u
j
+
1
โ
โ
2
u
j
โ
+
u
j
โ
1
โ
)
. Then march with any ODE method. [In notes: Note 5 p.26-29]
34
New cards
FTCS update for the heat equation
u
t
=
ฮฑ
u
x
x
u_t=\alpha u_{xx}
u
t
โ
=
ฮฑ
u
xx
โ
?
u
i
n
+
1
=
u
i
n
+
ฮฑ
ฮ
t
ฮ
x
2
(
u
i
+
1
n
โ
2
u
i
n
+
u
i
โ
1
n
)
u_i^{n+1}=u_i^n+\frac{\alpha\Delta t}{\Delta x^2}\left(u_{i+1}^n-2u_i^n+u_{i-1}^n\right)
u
i
n
+
1
โ
=
u
i
n
โ
+
ฮ
x
2
ฮฑ
ฮ
t
โ
(
u
i
+
1
n
โ
โ
2
u
i
n
โ
+
u
i
โ
1
n
โ
)
. All of the bracket at time
n
n
n
.
ฮ
t
\Delta t
ฮ
t
is only in the update, not in the semi-discrete ODE. [In notes: Note 5 (ODE) + Euler step]
35
New cards
FTCS stability limit, 1D heat equation?
ฮ
t
โค
ฮ
x
2
2
ฮฑ
\Delta t\le\frac{\Delta x^2}{2\alpha}
ฮ
t
โค
2
ฮฑ
ฮ
x
2
โ
. Smaller
ฮ
x
\Delta x
ฮ
x
makes it stricter (halve
ฮ
x
\Delta x
ฮ
x
, quarter
ฮ
t
\Delta t
ฮ
t
). [In notes: Note 5 p.29, Note 6 p.33]
36
New cards
Explicit stability limit, 2D heat equation (
ฮ
x
=
ฮ
y
\Delta x=\Delta y
ฮ
x
=
ฮ
y
)?
ฮ
t
โค
ฮ
x
2
4
ฮฑ
\Delta t\le\frac{\Delta x^2}{4\alpha}
ฮ
t
โค
4
ฮฑ
ฮ
x
2
โ
. General:
ฮ
t
โค
1
2
ฮฑ
(
1
ฮ
x
2
+
1
ฮ
y
2
)
\Delta t\le\frac{1}{2\alpha\left(\frac{1}{\Delta x^2}+\frac{1}{\Delta y^2}\right)}
ฮ
t
โค
2
ฮฑ
(
ฮ
x
2
1
โ
+
ฮ
y
2
1
โ
)
1
โ
. [NOT in notes: memorise]
37
New cards
Semi-discrete
ฮป
\lambda
ฮป
for heat vs advection?
Heat:
ฮป
=
โ
ฮฑ
(
k
โฒ
)
2
\lambda=-\alpha(k')^2
ฮป
=
โ
ฮฑ
(
k
โฒ
)
2
, real and negative, so Euler has a step limit. Advection:
ฮป
=
โ
i
c
k
โฒ
\lambda=-ick'
ฮป
=
โ
i
c
k
โฒ
, purely imaginary. [In notes: Note 6 p.32-34]
38
New cards
FTCS on the advection equation
u
t
+
c
u
x
=
0
u_t+cu_x=0
u
t
โ
+
c
u
x
โ
=
0
?
Unstable for every
ฮ
t
\Delta t
ฮ
t
:
ฮป
\lambda
ฮป
is purely imaginary and explicit Euler gives
โฃ
ฯ
โฃ
=
1
+
h
2
ฮป
I
2
>
1
|\sigma|=\sqrt{1+h^2\lambda_I^2}>1
โฃ
ฯ
โฃ
=
1
+
h
2
ฮป
I
2
โ
โ
>
1
. [Partly in notes: lambda in Note 6 p.34; 'always unstable' not stated]
39
New cards
Crank-Nicolson for the heat equation?
Trapezoidal in time + central in space. Unconditionally stable, so
ฮ
t
\Delta t
ฮ
t
can exceed the explicit limit. For large
ฮฑ
ฮ
t
ฮ
x
2
\frac{\alpha\Delta t}{\Delta x^2}
ฮ
x
2
ฮฑ
ฮ
t
โ
,
G
โ
โ
1
G\to-1
G
โ
โ
1
(oscillations). [In notes: Note 6 p.35-36]
40
New cards
Overall accuracy of a PDE scheme like FTCS?
FTCS: 1st order in time, 2nd order in space. Overall limited by the lowest order, and shrinking
ฮ
x
\Delta x
ฮ
x
alone won't help if the time error dominates. [NOT in notes: memorise]
41
New cards
4th order central difference for
f
โฒ
f'
f
โฒ
?
f
j
โ
2
โ
8
f
j
โ
1
+
8
f
j
+
1
โ
f
j
+
2
12
h
\frac{f_{j-2}-8f_{j-1}+8f_{j+1}-f_{j+2}}{12h}
12
h
f
j
โ
2
โ
โ
8
f
j
โ
1
โ
+
8
f
j
+
1
โ
โ
f
j
+
2
โ
โ
, error
O
(
h
4
)
O(h^4)
O
(
h
4
)
. Uses 2 points each side of
x
j
x_j
x
j
โ
(not
f
j
f_j
f
j
โ
itself). The notes print the last term as
f
j
โ
2
f_{j-2}
f
j
โ
2
โ
: it should be
f
j
+
2
f_{j+2}
f
j
+
2
โ
. [In notes: Note 1 p.5 (with typo)]
42
New cards
Linearising a non-linear ODE: what is
ฮป
\lambda
ฮป
?
ฮป
=
โ
f
โ
y
\lambda=\frac{\partial f}{\partial y}
ฮป
=
โ
y
โ
f
โ
at the given
(
y
0
,
t
0
)
(y_0,t_0)
(
y
0
โ
,
t
0
โ
)
. E.g.
f
=
y
2
โ
t
f=y^2-t
f
=
y
2
โ
t
at
y
0
=
โ
2
y_0=-2
y
0
โ
=
โ
2
:
ฮป
=
2
y
0
=
โ
4
\lambda=2y_0=-4
ฮป
=
2
y
0
โ
=
โ
4
. Terms without
y
y
y
go into the ignored inhomogeneous part. 'Largest stable
h
h
h
' means the boundary
h
=
2
โฃ
ฮป
โฃ
h=\frac{2}{|\lambda|}
h
=
โฃ
ฮป
โฃ
2
โ
, not just any stable
h
h
h
. [In notes: Note 2 p.10]
43
New cards
Why do stability questions assume
ฮป
<
0
\lambda\lt0
ฮป
<
0
(or
R
e
(
ฮป
)
โค
0
\mathrm{Re}(\lambda)\le0
Re
(
ฮป
)
โค
0
)?
Stability only matters when the exact solution decays. If
ฮป
>
0
\lambda\gt0
ฮป
>
0
the exact solution grows itself, so there is nothing to be 'stable' about. Read 'stable' / 'unconditionally stable' statements in that decaying case. [Partly in notes: Re(lambda) <= 0 is assumed in Note 4 p.19; the reason isn't stated]
44
New cards
How do you get a method's order from its
ฯ
\sigma
ฯ
?
Compare
ฯ
\sigma
ฯ
with
e
ฮป
h
=
1
+
ฮป
h
+
(
ฮป
h
)
2
2
+
(
ฮป
h
)
3
6
+
โฆ
e^{\lambda h}=1+\lambda h+\frac{(\lambda h)^2}{2}+\frac{(\lambda h)^3}{6}+\dots
e
ฮปh
=
1
+
ฮปh
+
2
(
ฮปh
)
2
โ
+
6
(
ฮปh
)
3
โ
+
โฆ
Order
ฮฑ
\alpha
ฮฑ
= matches up to and including the
(
ฮป
h
)
ฮฑ
ฮฑ
!
\frac{(\lambda h)^\alpha}{\alpha!}
ฮฑ
!
(
ฮปh
)
ฮฑ
โ
term. Explicit Euler
1
+
ฮป
h
1+\lambda h
1
+
ฮปh
: order 1. RK2
1
+
ฮป
h
+
(
ฮป
h
)
2
2
1+\lambda h+\frac{(\lambda h)^2}{2}
1
+
ฮปh
+
2
(
ฮปh
)
2
โ
: order 2. [In notes: Note 3 p.15]
45
New cards
Order when
ฯ
\sigma
ฯ
is a fraction (implicit Euler, trapezoidal)?
Expand with
1
1
โ
x
=
1
+
x
+
x
2
+
โฆ
\frac{1}{1-x}=1+x+x^2+\dots
1
โ
x
1
โ
=
1
+
x
+
x
2
+
โฆ
Implicit Euler:
1
1
โ
ฮป
h
=
1
+
ฮป
h
+
(
ฮป
h
)
2
+
โฆ
\frac{1}{1-\lambda h}=1+\lambda h+(\lambda h)^2+\dots
1
โ
ฮปh
1
โ
=
1
+
ฮปh
+
(
ฮปh
)
2
+
โฆ
(1 instead of
1
2
\frac12
2
1
โ
), order 1. Trapezoidal:
1
+
ฮป
h
+
(
ฮป
h
)
2
2
+
(
ฮป
h
)
3
4
+
โฆ
1+\lambda h+\frac{(\lambda h)^2}{2}+\frac{(\lambda h)^3}{4}+\dots
1
+
ฮปh
+
2
(
ฮปh
)
2
โ
+
4
(
ฮปh
)
3
โ
+
โฆ
(
1
4
\frac14
4
1
โ
instead of
1
6
\frac16
6
1
โ
), order 2. [Partly in notes: implicit Euler expansion Note 3 p.15; trapezoidal expansion not shown]
46
New cards
Checking stability when
ฯ
\sigma
ฯ
is a fraction?
Don't use
โ
1
โค
ฯ
โค
1
-1\le\sigma\le1
โ
1
โค
ฯ
โค
1
(that's for
1
+
h
ฮป
1+h\lambda
1
+
hฮป
). Use size of top / size of bottom. Implicit Euler:
โฃ
ฯ
โฃ
=
1
โฃ
1
โ
h
ฮป
โฃ
|\sigma|=\frac{1}{|1-h\lambda|}
โฃ
ฯ
โฃ
=
โฃ1
โ
hฮป
โฃ
1
โ
; for
ฮป
<
0
\lambda\lt0
ฮป
<
0
the bottom is
1
+
h
โฃ
ฮป
โฃ
>
1
1+h|\lambda|\gt1
1
+
h
โฃ
ฮป
โฃ
>
1
for every
h
h
h
, so stable for all
h
h
h
. Quick check:
ฮป
=
โ
10
\lambda=-10
ฮป
=
โ
10
,
h
=
10
h=10
h
=
10
gives
ฯ
=
1
101
\sigma=\frac{1}{101}
ฯ
=
101
1
โ
. [NOT in notes: memorise]
47
New cards
Implicit Euler by hand for a linear
f
f
f
, e.g.
y
โฒ
=
โ
3
y
+
2
y'=-3y+2
y
โฒ
=
โ
3
y
+
2
?
Write
y
n
+
1
=
y
n
+
h
(
โ
3
y
n
+
1
+
2
)
y_{n+1}=y_n+h(-3y_{n+1}+2)
y
n
+
1
โ
=
y
n
โ
+
h
(
โ
3
y
n
+
1
โ
+
2
)
, then collect
y
n
+
1
y_{n+1}
y
n
+
1
โ
:
y
n
+
1
=
y
n
+
2
h
1
+
3
h
y_{n+1}=\frac{y_n+2h}{1+3h}
y
n
+
1
โ
=
1
+
3
h
y
n
โ
+
2
h
โ
. Use this for every step. [Partly in notes: method Note 3 p.13; the rearranging is yours]
48
New cards
RK2 (midpoint) step by hand?
k
1
=
h
f
(
y
n
,
t
n
)
k_1=hf(y_n,t_n)
k
1
โ
=
h
f
(
y
n
โ
,
t
n
โ
)
,
k
2
=
h
f
(
y
n
+
k
1
2
,
t
n
+
h
2
)
k_2=hf\left(y_n+\frac{k_1}{2},t_n+\frac{h}{2}\right)
k
2
โ
=
h
f
(
y
n
โ
+
2
k
1
โ
โ
,
t
n
โ
+
2
h
โ
)
,
y
n
+
1
=
y
n
+
k
2
y_{n+1}=y_n+k_2
y
n
+
1
โ
=
y
n
โ
+
k
2
โ
. Both inputs move to the midpoint for
k
2
k_2
k
2
โ
. [In notes: Note 3 p.17-18]
49
New cards
Leapfrog step by hand?
y
n
+
1
=
y
n
โ
1
+
2
h
f
(
y
n
,
t
n
)
y_{n+1}=y_{n-1}+2hf(y_n,t_n)
y
n
+
1
โ
=
y
n
โ
1
โ
+
2
h
f
(
y
n
โ
,
t
n
โ
)
. Start from the point TWO back (
y
n
โ
1
y_{n-1}
y
n
โ
1
โ
), slope at the middle point
y
n
y_n
y
n
โ
. Needs a starting scheme (e.g. one Euler step) for
y
1
y_1
y
1
โ
. [In notes: Note 4 p.19]
50
New cards
Leapfrog roots: which is accurate, and why second order?
ฯ
1
,
2
=
ฮป
h
ยฑ
ฮป
2
h
2
+
1
\sigma_{1,2}=\lambda h\pm\sqrt{\lambda^2h^2+1}
ฯ
1
,
2
โ
=
ฮปh
ยฑ
ฮป
2
h
2
+
1
โ
. Expand the root,
1
+
x
2
โ
1
+
x
2
2
\sqrt{1+x^2}\approx1+\frac{x^2}{2}
1
+
x
2
โ
โ
1
+
2
x
2
โ
:
ฯ
1
โ
1
+
ฮป
h
+
(
ฮป
h
)
2
2
\sigma_1\approx1+\lambda h+\frac{(\lambda h)^2}{2}
ฯ
1
โ
โ
1
+
ฮปh
+
2
(
ฮปh
)
2
โ
, second order.
ฯ
2
โ
โ
1
+
ฮป
h
\sigma_2\approx-1+\lambda h
ฯ
2
โ
โ
โ
1
+
ฮปh
is spurious (no match to
e
ฮป
h
e^{\lambda h}
e
ฮปh
). Don't judge order from the lone
ฮป
h
\lambda h
ฮปh
. [In notes: Note 4 p.19-20]
51
New cards
Leapfrog general solution and the spurious part?
y
n
=
C
1
ฯ
1
n
+
C
2
ฯ
2
n
y_n=C_1\sigma_1^n+C_2\sigma_2^n
y
n
โ
=
C
1
โ
ฯ
1
n
โ
+
C
2
โ
ฯ
2
n
โ
with
y
0
=
C
1
+
C
2
y_0=C_1+C_2
y
0
โ
=
C
1
โ
+
C
2
โ
,
y
1
=
C
1
ฯ
1
+
C
2
ฯ
2
y_1=C_1\sigma_1+C_2\sigma_2
y
1
โ
=
C
1
โ
ฯ
1
โ
+
C
2
โ
ฯ
2
โ
. If the starting scheme gives exactly
y
1
=
ฯ
1
y
0
y_1=\sigma_1y_0
y
1
โ
=
ฯ
1
โ
y
0
โ
, then
C
2
=
0
C_2=0
C
2
โ
=
0
and the spurious part is completely suppressed. [In notes: Note 4 p.20]
52
New cards
Second-order ODE, e.g.
y
โฒ
โฒ
+
3
y
โฒ
+
2
y
=
0
y''+3y'+2y=0
y
โฒโฒ
+
3
y
โฒ
+
2
y
=
0
, with Euler?
Set
u
=
y
u=y
u
=
y
,
v
=
y
โฒ
v=y'
v
=
y
โฒ
. Then
u
โฒ
=
v
u'=v
u
โฒ
=
v
and
v
โฒ
=
โ
3
v
โ
2
u
v'=-3v-2u
v
โฒ
=
โ
3
v
โ
2
u
(rearrange for
y
โฒ
โฒ
y''
y
โฒโฒ
). Step both together with old values:
u
n
+
1
=
u
n
+
h
v
n
u_{n+1}=u_n+hv_n
u
n
+
1
โ
=
u
n
โ
+
h
v
n
โ
,
v
n
+
1
=
v
n
+
h
(
โ
3
v
n
โ
2
u
n
)
v_{n+1}=v_n+h(-3v_n-2u_n)
v
n
+
1
โ
=
v
n
โ
+
h
(
โ
3
v
n
โ
โ
2
u
n
โ
)
. Answer is
u
u
u
. [Partly in notes: systems with Euler Note 4 p.21; the u, v substitution isn't shown]
53
New cards
h
m
a
x
h_{max}
h
ma
x
โ
for a system
y
โฒ
=
A
y
y'=Ay
y
โฒ
=
A
y
: which eigenvalue?
The LARGEST
โฃ
ฮป
โฃ
|\lambda|
โฃ
ฮป
โฃ
, since
h
h
h
must be stable for every eigenvalue at once. Explicit Euler:
h
m
a
x
=
2
โฃ
ฮป
โฃ
m
a
x
h_{max}=\frac{2}{|\lambda|_{max}}
h
ma
x
โ
=
โฃ
ฮป
โฃ
ma
x
โ
2
โ
. E.g. eigenvalues
โ
2
,
โ
200
-2,-200
โ
2
,
โ
200
:
h
m
a
x
=
0.01
h_{max}=0.01
h
ma
x
โ
=
0.01
. [In notes: Note 4 p.22]
54
New cards
Exact
h
m
a
x
h_{max}
h
ma
x
โ
for the semi-discrete heat equation?
ฮป
j
=
ฮฑ
ฮ
x
2
(
โ
2
+
2
cos
โก
j
ฯ
N
)
\lambda_j=\frac{\alpha}{\Delta x^2}\left(-2+2\cos\frac{j\pi}{N}\right)
ฮป
j
โ
=
ฮ
x
2
ฮฑ
โ
(
โ
2
+
2
cos
N
j
ฯ
โ
)
,
j
=
1..
N
โ
1
j=1..N-1
j
=
1..
N
โ
1
. Largest
โฃ
ฮป
โฃ
|\lambda|
โฃ
ฮป
โฃ
is
j
=
N
โ
1
j=N-1
j
=
N
โ
1
, so compute only that one, then
h
m
a
x
=
2
โฃ
ฮป
โฃ
m
a
x
h_{max}=\frac{2}{|\lambda|_{max}}
h
ma
x
โ
=
โฃ
ฮป
โฃ
ma
x
โ
2
โ
. 'Exact' means don't use
ฮ
x
2
2
ฮฑ
\frac{\Delta x^2}{2\alpha}
2
ฮฑ
ฮ
x
2
โ
(large-
N
N
N
approx). Radians. [In notes: Note 5 p.28-29]
55
New cards
Crank-Nicolson equation for an interior node?
ฮฒ
=
ฮฑ
ฮ
t
2
ฮ
x
2
\beta=\frac{\alpha\Delta t}{2\Delta x^2}
ฮฒ
=
2ฮ
x
2
ฮฑ
ฮ
t
โ
. Unknown side:
โ
ฮฒ
ฯ
j
โ
1
n
+
1
+
(
1
+
2
ฮฒ
)
ฯ
j
n
+
1
โ
ฮฒ
ฯ
j
+
1
n
+
1
-\beta\phi_{j-1}^{n+1}+(1+2\beta)\phi_j^{n+1}-\beta\phi_{j+1}^{n+1}
โ
ฮฒ
ฯ
j
โ
1
n
+
1
โ
+
(
1
+
2
ฮฒ
)
ฯ
j
n
+
1
โ
โ
ฮฒ
ฯ
j
+
1
n
+
1
โ
. Known side:
ฮฒ
ฯ
j
โ
1
n
+
(
1
โ
2
ฮฒ
)
ฯ
j
n
+
ฮฒ
ฯ
j
+
1
n
\beta\phi_{j-1}^n+(1-2\beta)\phi_j^n+\beta\phi_{j+1}^n
ฮฒ
ฯ
j
โ
1
n
โ
+
(
1
โ
2
ฮฒ
)
ฯ
j
n
โ
+
ฮฒ
ฯ
j
+
1
n
โ
. It's half the bracket at
n
n
n
plus half at
n
+
1
n+1
n
+
1
, not an explicit update. [In notes: Note 6 p.35]