Download Ordinary Diferential Equations Computational Physics Ordinary Diferential Equations

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Vincent's theorem wikipedia , lookup

History of Grandi's series wikipedia , lookup

List of important publications in mathematics wikipedia , lookup

Elementary mathematics wikipedia , lookup

Arithmetic wikipedia , lookup

Leonhard Euler wikipedia , lookup

Partial differential equation wikipedia , lookup

Transcript
Ordinary Diferential
Equations
Computational Physics
Ordinary Diferential Equations
Improvements on the Euler Method
Outline
Problems with Euler Method
Runge-Kutta Approach (Second Order)
Accuracy and Roundof Error
Second Order DEQ
Euler Method
Velocity
Vi
Position
Xi
Vi+1 = Vi + F/m dt
Xi+1 = Xi + Vi dt
Solve
Simultaneously
time
dt
ti
ti+1
Problems with Euler
Method
Not a good
approximation
assumes derivative is
constant in interval
i
i+1
Energy is not
conserved
periodic phenomena
can't be explored
Solution is to devise
new methods
Solution for Pendulum
with Euler Method
Runge-Kutta Approach
Mean Value Theorem
Estimate typical
derivative within the
interval by fnding its
value at some point
within the interval.
Slope used by Euler
Method to advance
calculation
i
This slope occurs
someplace within
the interval.
i+1
Runge-Kutta uses
slope found at midpoint
to advance calculation
Second Order RungeKutta: estimate typical
value of derivative from
its value at half-way
point
i
i+1/2 i+1
Second Order Runge-Kutta
Diferential
Equation
Estimate value
of y at half-step
(Euler Method)
Use value at
half-step to
fnd new estimate
of derivative
Second Order DEQ
nd
Runge-Kutta (2 Order)
Compute estimate of V and X at midpoint:
vi+1/2
F(xi ,vi ) dt
= vi + -------- ---m
2
xi+1/2
dt
= xi + vi ---2
Use midpoint values to move ahead:
vi+1 = vi +
F(xi+1/2 , vi+1/2 )
------------------- dt
m
xi+1 = xi + vi+1/2 dt
VELOCITY
POSITION
##set
setparameters
parameters
gg==9.8
9.8
X0
X0==0.0.
V0
V0==0.0.
dtdt ==2.2.
tfnal
tfnal==100.
100.
##initialize
initializearrays
arrays
tt==np.arange(0.,tfnal+dt,dt)
np.arange(0.,tfnal+dt,dt)
npoints
=
npoints =len(t)
len(t)
XX==np.zeros(npoints)
np.zeros(npoints)
VV==np.zeros(npoints)
np.zeros(npoints)
XExact
XExact==X0
X0++V0*t
V0*t--0.5*g*t**2
0.5*g*t**2
##SECOND
SECONDORDER
ORDERRUNGE_KUTTA
RUNGE_KUTTASOLUTION
SOLUTION
X[0]
=
X0
X[0] = X0
V[0]
V[0]==V0
V0
for
fori iininrange(npoints-1):
range(npoints-1):
##compute
computemidpoint
midpointvelocity
velocity
Vmid
=
V[i]
0.5*g*dt
Vmid = V[i] - 0.5*g*dt
##use
usemidpoint
midpointvelocity
velocitytotoadvance
advanceposition
position
X[i+1]
=
X[i]
+
Vmid*dt
X[i+1] = X[i] + Vmid*dt
V[i+1]
V[i+1]==V[i]
V[i]--g*dt
g*dt
WARNING!
In this example, the force is constant.
In general we would advance BOTH the
Velocity and Position solution to the
midpoint since, for example, the force
might depend on the position.
Consider a Pendulum!!
Second Order Runge-Kutta
Consider Single Step with Falling
Ball
Recall that
velocity equation
was exact for Euler.
Position equation
is now also exact
with Runge-Kutta!
and Energy is
conserved!
Accuracy Part II
Velocity equation is supposed to be exact ... but ...
comparing solution to the true answer we see that there
are small errors! Worse yet, the errors get BIGGER when
we take smaller steps. What's going on??
Roundof Error
Computers represent numbers with a
fnite number of bits, so all numbers
contain small errors: a'=a(1+ea)
Subtraction: c = a-b
c'= a'-b' = a(1+ea) – b(1+eb)
c'/c = 1 + a/c ea – b/c eb
NOTE if a,b are big and a~b then c is small and the
error can be large: c'/c ~ 1 + a/c (ea - eb)
Multiplication: c = a*b
c' = a'*b' = a(1+ea) * b(1+eb)
c'/c ~ 1 + ea + eb (relative error in c)
NOTE successive multiplications add errors like a
random walk. In this case, the total error increase
goes as sqrt(number of steps)