Professional Documents
Culture Documents
October 2, 2013
d du
− p(x) + q(x)u = f (x) a < x < b , (1)
dx dx
u(a) = α u(b) = β
When p(x) = p, a constant, we have
x0 = a, x1 = x0 + h, . . . ,
xi = xi−1 + h, . . . , xn+1 = xn + h = b
where
b−a
h=
n+1
au e e e
h-
e e e e e e bu
u(x + h) − u(x)
Forward Difference: u 0 (x) = + O(h)
h
u(x) − u(x − h)
Backward Difference: u 0 (x) = + O(h)
h
h2 00 h3
u(x + h) = u(x) + h u 0 (x) + u (x) + u 000 (x) + O(h4 ) . (3)
2! 3!
Now we want an approximation for u 00 (x) but if we solve for it we get
h2 00 h3
u (x) = u(x + h) − u(x) − hu 0 (x) − u 000 (x) + O(h4 ) .
2! 3!
in (3) then we still have the u 0 (x) term. However if we consider the Taylor
series expansion for u(x − h)
h2 00 h3
u(x − h) = u(x) − h u 0 (x) + u (x) − u 000 (x) + O(h4 ) (4)
2! 3!
then we can eliminate the u 0 (x) term by adding the two expansions; we
have
() Finite Differences October 2, 2013 9 / 52
h2 00 h3
u(x + h) = u(x) + h u 0 (x) + u (x) + u 000 (x) + O(h4 ) .
2! 3!
h2 00 h3
u(x − h) = u(x) − h u 0 (x) + u (x) − u 000 (x) + O(h4 )
2! 3!
implies
u(x + h) + u(x − h) − 2u(x) = h2 u 00 (x) + O(h4 )
1k -2k 1k
xi−1 xi xi+1
The forward or backward difference quotients for u 0 (x) are first order
The second centered difference for u 00 (x) is second order
So we need a second order approximation to u 0 (x)
If we subtract the expansions
h2 00 h3
u(x + h) = u(x) + h u 0 (x) + u (x) + u 000 (x) + O(h4 ) .
2! 3!
h2 00 h3
u(x − h) = u(x) − h u 0 (x) + u (x) − u 000 (x) + O(h4 )
2! 3!
we get
u(x + h) − u(x − h) = 2hu 0 (x) + O(h3 )
u(x + h) − u(x − h)
First centered difference: u 0 (x) = + O(h2 )
2h
It is described by the stencil
k
-1 1k
xi−1 xi xi+1
At i = 1 we have
−U2 + 2U1 − U0 0 U2 − U0
p(x1 ) − p (x1 ) + q(x1 )U1 = f (x1 ) ,
h2 2h
First consider the simple case when p = 1 and q = 0 then we have the
equations
2U1 − U2 = h2 f (x1 ) + α
−U3 + 2U2 − U1 = h2 f (x2 )
−U4 + 2U3 − U2 = h2 f (x3 )
..
.
−Un + 2Un−1 − Un−2 = h2 f (xn−1 )
2Un − Un−1 = h2 f (xn ) + β
using h = 1/4. Our grid will contain five total grid points
sin( π4 )
2 −1 0 U1 2 0.436179
−1 π sin( π ) = 0.61685 .
2 −1 U2 = 2
16
0 −1 2 U3 sin( 3π
4 ) 0.436179
To get a higher order scheme we need to include more points in the stencil
1h 1 4 5 4
u 00 (x) = − u(x − 2h) + u(x − h) − u(x) + u(x + h)
h2 12 3 2 3
1 i
− u(x + 2h) + O(h4 )
12
where we derive this by combining Taylor series expansions for
u(x − 2h), u(x − h), u(x + h), and u(x + 2h).
u(x + h) − u(x)
u 0 (x) forward O(h)
h
difference
u(x) − u(x − h)
u 0 (x) backward O(h)
h
difference
u(x + h) − u(x − h)
u 0 (x) centered O(h2 )
2h
difference
Recall that for IVPs we made a LTE at each step and then the total or
global error was the accumulated error over all the time steps.
Unlike IVPs, for BVPs the total error (assuming no roundoff and using a
direct solver) is just due to the error in replacing the DE with a difference
equation.
ln EE21
r=
ln hh12
User specifies
n, the number of interior grid points (alternately the grid spacing h);
1
4 5.03588×10−2
1
8 1.27852×10−2 1.978
1
16 3.20864×10−3 1.994
1
32 8.02932×10−4 1.999
1
64 2.00781×10−4 2.000
1
4 3.1402×10−16
1
8 3.1802×10−16
h4 0000
u(x + h) + u(x − h) − 2u(x) = h2 u 00 (x) + 2 u (x) + O(h5 )
4!
and for our problem the exact solution is u(x) = x 2 − x.
So u 000 (x) and all higher derivatives vanish and thus the approximation is
exact.
As an example consider
b−a
with the grid x0 = a, xn+1 = b, xi+1 = xi + h, h = .
n+1
(U1 , V1 , U2 , V2 , · · · , Un , Vn )T .
2U1 − U2 + V1 = f (x1 )
2V1 − V2 + U1 = g (x1 )
−U1 + 2U2 − U3 + V2 = f (x2 )
−V1 + 2V2 − V3 + U2 = g (x2 )
..
.
−Un−1 + 2Un + Vn = f (xn )
−Vn−1 + 2Vn + Un = g (xn ) .
with a bandwidth of 5.
Moral: the way you number your unknowns can change the structure of
your coefficient matrix.
Let domain Ω = (0, 1) × (0, 1), the unit square with boundary Γ.
x0 = 0, x1 = x0 + h, . . . , xi = xi−1 + h, . . . , xn+1 = xn + h = 1
y0 = 0, y1 = y0 + h, . . . , yj = yj−1 + h, . . . , yn+1 = yn + h = 1 .
for i, j = 0, 1, . . . , n, n + 1.
To write our difference quotient for uxx we simply use the second centered
difference in x (holding y fixed)
yj+1 1k
yj 1k -4k 1k
yj−1 1k
xi−1 xi xi+1
S −I
−I S −I
−I S −I
A=
.. .. ..
. . .
−I S −I
−I S
which is spd block tridiagonal and where S is an n × n matrix defined by
4 −1
−1 4 −1
S =
. .. . .. . ..
−1 4 −1
−1 4
1 1
−U0,1 + 4U1,1 − U2,1 −U1,0 − U1,2 = h2 f ( , )
4 4
which gives
1 1 π 1
+4U1,1 − U2,1 − U1,2 = h2 f ( , ) + cos + (1 + )2
4 4 4 4
1 1
−U1,1 + 4U2,1 − U3,1 −U2,0 − U2,2 = h2 f ( , )
2 4
which gives
1 1 1
−U1,1 + 4U2,1 − U3,1 − U2,2 = h2 f ( , ) + (1 + )2
2 4 2
at (x3 , y1 ) = ( 34 , 14 )
3 1
−U2,1 + 4U3,1 − U4,1 −U3,0 − U3,2 = h2 f ( , )
4 4
which gives
3 1 π 3
−U2,1 + 4U3,1 − U3,2 − U1,2 = h2 f ( , ) + 4 cos + (1 + )2
4 4 4 4
U0,0 = (1 + 0)2
1
U1,0 = (1 + )2
4
1
U2,0 = (1 + )2
2
3
U3,0 = (1 + )2
4
U4,0 = (1 + 1)2
π
U0,1 = cos
4
1 1
−U0,1 + 4U1,1 − U2,1 −U1,0 − U1,2 = h2 f ( , )
4 4
1 1
−U1,1 + 4U2,1 − U3,1 −U2,0 − U2,2 = h2 f ( , )
2 4
2 3 1
−U2,1 + 4U3,1 − U2,1 −U3,0 − U3,2 = h f ( , )
4 4
π
U4,1 = 4 cos
4
..
.
() Finite Differences October 2, 2013 49 / 52
Neumann Boundary Conditions