You are on page 1of 7

Introduction to Computer Simulation Methods: HW1

Submitted by: Kiran Adhikari


0.0.1 Problem description
This problem is a free falling body problem in the presence of air resistance. All the forces
acting downward are considered negative while forces acting upward are considered pos-
itive. The equation of motion is thus:

d2 v k 2
= − g + v (1)
dt2 m
Here, g is the acceleration due to gravity, kv2 is the drag force and m is the mass of
falling body. The solution is obtained numerically by using Euler algorithm and Euler-
Richardson algorithm.

0.0.2 Source code


The source code for Euler Method is:
# Euler algorithm
# T h i s c o d e was w r i t t e n on Python 3 . 5 . 2 . V e r s i o n b e l o w Python 3 . 0
# m i g h t n o t run some o f t h e s e c o d e s .
import m a t p l o t l i b . pyplot as p l t
r 0 =10000 # I n i t i a l h e i g h t
v0=0 # I n i t i a l v e l o c i t y
a0 = − 9.8 # I n i t i a l a c c e l e r a t i o n
g = 9 . 8 # a c c e l e r a t i o n due t o g r a v i t y
t 0 =0 # I n i t i a l t i m e
h = 0 . 0 0 1 # Time s t e p
m=1# S i n c e mass i s 1 kg , i t i s n o t i n c l u d e d i n t h e c o d e
k=0.0003
R=[ r 0 ]
V=[ v0 ]
T=[ t 0 ]
# W h i l e l o o p r u n s u n t i l h e i g h t =0
while r0 >=0:
v1=v0+h∗ a0 # E u l e r A l g o r i t h m
r 1=r 0+h∗v0 # E u l e r A l g o r i t h m
a1=−g +( k∗v0 ∗ ∗ 2 )
t 0 = t 0 +h
V . append ( v1 )
R . append ( r 1 )
T . append ( t 0 )
v0=v1
r 0=r 1
a0=a1
# P r i n t i n g t h e number o f s t e p s
p r i n t ( ”The number o f s t e p s i s ” , len ( T ) , ” . ” )
# P l o t t i n g H e i g h t v s Time
plt . figure (1)
f=plt . plot (T ,R, ’ r ’ )
p l t . x l a b e l ( ’ Time [ s ] ’ )
p l t . y l a b e l ( ’ Height [m] ’ )
p l t . t i t l e ( ’ Height vs Time by E u l e r Method ’ )
p l t . show ( )
plt . figure (2)
# P l o t t i n g V e l o c i t y v s Time
p l t . p l o t ( T , V, ’ r ’ )
p l t . x l a b e l ( ’ Time [ s ] ’ )
p l t . y l a b e l ( ’ V e l o c i t y [m/s ] ’ )
p l t . t i t l e ( ’ V e l o c i t y vs Time by E u l e r Method ’ )
p l t . show ( )
The source code for Euler-Richardson Method is:

# Euler richardson algorithm


# This code was w r i t t e n on Python 3 . 5 . 2 . Version below Python 3 . 0 might not r
import m a t p l o t l i b . pyplot as p l t
# I n i t i a l conditions
r 0 =10000 # I n i t i a l h e i g h t
v0=0 # I n i t i a l v e l o c i t y
a0 = − 9.8 # I n i t i a l a c c e l e r a t i o n
g = 9 . 8 # a c c e l e r a t i o n due t o g r a v i t y
t 0 =0 # I n i t i a l time
h = 0 . 0 0 1 #Time s t e p
k=0.0003
R=[ r 0 ]
V=[ v0 ]
T=[ t 0 ]
# While loop runs u n t i l h e i g h t =0
while r0 >=0:
# E u l e r −Richardson Algorithm
vmid=v0 + ( 0 . 5 ∗ a0 ∗h )
rmid=r 0 + ( 0 . 5 ∗ v0∗h )
amid=−g +( k∗vmid ∗ ∗ 2 )
v1=v0+amid∗h
r 1=r 0+vmid∗h
a0=−g +( k∗v1 ∗ ∗ 2 )
t 0 = t 0 +h
V . append ( v1 )
R . append ( r 1 )
T . append ( t 0 )
v0=v1
r 0=r 1
p r i n t ( ” The number o f s t e p s i s ” , l e n ( T ) , ” . ” )
plt . figure (1)
plt . plot (T ,R, ’ r ’ )
p l t . x l a b e l ( ’ Time [ s ] ’ )
p l t . y l a b e l ( ’ Height [m] ’ )
p l t . t i t l e ( ’ Height vs Time by E u l e r Richardson Method ’ )
p l t . show ( )
plt . figure (2)
p l t . p l o t ( T , V, ’ r ’ )
p l t . x l a b e l ( ’ Time [ s ] ’ )
p l t . y l a b e l ( ’ V e l o c i t y [m/s ] ’ )
p l t . t i t l e ( ’ V e l o c i t y vs Time by E u l e r Richardson Method ’ )
p l t . show ( )

0.0.3 Check validation


Check validation I performed are:

1. Since there is an air resistance acting on the falling body, the falling body will attain
the terminal velocity. This terminal velocity can be calculated by letting acceleration
term in equation 1 zero.
0
d2 v k 02
= − g + v =0 (2)
dt2 m
q
0 gm
This will give terminal velocity v = k . For our specific problem, this turns out
to be 180.73 m/s.

2. Since this body is falling with velocity damping, the time of fall gets longer than
without velocity damping. This can be checked by plotting graph without and with
air resistance.

0.0.4 Graphs
Here, the mass of the falling body is 1 kg falling from a heightof 10,000 with drag coeffi-
cient k=3 ∗ 10− 4 kg/m.
Figure 1: Height vs Time using Euler algorithm[No.of steps=68102]

Figure 2: Velocity vs Time using Euler algorithm[No. of steps=68102]


Figure 3: Height vs Time using Euler Richardson algorithm[No.of steps=68102]

Figure 4: Velocity vs Time using Euler Richardson algorithm[No. of steps=68102]


0.0.5 Code checking
1. From both methods we can see that terminal velocity is around 180 m/s as we pre-
dicted analytically.
q
2. The time of flight without air resistance is obtained from equation t = 2h g = 44.5
seconds. In our graph, the time of flight is 68.7 seconds which is much longer than
without air resistance.

0.0.6 No. of iterations


The graph for velocity vs Time in Euler method for iterations(9,15,69,682,6811,68102,6810046)
is plotted in figure 5. It can be seen that, with increasing number of steps, we get more
stable results. There are big fluctuations for small no. of iterations while increasing it-
erations, these fluctuations decreases. The no. of iterations for getting stable results is
around 680 for euler method.

Figure 5: *
Velocity vs Time using Euler algorithm: iterations(9,15,69,682,6811,68102,6810046)

The graph for velocity vs Time in Euler richardson methods for iterations(8,15,69,683,6811,68102)
is plotted in figure 6.
Figure 6: *
Velocity vs Time using EulerRichardson algorithm: iterations(9,15,69,682,6811,68102)

It has also similar behavior in terms of stability like Euler method however, it gets
stable with even lower number of iterations. Thus, number of iterations to get stable is
around 680.
It is clear from figure 5 and 6 that there is a difference in the possible time steps in these
different schemes. In general, eulerrichardson gets stable even with larger time steps
while this is not true for euler algorithm.

You might also like