You are on page 1of 21

10.

34: Numerical Methods


Applied to
Chemical Engineering
Lecture 16:
ODE-IVP and Numerical Integration

1
Quiz 1 Results
• Mean: 70.6
• Standard deviation: 11.0

20

15

10

0
<50 50-59 60-69 70-79 80-89 >89

2
Recap

• Implicit methods for ODE-IVPs

3
Recap
• Example:
• Use implicit Euler to solve:
dx
= x, x(0) = x0
dt
Give a closed form formula for the numerical solution

4
Recap
• Example:
• Use implicit Euler to solve:
dx
= x, x(0) = x0
dt
• Let:x = x(k t)
k
xk+1 = xk + t xk+1
1
xk+1 = xk
1 t t
✓ ◆k
1
xk = x0
1 t
• Stability:
2 2
|1 t | 1 ) (1 tRe ) + ( tIm ) 1 5
Recap
• Example:
• Use implicit Euler to solve:
dx
= x, x(0) = x0
dtxk+1 = xk + t xk+1
1
• Numerical
xk+1 =solution: xk
1 t
✓ ◆k
1
xk = x0
1 t
t
• Exact solution:

x k = x0 e k t

• Stability and accuracy do not correlate!


6
Multistep Methods
• Multistep methods utilize information over multiple time steps to
approximate the solution of an ODE.

• These can be designed for higher accuracy, larger stability bounds or


both.

• Example: Leapfrog method


dx
= f (x(t), t)
dt
• Approximate derivative with central difference:
1
(x(t + t) x(t t)) = f (x(t), t)
2 t
x(tk+1 ) = x(tk 1) + 2 tf (x(tk ), tk )

k 1 k+1
7
Multistep Methods
• Local accuracy of the leap frog method:
dx 1
= (x(tk+1 ) x(tk 1 )) + O(( t)2 ) = f (x(tk ), tk )
dt 2 t
3
x(tk+1 ) = x(tk 1 ) + 2 tf (x(tk ), tk ) + O(( t) )
• Stability of the leap frog method: dx
= x
dt
xk+1 = xk 1 + 2 t xk
✓ ◆ ✓ ◆✓ ◆
xk+1 2 t 1 xk
=
xk 1 0 xk 1
✓ ◆ ✓ ◆
xk+1 k x1
=C
xk x0
8
Multistep Methods
• Local accuracy of the leap frog method:
dx 1
= (x(tk+1 ) x(tk 1 )) + O(( t)2 ) = f (x(tk ), tk )
dt 2 t
3
x(tk+1 ) = x(tk 1 ) + 2 tf (x(tk ), tk ) + O(( t) )
• Stability of the leap frog method: dx
= x
dt
xk+1 = xk 1 + 2 t xk
✓ ◆ ✓ ◆
xk+1 k x1
=C
xk x0
✓ ◆
2 t 1
C=
1 0
What are the eigenvalues of this matrix? 9
Multistep Methods
• Local accuracy of the leap frog method:
dx 1
= (x(tk+1 ) x(tk 1 )) + O(( t)2 ) = f (x(tk ), tk )
dt 2 t
3
x(tk+1 ) = x(tk 1 ) + 2 tf (x(tk ), tk ) + O(( t) )
• Stability of the leap frog method: dx
= x
dt
xk+1 = xk 1 + 2 t xk
• Both eigenvalues of C must be bounded:
t
p i
| t ± ( t )2 + 1|  1
consider
| t ± 1|  1 when | t | ⌧ 1 :
| t ± 1|  1 | t |⌧1 i 10
Multistep Methods
• Exercise:
• Should I use the leap frog method to integrate the equations of
motion for a mass-spring system?

d2 x
m 2 = kx
dt
• If so, what time steps should I limit myself to?
• If not, what other integrator could I use?

11
Multistep Methods
• Exercise:
• Should I use the leap frog method to integrate the equations of
motion for a mass-spring system?
d2 x
m 2 = kx
dt

• Transform
✓ to◆system✓of first order ODEs:
◆✓ ◆
d v 0 k/m v
=
dt x 1 0 x
r
k
• Eigenvalues of matrix: = ±i
m
• Since eigenvalues are imaginary, leap frog is stable when:
r
m
t<
k 12
Multistep Methods
• Multistep methods can be implicit as well such as the backward
differentiation formulas or Adams-Moulton integrators.

• Example: Backwards differentiation


4 1 2
xk+1 = xk xk 1+ tf (xk+1 , tk+1 )
3 3 3
• Second order accurate.
• How would you identify the stability bounds?

13
Numerical Integration
• Consider the definite integral:
Z t f

f (⌧ )d⌧
t0

• We can define a variable:


Z t
x(t) = f (⌧ )d⌧
t0
• which, if f (t) is continuous, satisfies the differential equation:
d
x(t) = f (⌧ ), x(t0 ) = 0
dt
• Thus, a definite integral of a known, continuous function can be
determined using methods for ODE-IVPs to compute:
x(tf )
14
Numerical Integration

• Consider the definiteZintegral:


t f

f (⌧ )d⌧
t0

• If the discontinuities in f (t) are known, then ODE-IVP solvers can be


used in the domain between the discontinuities too!

• If the discontinuities in f (t)are unknown, then Monte-Carlo methods


(discussed later are a better option).

• This approach is efficient with adaptive time stepping methods because


an appropriate spacing between points can be chosen when t
changes more or less rapidly with f (t)

• For multi-dimensional integrals, this approach is not as straightforward,


however.
15
Numerical Integration
• One alternative is integration by polynomial interpolation:
Z tf N Z
X tk N Z
X tk
f (⌧ )d⌧ = f (⌧ )d⌧ ⇡ Pk (⌧ )d⌧
t0 k=1 tk 1 k=1 tk 1

• where Pk (⌧ ) is a polynomial approximation of f (⌧ ) in the


domain
⌧ 2 [tk 1 , tk ]
• If the size of the domains of integration and the order of the
polynomial interpolant can be used to control the accuracy of the
integration.

• Example: quadratic interpolation – Simpson’s rule:


1
Pk (⌧ ) = f (tk 1 ) + (f (tk ) f (tk 1 )) (⌧ tk 1)
tk 1 tk
Z tk
1
Pk (⌧ )d⌧ = (f (tk ) + f (tk 1 )) (tk tk 1)
tk 1 2 16
Numerical Integration
• One alternative is integration by polynomial interpolation:
Z tf N Z
X tk N Z
X tk
f (⌧ )d⌧ = f (⌧ )d⌧ ⇡ Pk (⌧ )d⌧
t0 k=1 tk 1 k=1 tk 1

• where Pk (⌧ ) is a polynomial approximation of f (⌧ ) in the


domain
⌧ 2 [tk 1 , tk ]
• If the size of the domains of integration and the order of the
polynomial interpolant can be used to control the accuracy of the
integration.

• Example: quadratic interpolation – Simpson’s rule:

Z tk
1
Pk (⌧ )d⌧ = (f (tk ) + 4f ((tk + tk 1 )/2) + f (tk 1 )) (tk tk 1)
tk 1
6
17
Numerical Integration
• Multidimensional integration:

• Of the sort: Z yU Z zU
f (y, z)dydz
yL zL
• For any number of dimensions larger than 3, this is best handled
with Monte Carlo methods

• For dimensions less than 3, this integration can be done with


polynomial interpolation.

• Fit the function to a polynomial of a prescribed degree within


small regions of the domain of integration.

• Sum integrals over the polynomial fits in each fit region.

• This fails with higher dimensions because the number of fit


regions grows exponentially with dimension.

• Example:
18
Numerical Integration
• Improper integrals:
• Of the sort: Z 1
f (⌧ )d⌧
t0
• Can be split into two domains of integration
Z 1 Z tf Z 1
f (⌧ )d⌧ = f (⌧ )d⌧ + f (⌧ )d⌧
t0 t0 tf
• The first integral can be handled with ODE-IVP methods or
polynomial interpolation

• The second must be handled separately through either:


• transformation onto a finite domain
• or substitution of an asymptotic approximation
• This same idea applies to integrable singularities as well.
19
Numerical Integration
• Improper integrals:
• Example:
Z tf
cos ⌧
p d⌧
0 ⌧
Z t0 2 Z tf
1 ⌧ /2 cos ⌧
⇡ p d⌧ + p d⌧
0 ⌧ t0 ⌧
Z tf
1/2 1 5/2 cos ⌧
⇡ 2t0 t0 + p d⌧
5 t0 ⌧

20
MIT OpenCourseWare
httpV://ocw.mit.edu

10.34 Numerical Methods Applied to Chemical Engineering


Fall 2015

For information about citing these materials or our Terms of Use, visit: httpV://ocw.mit.edu/terms.

You might also like