Professional Documents
Culture Documents
Two Point
Two Point
Two-point Boundary
Value Problems:
Numerical
Approaches
Bueler
finite difference
shooting
serious example:
solved
exercises
Ed Bueler
Dept of Mathematics and Statistics
University of Alaska, Fairbanks
elbueler@alaska.edu
1.1
abbreviations
Two-point Boundary
Value Problems:
Numerical
Approaches
Bueler
shooting
serious example:
solved
exercises
1.2
Outline
Two-point Boundary
Value Problems:
Numerical
Approaches
Bueler
finite difference
shooting
serious example:
solved
exercises
1.3
Two-point Boundary
Value Problems:
Numerical
Approaches
Bueler
serious example
find y (x) if
y + 2y 8y = 0,
y (0) = 1,
finite difference
y (0) = 0
shooting
serious example:
solved
exercises
find y (x) if
y 00 + 2y 0 8y = 0,
y (0) = 1,
y (1) = 0
1.4
Two-point Boundary
Value Problems:
Numerical
Approaches
Bueler
find y (x) if
y 00 + 2y 0 8y = 0,
Example 2: ODE BVP.
00
y (0) = 1,
y 0 (0) = 0
classical IVPs and
BVPs
find y (x) if
y + 2y 8y = 0,
y (0) = 1,
serious example
y (1) = 0
finite difference
shooting
serious example:
solved
exercises
Two-point Boundary
Value Problems:
Numerical
Approaches
Bueler
IVP soln
BVP soln
exercises
0
0
0.2
0.4
0.6
0.8
1.6
Two-point Boundary
Value Problems:
Numerical
Approaches
Bueler
find y (x) if
y + 2y 8y = 0,
y (0) = 1,
y (1) = 0
serious example
finite difference
shooting
serious example:
solved
exercises
Two-point Boundary
Value Problems:
Numerical
Approaches
Bueler
(1)
y 00 = f (x, y , y 0 )
(2)
finite difference
shooting
serious example:
solved
exercises
0
y
v
=
v0
p(x)v q(x)y + r (x)
and equation (2) is equivalent to
0
y
v
=
v0
f (x, y , v )
first order systems are the form in which we can apply a
Two-point Boundary
Value Problems:
Numerical
Approaches
Bueler
serious example
Theorem.
finite difference
shooting
y = f(t, y),
(3)
serious example:
solved
exercises
1.9
Two-point Boundary
Value Problems:
Numerical
Approaches
Bueler
find y (x) if
y (0) = 1,
y (1) = 0
serious example
finite difference
shooting
serious example:
solved
exercises
0 = y (1) = 1 + c2 sin()
Two-point Boundary
Value Problems:
Numerical
Approaches
Bueler
y 00 + p(x)y 0 + q(x)y = y ,
y (a) = 0,
y (b) = 0 (4)
operator
d
d
+ p(x)
+ q(x)
dx
dx
(though the operator A must somehow also include the
homogeneous boundary conditions)
in (4) we seek eigenvalues = n , which come in an
infinite-but-countable list, and their associated
eigenfunctions y = yn (x)
Sturm-Liouville theory explains the impossible case on
the previous slide . . . but this Sturm-Liouville thread will not
be pursued further here . . .
A=
1.11
Outline
Two-point Boundary
Value Problems:
Numerical
Approaches
Bueler
finite difference
shooting
serious example:
solved
exercises
1.12
Two-point Boundary
Value Problems:
Numerical
Approaches
Bueler
u
c
=
k (x)
+ r (x)u + s(x)
t
x
x
serious example
finite difference
shooting
(5)
serious example:
solved
exercises
1.13
Two-point Boundary
Value Problems:
Numerical
Approaches
Bueler
serious example
0=
x
u
k (x)
+ r (x)u + s(x)
x
finite difference
shooting
serious example:
solved
exercises
(6)
u(L) = 0
(7)
1.14
Two-point Boundary
Value Problems:
Numerical
Approaches
Bueler
1.15
example, as code
Two-point Boundary
Value Problems:
Numerical
Approaches
Bueler
L
k
r0
s
=
=
=
=
3;
@(x) 0.5 * atan((x-1.0) * 20.0) + 1.0;
0.5;
@(x) exp(-(x-2.0).^2);
finite difference
shooting
serious example:
solved
exercises
J = 300;
dx = L / J;
x = 0:dx:L;
plot(x,k(x),x,r0*ones(size(x)),x,s(x))
grid on, xlabel x
legend(k(x),r(x)=r_0,s(x))
1.16
Two-point Boundary
Value Problems:
Numerical
Approaches
Bueler
problem to solve:
0 0
(k (x)u ) + r0 u = s(x),
u (0) = 0,
u(3) = 0
(8)
serious example
finite difference
shooting
serious example:
solved
exercises
left end?
1.17
Two-point Boundary
Value Problems:
Numerical
Approaches
Bueler
serious example:
solved
exercises
1.18
Outline
Two-point Boundary
Value Problems:
Numerical
Approaches
Bueler
finite difference
shooting
serious example:
solved
exercises
1.19
finite differences
Two-point Boundary
Value Problems:
Numerical
Approaches
Bueler
serious example
finite difference
shooting
serious example:
solved
exercises
Taylors-theorem-with-remainder argument:
f (x h) 2f (x) + f (x + h)
f (4) () 2
00
=
f
(x)
+
h
h2
12
1.20
Two-point Boundary
Value Problems:
Numerical
Approaches
Bueler
finite difference
shooting
00
y = 12x ,
y (0) = 0,
y (1) = 0
serious example:
solved
exercises
integrating
1.21
x = 1/J
Two-point Boundary
Value Problems:
Numerical
Approaches
Bueler
xj = 0 + (j 1)x
(j = 1, . . . , J + 1)
shooting
serious example:
solved
exercises
y 00 = 12x 2
by
Yj1 2Yj + Yj+1
= 12xj2
x 2
the boundary conditions are: Y1 = 0, YJ+1 = 0
1.22
unknowns:
Two-point Boundary
Value Problems:
Numerical
Approaches
Bueler
Y1 = 0
Y1 2Y2 + Y3 =
12x 2 x22
12x 2 x32
serious example:
solved
exercises
Y2 2Y3 + Y4 =
..
..
.
.
1.23
Two-point Boundary
Value Problems:
Numerical
Approaches
Bueler
serious example
1
1
..
.
0
2
1
...
0
1
2
0
0
1
..
.
1
0
0
0
Y1
2 2
0
Y2 12x 2 x22
0 Y3 12x x3
.. =
..
.
2
2
2 1
YJ
12x xJ
0 1
YJ+1
0
...
...
finite difference
shooting
serious example:
solved
exercises
i.e.
AY = b
1.24
as a sparse matrix
this means that the locations of nonzero entries, and the
Two-point Boundary
Value Problems:
Numerical
Approaches
Bueler
1.25
Two-point Boundary
Value Problems:
Numerical
Approaches
Bueler
% solve A Y = b
1.26
Two-point Boundary
Value Problems:
Numerical
Approaches
Bueler
expect:
classical IVPs and
BVPs
serious example
finite difference
shooting
serious example:
solved
exercises
1.27
Two-point Boundary
Value Problems:
Numerical
Approaches
Bueler
let ej = Yj y (xj )
Two-point Boundary
Value Problems:
Numerical
Approaches
Bueler
by subtraction,
serious example
finite difference
shooting
serious example:
solved
exercises
ej = 0.01xj (xj 1)
so
1.29
Outline
Two-point Boundary
Value Problems:
Numerical
Approaches
Bueler
finite difference
shooting
serious example:
solved
exercises
1.30
Two-point Boundary
Value Problems:
Numerical
Approaches
Bueler
y 00 = 12x 2 ,
y (0) = 0,
y (1) = 0
w 00 = 12x 2 ,
w(0) = 0,
w 0 (0) = A
1.31
w(0) = 0,
w 0 (0) = A
w(x) = x + Ax
plotting for A = 2.5, 1.5, 0.5, 0.5, 1.5 gives this figure:
Two-point Boundary
Value Problems:
Numerical
Approaches
Bueler
1.32
Two-point Boundary
Value Problems:
Numerical
Approaches
Bueler
finite difference
shooting
serious example:
solved
exercises
1.33
Two-point Boundary
Value Problems:
Numerical
Approaches
Bueler
y 00 = 12x 2 ,
y (0) = 0,
y (1) = 0
serious example
finite difference
w 00 = 12x 2 ,
w(0) = 0,
w 0 (0) = A
(9)
shooting
serious example:
solved
exercises
F (A) = 0
in this easy problem, w(x) = x 4 + Ax
so we solve F (A) = 1 + A = 0 and get A = 1
generally we solve F (A) = 0 numerically, e.g. by the
Two-point Boundary
Value Problems:
Numerical
Approaches
Bueler
1.35
Outline
Two-point Boundary
Value Problems:
Numerical
Approaches
Bueler
finite difference
shooting
serious example:
solved
exercises
1.36
(k (x)u 0 ) + r0 u = s(x),
u 0 (0) = 0,
u(3) = 0, (10)
Two-point Boundary
Value Problems:
Numerical
Approaches
Bueler
shooting
serious example:
solved
exercises
1.37
Two-point Boundary
Value Problems:
Numerical
Approaches
Bueler
xj = (j 1)x
for j = 1, . . . , J + 1
serious example
finite difference
shooting
serious example:
solved
exercises
solving
q 0 + r0 u = s(x)
the finite difference version looks like
qj+1/2 qj1/2
+ r0 Uj = s(xj )
x
or
k (xj+1/2 )
Uj+1 Uj
x
k (xj1/2 )
x
Uj Uj1
x
+ r0 Uj = s(xj )
1.38
Two-point Boundary
Value Problems:
Numerical
Approaches
Bueler
x 2
+ r0 Uj = sj
serious example
finite difference
or (clear denominators)
shooting
serious example:
solved
exercises
or
kj 1 Uj1 kj 1 + kj+ 1 r0 x 2 Uj + kj+ 1 Uj+1 = sj x 2
2
matrix equation AU = b
note we actually evaluate the conductivity k (x), and the
Two-point Boundary
Value Problems:
Numerical
Approaches
Bueler
approximate this by
finite difference
U2 U1
=0
x
shooting
serious example:
solved
exercises
or
U1 + U2 = 0
we will see there is a more-accurate way later . . .
also we have u(L) = 0 so
UJ+1 = 0
1.40
=
=
=
=
3;
@(x) 0.5 * atan((x-1.0) * 20.0) + 1.0;
@(x) exp(-(x-2.0).^2);
0.5;
dx
x
xstag
kstag
=
=
=
=
L / J;
(0:dx:L);
% regular grid
((dx/2):dx:L-(dx/2)); % staggered grid
k(xstag);
% k(x) on staggered grid
Two-point Boundary
Value Problems:
Numerical
Approaches
Bueler
Two-point Boundary
Value Problems:
Numerical
Approaches
Bueler
serious example
finite difference
shooting
serious example:
solved
exercises
6
8
10
12
0
6
nz = 30
10
12
1.42
Two-point Boundary
Value Problems:
Numerical
Approaches
Bueler
finite difference
shooting
serious example:
solved
exercises
figure(1)
plot(x,k(x),r,x,s(x),b,...
x,U,g*,markersize,3)
grid on, xlabel x
legend(k(x),s(x),solution U_j)
1.43
Two-point Boundary
Value Problems:
Numerical
Approaches
Bueler
serious example
finite difference
shooting
serious example:
solved
exercises
1
2
3
k(x)
s(x)
solution Uj
5
6
0
0.5
1.5
x
2.5
1.44
Two-point Boundary
Value Problems:
Numerical
Approaches
Bueler
serious example
finite difference
J
10
20
60
200
1000
4000
estimate of u(0)
-13.86507
-7.20263
-5.66666
-5.27443
-5.15199
-5.12965
shooting
serious example:
solved
exercises
1.45
Two-point Boundary
Value Problems:
Numerical
Approaches
Bueler
serious example:
solved
exercises
1.46
Two-point Boundary
Value Problems:
Numerical
Approaches
Bueler
N = 100;
for n = 1:N
fprintf(.)
c = (a+b)/2;
% evaluate F(c) = (estimate of u(3) using u(0)=c)
Y = lsode(G,[c; 0.0],[0.0 3.0]);
F = Y(2,1);
if abs(F) < 1e-12
break % we are done
elseif F >= 0.0
a = c;
else
b = c;
end
end
finite difference
shooting
serious example:
solved
exercises
1.47
Two-point Boundary
Value Problems:
Numerical
Approaches
Bueler
the finish:
% redo to get final version on a grid for plot
x = 0:0.05:3.0;
Y = lsode(G,[c; 0.0],x);
u = Y(:,1);
q = Y(:,2);
figure(2)
plot(x,k(x),r,x,s(x),b,x,u,g*,x,q,k)
grid on, xlabel x
legend(k(x),s(x),u(x),q(x))
serious example
finite difference
shooting
serious example:
solved
exercises
1.48
Two-point Boundary
Value Problems:
Numerical
Approaches
Bueler
finite difference
shooting
serious example:
solved
exercises
2
3
k(x)
s(x)
u(x)
q(x)
6
0.5
1.5
x
2.5
minimal conclusion
Two-point Boundary
Value Problems:
Numerical
Approaches
Bueler
finite difference
shooting
serious example:
solved
exercises
1.50
Outline
Two-point Boundary
Value Problems:
Numerical
Approaches
Bueler
finite difference
shooting
serious example:
solved
exercises
1.51
Two-point Boundary
Value Problems:
Numerical
Approaches
Bueler
exercises
1
y (0) = 1,
y (1) = 0.
classical IVPs and
BVPs
y (0) = 1,
y (1) = A.
serious example
finite difference
shooting
serious example:
solved
exercises
Two-point Boundary
Value Problems:
Numerical
Approaches
Bueler
exercises, cont
y (0) = 0,
y (1) = 0.
finite difference
shooting
serious example:
solved
exercises
1.53
Two-point Boundary
Value Problems:
Numerical
Approaches
Bueler
u 00 + u 3 = 0,
u(0) = 1,
u(1) = 0.
finite difference
shooting
u(0) = 1,
serious example:
solved
exercises
u 0 (0) = A
1 Possibly
1.54