Body falling in a viscous medium using Euler method

Theory

Weight of body Mg=density*g*Volume
Upward thrust=Volume*d2*g
resultant downward force=V*d1*g-V*d2*g

Program:
#Simulation of a body falling in a viscous medium using Euler method
#Falling of a body through viscous medium
#Loss of weight   V*d1*g-V*d2*g=V*d1*g(1-d2/d1)=m*a where a=g(1-d2/d1)
#Drag in the case of ball 6*pi*eta*a*v=k*v
#dy/dt=v
#dv/dt=a-kv
from pylab import*
from math import*
d1=2000.0 #density of body
d2=750.0 #density of liquid
g=9.8
height=2000
y0=0
v0=0
a=(1.0- d2/d1)*g #including buoyant force
k=0.2 #drag coefficient
h=0.001
t=0
y=[y0]
v=[v0]
time=[t]
while height-y0>0:
    v1=v0+h*(a-k*v0)
    y1=y0+h*v0
     t=t+h
    y.append(height-y1)
    v.append(fabs(v1))
    time.append(t)
    y0=y1
    v0=v1
figure(1)
title("Fall through viscous medium")
xlabel(" Time")
ylabel("Position")
plot(time,y)
figure(2)
title("Fall through viscous medium")
xlabel(" Time")
ylabel("Velocity")
plot(time,v)
show()

Output  plot
 

Comments