Week2 ODEs
-
Upload
sadiq-sarfaraz -
Category
Documents
-
view
260 -
download
0
Transcript of Week2 ODEs
-
8/13/2019 Week2 ODEs
1/32
Friday, March 15, 13
-
8/13/2019 Week2 ODEs
2/32
CLASS II : Ordinary Differential Equations
Example : Newtons Equation of Motion
m d ~ v (t )
dt =
~
F (t )
~ v (t ) = d ~ x ( t )
dt
m : mass, ~ x (t ) : position , ~ v(t ) : velocity, ~
F (t) : Forcem d
2 ~
x (t )dt 2
= ~
F (t )
First or er High r erSingle equation Systems of equations
Linear Non-linearHomogenous Inhomogenous
Initial Value Problem (IVP) Boundary Value Problem (BVP)
CLASSIFICATIONS of ODEs
Friday, March 15, 13
-
8/13/2019 Week2 ODEs
3/32
CLASS II : Ordinary Differential Equations
Almost all equations of higher order can be reduced to first order equations
d ~ x
dt =
~ u
d ~ u
dt =
~
F
m
d 2~
xdt
=
~
F m
2nd order ODE
System of 1st Order ODEs
More generally: y( n ) = f (x, y, y . . . , y ( n 1) )
we set: y1 = y
y j = y(j 1) , j = 2 , . . . , n 1
y 0j = yj +1 , j = 1 , 2, . . . , n 1y 0n = f (x,y,y 1 , . . . , y n )
To obtain:
Friday, March 15, 13
-
8/13/2019 Week2 ODEs
4/32
Numerical Differentiation
How to estimate derivatives in the computer?
Estimate derivatives of a function using a finite set of points.
Assume that the data are the exact values of a smooth function at the data points andfurther, that the derivatives are needed only at the data points.
There are 3 ways to do this:1.INTERPOLATE: Then differentiate the interpolant
2.TAYLOR SERIES
: more effort but have error estimates3.INTEGRATE the ODEs using numerical quadrature
Friday, March 15, 13
-
8/13/2019 Week2 ODEs
5/32
1. INTERPOLATION
INTERPOLATION
Use Lagrange interpolation: (1st order) (linear interpolation)
f (x ) i
x i x i 1f (x i 1 ) +
i 1
x i x i 1f (x i ) on x i 1 x x i
Differentiating this function we nd that its derivative is:
Backward Derivative
Forward Derivative
f 0 (x i 1 ) D + f = f i f i 1
h i
f 0 (x i ) D f = f i f i 1
h iwith f i = f (x i ) & h i = x i x i 1
Friday, March 15, 13
-
8/13/2019 Week2 ODEs
6/32
INTERPOLATION (Cont.)
Differentiating this expression and evaluating at the central point of this interval x_i, we get for h_i = h_{i-1} = h
f 0 (x i ) f i +1 f i 1
2h =
1
2(D + D )f (central di ff erences)
f 0 (x i 1 ) 3f i 1 + 4 f i f i +1
2h
f 0 (x i +1 ) f i 1 3f i 3f i +1
2h
Higher order formulas can be obtained by using the quadratic Lagrange polynomial
f (x ) = (x x i )(x x i +1 )
(x i 1
x i )(x i 1
x i +1 )f i 1 +
x x i 1 )(x x i +1 )
(x i
x i 1 )(x i
x i +1 )f i +
(x x i 1 )(x x i )
(x i +1
x i 1 )(x i +1
x i )f i +1
We can also differentiate {LagrangePolynomial} to get a second order derivative
f 00 f i 1 2 f i + f i +1
h2
= D + D = D D + f
Friday, March 15, 13
-
8/13/2019 Week2 ODEs
7/32
2. TAYLOR SERIES
Start from f (x h ) = f (x ) hf 0 (x ) + h 2
2 f 00 (x ) . . .
and form linear combinations of the function at various mesh points
af (x h ) + bf (x ) + cf (x + h)=( a + b + c)f (x ) + ( c a )hf 0 (x )+
(c + a)1
2h 2 f 00 (x ) + ( c a )
1
6h 3 f 000 (x ) + h.o.t.
Since we wish to approximate $f'(x)$ we wish that coefcientsof f' are 1 and as many of the others are equal to 0
a + b + c = 0
c a =1
h
c + a = 0
Higher Accuracy can be obtained with More points. That can be more expensive and may be problematic with boundary conditions
c = a = 1
2 h and b = 0
Solve to get:
12h
f (x h ) + 12h
f (x + h)= f 0 (x ) + 16
h 2 f 000 (x ) + h.o.t.SUBSTITUTE
EXAMPLE: construct an approximation for the rst derivative of the function at x using values at f(x-h), f(x), f(x+h).
x, x , x 2
Friday, March 15, 13
-
8/13/2019 Week2 ODEs
8/32
3. INTEGRATE : Numerical Quadrature
dy
dx = f (x, y ) y(x ) = y(0) +
Z
x
0
f (x 0 , y ) dx 0
We can apply any type of quadrature rule for computing
Suppose at x = x n we have y (x ) = y (x n ) = y n .How to compute y (x n +1 ) = y n +1 at x n +1 ?
y(x n +1 ) = y(x n ) + Z x n +1
x n
f (x 0 , y ) dx 0
Forward: Z x n +1
x n
f (x, y ) dx hf (x n , y n ) yn +1 = yn + hf (x n , y n ) (Explicit Euler)
Backward: Z x n +1
x n
f (x, y ) dx hf (x n +1 , y n +1 ) yn +1 = yn + hf (x n +1 , y n +1 ) (Implicit Euler)
Midpoint: Z x n +1
x n
f (x, y ) dx hf (x n + 12
, y n + 12
) yn +1 = yn 1 + 2hf (x n , y n ) (Leap-frog)
Trapezoidal: Z x n +1
x n
f (x, y ) dx h2
[f (x n , y n ) + f (x n +1 , y n +1 )] yn +1 = yn + h2
[f (x n , y n ) + f (x n +1 , y n
Friday, March 15, 13
-
8/13/2019 Week2 ODEs
9/32
STABILITY OF ODEs
Use of a model equation to study the stability behavior of various numerical schemes
dx
dt = x
Note that this model can be related to any generic right hand side as:
f (x, t ) = f (x 0 , t 0 ) + ( x x 0 ) f x
+ ( t t 0 ) f t
+ h.o.t.
So we write
Stability is determined by the term
dxdt
= f (x, t ) x + ( 0 + 1 t )
Return to Model Equation the solution is: x (t ) = x 0 e t
Friday, March 15, 13
-
8/13/2019 Week2 ODEs
10/32
STABILITY OF NUMERICAL METHODS
Forward Euler:
Note that :
Euler's method reproduces the rst two terms so it is rst order accurate
xn +1 = x n + h x n x n +1 = x n (1 + h )
x n = x 0 (1 + h ) n
e h = 1 + h + 12
( h )2 + . . .
What if then = k + i e h = ekh (cos h + i sin h )
Friday, March 15, 13
-
8/13/2019 Week2 ODEs
11/32
BREAK
Friday, March 15, 13
-
8/13/2019 Week2 ODEs
12/32
d~
x idt =
~
u i , i = 1 , . . . , N
md
~
u idt
= ~
F i , i = 1 , . . . , N
N-body Problems
Particles moving according to Newtons Laws of Motion:
d ~ x
dt =
~ u
m
d ~ u
dt =
~
F
One Particle:
N Particles:(N-body Problem)
~
F i = ~
F i (m 1 , . . . , m N , ~ x 1 , . . . , ~ x N )
Friday, March 15, 13
-
8/13/2019 Week2 ODEs
13/32
Time Integrators for ODEs in Particle Methods
The beating heart of any Particle simulation :
Replace Ordinary Differential Equations with Difference Equations
Approximate solution snapshots at discrete steps
QUESTIONS
What properties of the continuous system must be preserved in the discrete ?
How accurate ? How to design schemes that respect physical principles regardless of classical
accuracy requirements ?
Friday, March 15, 13
-
8/13/2019 Week2 ODEs
14/32
Time integration schemes for particle methods
Particle ODEs
Example: For a particle with charge q moving in an electric field Eand magnetic field B, F is the sum of the electrical force qE andthe magnetic force (Lorentz force) qu x B).
Each particle is described by a set (x,u,m).
Friday, March 15, 13
-
8/13/2019 Week2 ODEs
15/32
Example : The Leapfrog scheme
The Leapfrog Scheme:
In general
If bk is zero the scheme is explicit , else it is implicit andsolutions are found iteratively .
Friday, March 15, 13
-
8/13/2019 Week2 ODEs
16/32
Time integration schemes for particle methods
Criteria to select a scheme:
Consistency,
Accuracy,
Stability ,
Efficiency
Important notions for Certain Physical Systems:Preservation of time symmetriesConservation of physical quantities such as E, mu.
Friday, March 15, 13
-
8/13/2019 Week2 ODEs
17/32
CONSISTENCY
is consistent with
Why ?
Eulerscheme
The approximate scheme is consistent with the
systems it approximates
EXAMPLE
Taylor series expansion:
Friday, March 15, 13
-
8/13/2019 Week2 ODEs
18/32
ACCURACY
Accuracy : The deviation of the computed values of position andvelocities from what the code gives are small.
Accuracy is concerned with local errors, i.e. with truncation errorscaused by representing continuous variables by a discrete set ofpoints.
Friday, March 15, 13
-
8/13/2019 Week2 ODEs
19/32
STABILITY and Eigenvalues
Understand stability through an example ofthe harmonic oscillator
Asymptotically StableA numerical method is asymptotically stable if the growth
of the solution for a linear model problem is asymptoticallybounded
ConditionsEigenvalues (of the linear model problem) must be on orinside the unit disk of the complex plane and not repeatedif on the unit circle
Examples of Numerical Methods: Explicit Euler
Strmer-VerletFriday, March 15, 13
-
8/13/2019 Week2 ODEs
20/32
Time symmetry
Example:The leapfrog scheme is time centered, since
A desired property for particle integrators is that they reflect
time symmetry.
The particle equations are time reversible . Time reversibleapproximations are obtained by defining time-centered
derivatives.
is centered around
is centered around
Friday, March 15, 13
-
8/13/2019 Week2 ODEs
21/32
Time integration schemes for particle methods
and the right hand side is centered around
It is not always practical to employ properly time-centeredschemes as generally they lead to implicit equations in variablesat the new time level.
The Euler scheme is not time centered as
is centered around
Friday, March 15, 13
-
8/13/2019 Week2 ODEs
22/32
Time Reversible schemes
Consider:
Time reversibility ! Often implicit schemes!
Friday, March 15, 13
-
8/13/2019 Week2 ODEs
23/32
Conservative Systems
If ~
F i = ~ x i V (~
x 1 , . . . ,~
x N )
~
F i is a conservative force
Conservative System: A system with an energy functionthat is constant along a trajectory(in the phase space )( ~ x, ~ u )
Examples: (1) Gravitation (2) Molecular Dynamics (3) Wave Equation
Friday, March 15, 13
-
8/13/2019 Week2 ODEs
24/32
Solving Mechanical Systems
M d ~ x
dt 2 = V
Rewrite using velocity: and~ u =d ~ x
dt M
d ~ u
dt = V
- Use different approximations (time integrators) fordifferent components of the solution
- Useful when there is a dichotomy between velocitiesand positions
Examples:(1) Partitioned Runge Kutta Methods(2) Asymmetric Euler A(3) Asymmetric Euler B(4) Strmer-Verlet Methods and Alternatives
Friday, March 15, 13
-
8/13/2019 Week2 ODEs
25/32
Time Integrators : The Verlet Algorithm
The Verlet algorithm (1967)Use positions r(t), accelerations a(t) and r(t-dt), velocities do notappear.
r(t+dt) = r(t) + dt*u(t) + dt 2*a(t)/2 + dt 3*a(t) + O(dt 4)
r(t-dt) = r(t) dt*u(t) + dt2
*a(t)/2 - dt3
*a(t) + O(dt4
) Add these two expressions to get :
r(t+dt) = 2*r(t) - r(t-dt) + a(t)*dt 2 + O(dt 4)
This is equivalent to central differences of the 2nd derivative We need the velocities to compute the kinetic energy:
u(t) = (r(t+dt) - r(t-dt))/2dt + O (dt^2)
Friday, March 15, 13
-
8/13/2019 Week2 ODEs
26/32
The Verlet Algorithm
Note that u(t) can be computed only after r(t+dt) is available, which is somewhat awkward.
It is properly centered, r(t+dt) and r(t-dt) play symmetricalroles which makes it time reversible.
Advancement of positions take place in one go as opposedto the two-stages in the Predictor-corrector algorithm.
It is guaranteed to conserve linear momentum and energy.
Also note that in r(t+dt) and r(t-dt) a small term dt2
a(t) isadded to a difference of large terms O(dt) in order tointroduce the trajectory.
Friday, March 15, 13
-
8/13/2019 Week2 ODEs
27/32
Modified Verlet Algorithms
Modification I:
u(t+dt/2) = u(t-dt/2) + dt*a(t)
r(t+dt) = r(t) + dt u(t+dt/2)
Store r(t), a(t), u(t-dt/2)u(t) = ! [u(t+dt/2) + u(t-dt/2) ]
The Energy at time t can be calculated
This scheme is algebraically equivalent to Verlet, thevelocities appear explicitly but not at time (t)
Less roundoff error problems
Friday, March 15, 13
-
8/13/2019 Week2 ODEs
28/32
R K M h d
-
8/13/2019 Week2 ODEs
29/32
Runge Kutta Methods
(1) Higher order methods(2) Do not require knowing past values of the solution (Still one step methods)(3) Evaluate s stages
~ x k +1 = ~ x k + ts
Xi =1
bi ~ f (~ x i )
~ x i = ~ x k + tsX
i =1
ij ~ f (~ x j ) i = 1 , . . . s
Friday, March 15, 13
Partitioned Runge Kutta Methods
-
8/13/2019 Week2 ODEs
30/32
use RK with { ij , bi } to discretize
Partitioned Runge Kutta Methods
Runge Kutta Nystrm Methods
d~
xdt =
~
g(~
x,~
u )d
~
udt
= ~
h ( ~ x, ~ u )
use RK with { ij , bi } to discretize
Friday, March 15, 13
S V l M h d
-
8/13/2019 Week2 ODEs
31/32
Strmer-Verlet Method
Step 1: M ~ u n + 12 = M ~ u n t
2 V (~ x n )
M ~ u n +1 = M ~ u n + 12 t
2 V (~ x n +1 )
~ x n +1 = ~ x n + t ~ u n + 12Step 2:
Step 3:
Alternative 1: solve the velocity at half steps onlyAlternative 2: eliminate the velocity
Friday, March 15, 13
P i l M d l
-
8/13/2019 Week2 ODEs
32/32
PhysicalSystem Model(Differential Equations) Simulation(Difference Equations)
want to maintain geometricproperties of physical system(i.e conservative systems)
Particle Methods (N body problem)Solve using time integratorsODEs = DEs(accuracy and stability )
Particle Models