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
no text concepts found
Transcript
Ordinary Diferential
Equations
Computational Physics
Ordinary Diferential Equations
Second Order ODE's
Outline
Second Order Ordinary Diferential
Equations
General Method of Solution
Euler's Method
Ordinary Diferential
Equations
First Order
Radioactive Decay
Second Order
Projectile Motion
Method for
Second Order DEQ's
Write
Second Order Equation
as
two simultaneous
First Order Equations
Second Order DEQ
Initial Conditions
First Order DEQ required specifcation
of solution at initial time.
e.g. value of N at t=0 in radioactive decay
problem.
Second Order DEQ requires initial
values for each First Order DEQ.
velocity at initial time (t=0)
position at initial time (t=0)
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
Second Order DEQ
Euler Method
Formula to obtain solution at next time step:
Fi
vi+1 = vi + ---- dt
v solution
m
xi+1 = xi + vi dt
x solution
where:
Fi = force at time step i
vi = velocity at timestep i
xi = position at timestep i
import
importnumpy
numpyas
asnp
np
##set
setparameters
parameters
gg==9.8
9.8
X0
X0==0.0.
V0
V0==0.0.
dt
dt ==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
##Euler
EulerMethod
MethodSolution
Solution
X[0]
X[0]==X0
X0
V[0]
V[0]==V0
V0
for
fori iininrange(npoints-1):
range(npoints-1):
X[i+1]
X[i+1]==X[i]
X[i]++V[i]*dt
V[i]*dt
V[i+1]
V[i+1]==V[i]
V[i]--g*dt
g*dt
##time
timearray
arraytt
##position
positionarray
arrayXX
##velocity
velocityarray
arrayVV
##exact
exactsolution
solutionfor
forXX
Xi+1 = Xi + Vi dt
Vi+1 = Vi + F/m dt
Euler Method
Consider Single Step with Falling
Ball
Velocity equation
is exact
Position equation
missing quadratic
term
Initial E:
E after
one step:
Energy is not
conserved!
Related documents