!PROGRAM to solve second order ODE of the form d^2xdt^2 + x = 0
!One-dimensional harmonic oscillator using Euler Method
real::t,v,x,dt
integer::time=20
open(1,file="harmonic_oscillator.out")
open(2,file="harmonic_oscillator1.out")
t=0;x=0.1;v=0;dt=0.1
write(1,*)t,x
1 v=v-dt*x
x=x+dt*v
if(t<=time) then
t=t+dt
write(1,*)t,x
write(2,*)x,v
go to 1
endif
end
!One-dimensional harmonic oscillator using Euler Method
real::t,v,x,dt
integer::time=20
open(1,file="harmonic_oscillator.out")
open(2,file="harmonic_oscillator1.out")
t=0;x=0.1;v=0;dt=0.1
write(1,*)t,x
1 v=v-dt*x
x=x+dt*v
if(t<=time) then
t=t+dt
write(1,*)t,x
write(2,*)x,v
go to 1
endif
end
Comments
Post a Comment