! PROGRAM Modified Euler method to solve m dv/dt= mg- bv with v(0)=0
real::t,v,g,b,m,t1,v1
f(t,v)=g-(b/m)*v
open(3,file="Mod_euler.out")
m=1.0
g=9.8
b=10.0
t=0;v=0;h=0.5
1 write(3,*)t,v
v1=v+h*f(t,v)
t1=t+h
v=v+0.5*h*(f(t,v)+f(t1,v1))
t=t1
if(t<=5) goto 1
open(4,file="analytical.out")
t=0;v=0
2 write(4,*)t,v
t=t+h
v=(m*g)/b*(1-exp(-(b/m)*t))
if(t<=5)goto 2
end
real::t,v,g,b,m,t1,v1
f(t,v)=g-(b/m)*v
open(3,file="Mod_euler.out")
m=1.0
g=9.8
b=10.0
t=0;v=0;h=0.5
1 write(3,*)t,v
v1=v+h*f(t,v)
t1=t+h
v=v+0.5*h*(f(t,v)+f(t1,v1))
t=t1
if(t<=5) goto 1
open(4,file="analytical.out")
t=0;v=0
2 write(4,*)t,v
t=t+h
v=(m*g)/b*(1-exp(-(b/m)*t))
if(t<=5)goto 2
end
Comments
Post a Comment