Você está na página 1de 32

Friday, March 15, 13

CLASS II : Ordinary Differential Equations


d~ v ( t) ~ ( t) m =F dt

Example : Newtons Equation of Motion


~ (t) : Force m : mass, ~ x(t) : position, ~ v (t) : velocity, F

d~ x ( t) ~ v ( t) = dt

d2 ~ x ( t) ~ ( t) m = F dt2

CLASSIFICATIONS of ODEs

First order Single equation Linear Homogenous Initial Value Problem (IVP)

High Order Systems of equations Non-linear Inhomogenous Boundary Value Problem (BVP)

Friday, March 15, 13

CLASS II : Ordinary Differential Equations


2nd order ODE

~ d2 ~ x F = dt m

d~ x =~ u dt ~ d~ u F = dt m

System of 1st Order ODEs

Almost all equations of higher order can be reduced to first order equations

More generally: y (n) = f (x, y, y . . . , y (n1) ) we set: To obtain:


y1 = y yj = y
0 yj 0 yn
(j 1)

j = 2, . . . , n 1

= yj +1 ,

= f (x, y, y1 , . . . , yn )

j = 1, 2, . . . , n 1

Friday, March 15, 13

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 and
further, 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 estimates 3.INTEGRATE the ODEs using numerical quadrature

Friday, March 15, 13

1. INTERPOLATION
INTERPOLATION
Use Lagrange interpolation: (1st order) (linear interpolation)
f ( x) xi x x x i 1 f ( x i 1 ) + f (xi ) on xi1 x xi x i x i 1 x i x i 1

Differentiating this function we nd that its derivative is:


f i f i 1 Backward Derivative f (xi1 ) D+ f = hi f i f i 1 0 Forward Derivative f ( xi ) D f = hi with fi = f (xi ) & hi = xi xi1
0

Friday, March 15, 13

INTERPOLATION (Cont.)
Higher order formulas can be obtained by using the quadratic Lagrange polynomial

(x xi )(x xi+1 ) x xi1 )(x xi+1 ) (x xi1 )(x xi ) f ( x) = f i 1 + fi + fi+1 (xi1 xi )(xi1 xi+1 ) (xi xi1 )(xi xi+1 ) (xi+1 xi1 )(xi+1 xi )
Differentiating this expression and evaluating at the central point of this interval x_i, we get for h_i = h_{i-1} = h

fi+1 fi1 1 f ( xi ) = (D+ D )f (central dierences) 2h 2 3fi1 + 4fi fi+1 0 f ( x i 1 ) 2h fi1 3fi 3fi+1 0 f (xi+1 ) 2h
0
We can also differentiate {LagrangePolynomial} to get a second order derivative

fi1 2fi + fi+1 f = D+ D = D D+ f 2 h


00
Friday, March 15, 13

2. TAYLOR SERIES
2 h 0 00 f ( x h ) = f ( x ) hf ( x ) + f ( x) . . . Start from 2
and form linear combinations of the function at various mesh points

x, x h, x 2h

EXAMPLE: construct an approximation for the rst derivative of the function at x using values at f(x-h), f(x), f(x+h).

af (x h) + bf (x) + cf (x + h)=(a + b + c)f (x) + (c a)hf 0 (x)+ 1 2 00 1 3 000 (c + a) h f (x) + (c a) h f (x) + h.o.t. 2 6
Solve to get:

Since we wish to approximate $f'(x)$ we wish that coefcients of f' are 1 and as many of the others are equal to 0

a+b+c=0 1 ca= h c+a=0

c = a =

1 and b = 0 2h

SUBSTITUTE

1 1 1 2 000 0 f ( x h) + f (x + h)=f (x) + h f (x) + h.o.t. 2h 2h 6

Higher Accuracy can be obtained with More points. That can be more expensive and may be problematic with boundary conditions
Friday, March 15, 13

3. INTEGRATE: Numerical Quadrature


dy = f (x, y ) y (x) = y (0) + dx Z
x 0

f (x0 , y ) dx0

Suppose at x = xn we have y (x) = y (xn ) = yn . How to compute y (xn+1 ) = yn+1 at xn+1 ?


We can apply any type of quadrature rule for computing

y (xn+1 ) = y (xn ) +

xn+1 xn

f (x0 , y ) dx0

Forward: Backward: Midpoint: Trapezoidal:

Z Z Z Z

xn+1 xn xn+1 xn xn+1 xn xn+1 xn

f (x, y ) dx hf (xn , yn ) yn+1 = yn + hf (xn , yn ) (Explicit Euler) f (x, y ) dx hf (xn+1 , yn+1 ) yn+1 = yn + hf (xn+1 , yn+1 ) (Implicit Euler) f (x, y ) dx hf (xn+ 1 , yn+ 1 ) yn+1 = yn1 + 2hf (xn , yn ) (Leap-frog) 2 2 f (x, y ) dx h h [f (xn , yn ) + f (xn+1 , yn+1 )] yn+1 = yn + [f (xn , yn ) + f (xn+1 , yn+1 )] 2 2

Friday, March 15, 13

STABILITY OF ODEs
Use of a model equation to study the stability behavior of various numerical schemes

dx = x dt
Note that this model can be related to any generic right hand side as:

f f f (x, t) = f (x0 , t0 ) + (x x0 ) + ( t t0 ) + h.o.t. x t


So we write

dx = f (x, t) x + (0 + 1 t) dt

Stability is determined by the term Return to Model Equation the solution is:

x ( t) = x 0 e

Friday, March 15, 13

STABILITY OF NUMERICAL METHODS


Forward Euler: xn+1 = xn + h xn xn+1 = xn (1 + h)
xn = x0 (1 + h) e
h n

Note that :

1 2 = 1 + h + ( h) + . . . 2

Euler's method reproduces the rst two terms so it is rst order accurate

What if

= k + i

then e

=e

kh

(cos h + i sin h)

Friday, March 15, 13

BREAK

Friday, March 15, 13

N-body Problems
Particles moving according to Newtons Laws of Motion:

One Particle:

d~ x dt d~ u m dt

= ~ u = ~ F

N Particles: (N-body Problem)

d~ xi dt d~ ui m dt

= ~ ui , = ~i , F

i = 1, . . . , N i = 1, . . . , N

~i = F ~i (m1 , . . . , mN , ~ F x1 , . . . , ~ xN )
Friday, March 15, 13

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

Time integration schemes for particle methods


Particle ODEs

Example: For a particle with charge q moving in an electric field E


and magnetic field B, F is the sum of the electrical force qE and the magnetic force (Lorentz force) qu x B).

Each particle is described by a set (x,u,m).

Friday, March 15, 13

Example : The Leapfrog scheme

The Leapfrog Scheme:

In general

If bk is zero the scheme is explicit, else it is implicit and


solutions are found iteratively.

Friday, March 15, 13

Time integration schemes for particle methods


Criteria to select a scheme:

Consistency, Accuracy, Stability , Efficiency

Important notions for Certain Physical Systems:


Preservation of time symmetries Conservation of physical quantities such as E, mu.
Friday, March 15, 13

CONSISTENCY
The approximate scheme is consistent with the systems it approximates EXAMPLE
Euler scheme is consistent with

Why ?
Taylor series expansion:

Friday, March 15, 13

ACCURACY

Accuracy : The deviation of the computed values of position and


velocities from what the code gives are small.

Accuracy is concerned with local errors, i.e. with truncation errors


caused by representing continuous variables by a discrete set of points.

Friday, March 15, 13

STABILITY and Eigenvalues


Understand stability through an example of the harmonic oscillator
Asymptotically Stable A numerical method is asymptotically stable if the growth of the solution for a linear model problem is asymptotically bounded Conditions Eigenvalues (of the linear model problem) must be on or inside the unit disk of the complex plane and not repeated if on the unit circle Examples of Numerical Methods: Explicit Euler Strmer-Verlet
Friday, March 15, 13

Time symmetry
A desired property for particle integrators is that they reflect
time symmetry.

The particle equations are time reversible. Time reversible


approximations are obtained by defining time-centered derivatives.

Example:
The leapfrog scheme is time centered, since is centered around is centered around

Friday, March 15, 13

Time integration schemes for particle methods

It is not always practical to employ properly time-centered


schemes as generally they lead to implicit equations in variables at the new time level.

The Euler scheme is not time centered as


is centered around

and the right hand side is centered around

Friday, March 15, 13

Time Reversible schemes

Consider:

Time reversibility ! Often implicit schemes!

Friday, March 15, 13

Conservative Systems
~i = ~ If F x1 , . . . , ~ xN ) xi V (~ ~i is a conservative force F

Conservative System: A system with an energy function that is constant along a trajectory (in the phase space (~ x, ~ u)) Examples: (1) Gravitation (2) Molecular Dynamics (3) Wave Equation
Friday, March 15, 13

Solving Mechanical Systems


d2 ~ x M 2 = V dt

Rewrite using velocity:

d~ x ~ u= and dt

d~ u M = V dt

- Use different approximations (time integrators) for different components of the solution - Useful when there is a dichotomy between velocities and 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

Time Integrators : The Verlet Algorithm


The Verlet algorithm (1967)
Use positions r(t), accelerations a(t) and r(t-dt), velocities do not appear. r(t+dt) = r(t) + dt*u(t) + dt2*a(t)/2 + dt3*a(t) + O(dt4) 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)*dt2 + O(dt4)

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

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 symmetrical


roles which makes it time reversible.

Advancement of positions take place in one go as opposed


to 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 dt2a(t) is
added to a difference of large terms O(dt) in order to introduce the trajectory.

Friday, March 15, 13

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, the
velocities appear explicitly but not at time (t)

Less roundoff error problems

Friday, March 15, 13

The Velocity Verlet Algorithm


The Velocity Verlet Algorithm
r(t+dt) = r(t) + dt*u(t) + dt2*a(t)/2 + " u(t+dt) = u(t) + dt*(a(t) + a(t+dt))/2

This is again algebraically equivalent to Verlet. In practice, compute new positions and velocity
r(t+dt) = r(t) + dt*u(t) + dt2a(t)/2 u(t+dt/2) = u(t) + dt*a(t)/2

Then forces (accelerations) are computed at t+dt and the


velocity move is completed: u(t+dt) = u(t+dt/2) + dt*a(t+dt)/2

Friday, March 15, 13

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
s X i=1 i ~ bi f (~ x)

~ xk+1 = ~ xk + t ~ x =~ xk + t
i

s X i=1

j ~ ij f (~ x ) i = 1, . . . s

Friday, March 15, 13

Partitioned Runge Kutta Methods

Runge Kutta Nystrm Methods


d~ x dt d~ u dt = ~ g (~ x, ~ u) = ~ h(~ x, ~ u)
use RK with { ij , bi } to discretize use RK with { ij , bi } to discretize

Friday, March 15, 13

Strmer-Verlet Method
t = M~ un V (~ xn ) 2 t V (~ xn+1 ) 2

u n+ 1 Step 1: M ~ 2

xn+1 = ~ xn + t~ un+ 1 Step 2: ~ 2 un+1 = M ~ u n+ 1 Step 3: M ~ 2

Alternative 1: solve the velocity at half steps only Alternative 2: eliminate the velocity

Friday, March 15, 13

Particle Models
Physical System Model Simulation
(Difference Equations)

(Differential Equations)

want to maintain geometric properties of physical system (i.e conservative systems)

Particle Methods (N body problem) Solve using time integrators ODEs = DEs (accuracy and stability)

Friday, March 15, 13

Você também pode gostar