Você está na página 1de 50

Numerical Solution to ODEs (BVP)

ChE 106
Maria Christine Tankeh Asuncion
You never know a good thing till its gone
-The Script (Live Like Were Dying)
Outline: September 25, 2012
Review: Reducing ODEs to Canonical Form
ODEs Boundary Value Problems
Shooting Method (Linear)
Finite Difference Method for Linear BVPs
Review of ODEs
Ordinary Differential Equations: Recall
Linear vs. Nonlinear
order: 1 [linear]
order: 2 [nonlinear]
order: 3 [nonlinear]
Ordinary Differential Equations: Recall
Transformation to Canonical Form (system of 1
st
order DEs)
system of
equations
Ordinary Differential Equations: Recall
Transformation to Canonical Form (system of 1
st
order DEs)
initial conditions solution
Ordinary Differential Equations: Recall
Transformation to Canonical Form (system of 1
st
order DEs) CAN ALSO BE DONE TO n-th ORDER
DEs
Steps:
1. represent dependent variable & its derivatives with
new variables (start from z and end in z
(n-1)
)
2. reduce n-th order DE to system of 1
st
order DEs
Ordinary Differential Equations: Recall

y
1
,y
2
y
n
are new variables
canonical form
Ordinary Differential Equations: Recall
Exercise on the board. :D Reduce these to canonical
form.
Ordinary Differential Equations: Recall
a b
Ordinary Differential Equations: Recall
c [nonlinear] d [nonlinear]
Boundary Value Problems
Ordinary Differential Equations: BVP
we will focus on second order two-point boundary
value problems
with the boundary conditions
) ' , , ( ' ' ) , , (
2
2
y y t f y or
dt
dy
y t f
dt
y d
= =
|
o
=
=
) (
) (
b y
a y
Ordinary Differential Equations: BVP
Methods of Solving
1. Shooting Methods
Linear Shooting Method
Nonlinear Shooting Method
2. Finite Difference Methods for Linear BVPs
3. Rayleigh-Ritz Method
Ordinary Differential Equations: BVP
note: we will be dealing with LINEAR differential
equations only TODAY (degree of derivatives are 1,
no products of the dependent variable or/and its
derivatives)
Ordinary DEs: BVP: Application Example
cooling fin: what is the temperature profile across
the fin?
Shooting Method
Linear Shooting Method
solves the BVP by
solving 2 IVPs (2
shots)
a linear combination
of the 2 solutions
from the 2 IVPs will
yield a solution for
the BVP
Linear Shooting Method
given a linear BVP
with the boundary conditions:
we can associate 2 IVPs
) ( ) ( ' ) ( ) ( ' ' t r y t q y t p t y + + =
| o = = ) ( & ) ( b y a y

= =
+ + =

0 ) ( ' , ) (
) ( ) ( ' ) ( ) ( ' '
1
1 1
1 1 1
a y a y
t r y t q y t p t y
IVP
o

= =
+ =

1 ) ( ' , 0 ) (
) ( ' ) ( ) ( ' '
2
2 2
2 2 2
a y a y
y t q y t p t y
IVP
identical to y(t)
homogeneous
Linear Shooting Method
if is a solution to IVP-1 and
is a solution to IVP-2
then
is a solution of the original BVP, as long as
now, lets prove it. :D
) (
) (
2
1
t y
t y
) (
) (
) (
) ( ) (
2
2
1
1
t y
b y
b y
t y t y

+ =
|
0 ) (
2
= b y
Linear Shooting Method: Derivation
To prove is a solution
to
To be a solution and because of linearity of the
differential operator, it should be that
) (
) (
) (
) ( ) (
2
2
1
1
t y
b y
b y
t y t y

+ =
|
) ( ) ( ' ) ( ) ( ' ' t r y t q y t p t y + + =
) ( ' ' ) ( ' ' ) ( ' '
2 1
t Cy t y t y + =
C
Linear Shooting Method: Derivation
plugging in the form of y
1
and y
2
from IVP-1 and
IVP-2,
) ( ' ' ) ( ' ' ) ( ' '
2 1
t Cy t y t y + =
) ( ) ( ) ( ' ) ( ) ( ) ( ) ( ) ( ' ) ( ) ( ' '
2 2 1 1
t y t Cq t y t Cp t r t y t q t y t p t y + + + + =
| | | | ) ( ) ( ) ( ) ( ) ( ' ) ( ' ) ( ) ( ' '
2 1 2 1
t r t Cy t y t q t Cy t y t p t y + + + + =
) ( ) ( ) ( ) ( ' ) ( ) ( ' ' t r t y t q t y t p t y + + =
and this is the form of the original
linear BVP, thus proving the claim
Linear Shooting Method: Derivation
now to derive the expression for , let us use the
given boundary conditions in this expression:
using IVP-1 conditions
using IVP-2 conditions
now imposing the boundary condition that
and solving for C, we get for BC2 to
be true
C
) ( ) ( ) (
2 1
t Cy t y t y + =
0 ) ( ) ( ) (
2 1
+ = + = o a Cy a y a y
) ( ) ( ) (
2 1
b Cy b y b y + =
| = ) (b y
which is
consistent with
BC1
) (
) (
2
1
b y
b y
C

=
|
Linear Shooting Method
so finally, the solution when using the shooting
method is given by
) (
) (
) (
) ( ) (
2
2
1
1
t y
b y
b y
t y t y

+ =
|
Linear Shooting Method: Steps
Steps:
1. Derive IVP-1 and IVP-2 from BVP
2. Specify h to be used in solving the IVPs
3. Solve the two IVPs using the Runge-Kutta Method
4. Use the formula at each discrete value of the
independent variable
) (
) (
) (
) ( ) (
2
2
1
1
t y
b y
b y
t y t y

+ =
|
Linear Shooting Method: Example
Solve the BVP over the interval [0,4] using RK
(h=0.2)
#1
1 ) (
1
2
) ( '
1
2
) ( ' '
2 2
+
+

+
= t x
t
t x
t
t
t x
95 . 0 ) 4 ( , 25 . 1 ) 0 ( = = x x
1 ) (
1
2
) ( '
1
2
) ( ' '
1
2
1
2
1
+
+

+
= t x
t
t x
t
t
t x
) (
1
2
) ( '
1
2
) ( ' '
2
2
2
2
2
t x
t
t x
t
t
t x
+

+
=
0 ) 0 ( ' , 25 . 1 ) 0 (
1 1
= = x x
1 ) 0 ( ' , 0 ) 0 (
2 2
= = x x
Linear Shooting Method: Example
#2, h=0.2
#3 using RK4
1 ) (
1
2
) ( '
1
2
) ( ' '
1
2
1
2
1
+
+

+
= t x
t
t x
t
t
t x
'
1 2
1 1
x u
x u
=
=
1
1
2
1
2
'
'
1
2
2
2
2
2 1
+
+

+
=
=
u
t
u
t
t
u
u u
converting this 2
nd
order DE to a system of 1
st
order DEs
0 ) 0 ( ' , 25 . 1 ) 0 (
1 1
= = x x
note that u
1
is x
1
0 ) 0 ( , 25 . 1 ) 0 (
2 1
= = u u
Linear Shooting Method: Example

h 0.2 h/2 0.1


u1 u2
t k1 k2 k3 k4 u1 k1 k2 k3 k4 u2
0 1.25 0
0.2 0 -0.15 -0.1505 -0.29507 1.220131 -1.5 -1.50495 -1.47535 -1.45945 -0.29733
0.4 -0.29733 -0.44341 -0.44016 -0.57728 1.132073 -1.46077 -1.4283 -1.39971 -1.35002 -0.57956
0.6 -0.57956 -0.71472 -0.7086 -0.83233 0.990122 -1.35155 -1.29036 -1.26384 -1.19081 -0.83459
0.8 -0.83459 -0.95383 -0.94591 -1.05254 0.800569 -1.19246 -1.11322 -1.08976 -1.00362 -1.05465
1 -1.05465 -1.15518 -1.14634 -1.23405 0.570844 -1.00523 -0.91687 -0.89697 -0.80535 -1.23593
1.2 -1.23593 -1.31661 -1.30747 -1.37573 0.30885 -0.80677 -0.7154 -0.699 -0.60674 -1.37734
1.4 -1.37734 -1.43813 -1.42906 -1.47813 0.022522 -0.60792 -0.51724 -0.50396 -0.4138 -1.47948
1.6 -1.47948 -1.52095 -1.51215 -1.5427 -0.28042 -0.41472 -0.32677 -0.3161 -0.22944 -1.54381
1.8 -1.54381 -1.56682 -1.5584 -1.57128 -0.59261 -0.23015 -0.14591 -0.13736 -0.05481 -1.57219
2 -1.57219 -1.57772 -1.56971 -1.56586 -0.90704 -0.05535 0.024794 0.03164 0.109931 -1.56661
2.2 -1.56661 -1.55566 -1.54806 -1.52841 -1.21712 0.109529 0.185517 0.191011 0.265122 -1.52902
2.4 -1.52902 -1.50254 -1.49534 -1.46078 -1.51664 0.264822 0.336785 0.341206 0.411338 -1.46128
2.6 -1.46128 -1.42017 -1.41335 -1.36471 -1.79974 0.411114 0.479268 0.482834 0.549241 -1.36513
2.8 -1.36513 -1.31022 -1.30376 -1.24182 -2.0609 0.549074 0.613669 0.616552 0.679503 -1.24216
3 -1.24216 -1.17422 -1.16809 -1.09356 -2.29492 0.679379 0.740674 0.743009 0.802769 -1.09384
3.2 -1.09384 -1.01358 -1.00775 -0.92128 -2.49684 0.802677 0.860926 0.862817 0.919639 -0.92152
3.4 -0.92152 -0.82956 -0.82402 -0.72621 -2.662 0.919571 0.975012 0.976543 1.030659 -0.72641
3.6 -0.72641 -0.62334 -0.61806 -0.50947 -2.78596 1.030609 1.083462 1.084699 1.136324 -0.50963
3.8 -0.50963 -0.396 -0.39096 -0.27208 -2.86448 1.136288 1.186755 1.18775 1.237078 -0.27222
4 -0.27222 -0.14851 -0.14369 -0.015 -2.89353 1.237053 1.285318 1.286114 1.333322 -0.01511
Linear Shooting Method: Example

) (
1
2
) ( '
1
2
) ( ' '
2
2
2
2
2
t x
t
t x
t
t
t x
+

+
=
'
2 2
2 1
x r
x r
=
=
1
2
2
2
2
2 1
1
2
1
2
'
'
r
t
r
t
t
r
r r
+

+
=
=
converting this 2
nd
order DE to a system of 1
st
order DEs
note that r
1
is x
2
1 ) 0 ( ' , 0 ) 0 (
2 2
= = x x
1 ) 0 ( , 0 ) 0 (
2 1
= = r r
Linear Shooting Method: Example

h 0.2 h/2 0.1


r1 r2
t k1 k2 k3 k4 r1 k1 k2 k3 k4 r2
0 0 1
0.2 1 1 1 1 0.2 0 0 0 0 1
0.4 1 1 1 1 0.4 0 0 0 0 1
0.6 1 1 1 1 0.6 0 0 0 0 1
0.8 1 1 1 1 0.8 0 0 0 0 1
1 1 1 1 1 1 0 0 0 0 1
1.2 1 1 1 1 1.2 0 0 0 0 1
1.4 1 1 1 1 1.4 0 0 0 0 1
1.6 1 1 1 1 1.6 0 0 0 0 1
1.8 1 1 1 1 1.8 0 0 0 0 1
2 1 1 1 1 2 0 0 0 0 1
2.2 1 1 1 1 2.2 0 0 0 0 1
2.4 1 1 1 1 2.4 0 0 0 0 1
2.6 1 1 1 1 2.6 0 0 0 0 1
2.8 1 1 1 1 2.8 0 0 0 0 1
3 1 1 1 1 3 0 0 0 0 1
3.2 1 1 1 1 3.2 0 0 0 0 1
3.4 1 1 1 1 3.4 0 0 0 0 1
3.6 1 1 1 1 3.6 0 0 0 0 1
3.8 1 1 1 1 3.8 0 0 0 0 1
4 1 1 1 1 4 0 0 0 0 1
Linear Shooting Method: Example
#4
so finally, x(t) values are
) (
) (
) (
) ( ) (
2
2
1
1
t x
b x
b x
t x t x

+ =
|
) (
) 4 (
) 4 ( 95 . 0
) ( ) (
2
2
1
1
t x
x
x
t x t x

+ =
) (
4
89353 . 2 95 . 0
) ( ) (
2 1
t x t x t x
+
+ =
Linear Shooting Method: Example
t x(t)
0 1.25
0.2 1.317308
0.4 1.326426
0.6 1.281652
0.8 1.189276
1 1.056728
1.2 0.891911
1.4 0.702759
1.6 0.496989
1.8 0.281982
2 0.064728
2.2 -0.14818
2.4 -0.35052
2.6 -0.53644
2.8 -0.70043
3 -0.83726
3.2 -0.94201
3.4 -1.01
3.6 -1.03678
3.8 -1.01812
4 -0.95
Nonlinear Shooting Method
applicable even to
nonlinear BVPs
Nonlinear Shooting Method

Nonlinear Shooting Method

Nonlinear Shooting Method

Finite Difference Method


Finite Difference Method
approximates first and
second derivative using
the central difference
formulas
Finite Difference Method: Recall
Recall the Central Difference Formulas:
2
) ( ) ( 2 ) (
) ( ' '
2
) ( ) (
) ( '
h
h a f a f h a f
a f
h
h a f h a f
a f
+ +
~
+
~
Finite Difference Method: Derivation
given a linear BVP
with the boundary conditions:
we will now subdivide the interval [a b]
choose a positive integer N
divide [a b] by N
you get N equal intervals using (N-1) interior values
) ( ) ( ' ) ( ) ( ' ' t r y t q y t p t y + + =
| o = = ) ( & ) ( b y a y
a t =
0
b t
N
=
h
h a t
i
+ = h N a t
N
) 1 (
1
+ =

Finite Difference Method: Derivation


at each interior value, we approximate the DE
as
multiplying by h
2
and after regrouping, it is
rewritten as
) ( ) ( ' ) ( ) ( ' ' t r y t q y t p t y + + =
i i i
i i
i
i i i
r y q
h
y y
p
h
y y y
+ +

=
+
+ +
2
2
1 1
2
1 1
( )
i i
i
i i i
i
r h y
h p
y q h y
h p
2
1
2
1
2
1 2
2
1 =
|
.
|

\
|
+ +
|
.
|

\
|
+
+
for
0<i<N
Finite Difference Method: Derivation
And since we know that
we can use that in our system of equations with
N-1 equations (since N-1 interior values)
N-1 unknowns (since you already know y
0
& y
N
)
unknowns are
| o = = ) ( & ) ( b y a y
1 3 2 1
... , ,
N
y y y y
Finite Difference Method: Derivation
writing down all the equations, we can put it in
matrix form
C AY =
(
(
(
(
(
(
(
(

|
.
|

\
|

|
.
|

\
|
+
=
(
(
(
(
(
(

(
(
(
(
(
(
(
(
(

+ +
+ +
+ +
+

|
o
2
1
2
1
) 2 (
2
1 0 0
2
1 ) 2 (
2
1
0
0
2
1 ) 2 (
2
1
0 0
2
1 ) 2 (
1
1
2
2
2
2
2
1
1
2
3
2
1
1
2 1
2
2
2 2
2
2
2 2
1
1
2
h p
r h
r h
r h
h p
r h
y
y
y
y
q h
h p
h p
q h
h p
h p
q h
h p
h p
q h
N
N
N
N
N
N
N
N
N

A is a tridiagonal matrix!
Finite Difference Method: Derivation
To solve the system of equations, you may use
LU Decomposition, Inverse Method, Cramers Rule
Gaussian-Elimination, Gauss-Jordan, etc.
Thomas Method
etc.
Finite Difference Method: Steps
Steps:
1. Identify p(t), q(t), and r(t)
2. Specify N, and calculate h
3. Build matrix A and C
4. Solve for Y
Finite Difference Method: Example
Given the following BVP
#1 & #2
0 ) 50 ( & 0 ) 0 (
1920000
) 50 (
10 25 . 6 ) ( ' '
6
= =

+ =

y y
x x
y x x y
1920000
) 50 (
) (
10 25 . 6 ) (
0 ) (
6

=
=
=

x x
t r
x t q
t p
5 . 2
20
0 50
=

=
N
a b
h
Finite Difference Method: Example
#3
Finite Difference Method: Example

Finite Difference Method: Example


#4 the program was done in MATLAB using N=20
note: x in the program stands for the dependent
variable and t stands for the independent variable
0 5 10 15 20 25 30 35 40 45 50
0
0.01
0.02
0.03
0.04
0.05
0.06
0.07
0.08
0.09
x
y
I am pleased to say we have homework. :D
Solve the given DE using
a) Linear Shooting Method
b) Finite Difference Method
c) Nonlinear Shooting Method
show complete solution for every
method, write down necessary
auxiliary equations, etc.
use h = 0.01 when doing RK4
plot the solutions

= =
= +
0 ) 3 ( , 4 ) 1 (
2 ) ( ' 3 ) ( ' '
2
y y
t ty t y t
try replicating the values in the slides first

Você também pode gostar