Example computer programs
Posted: Mon Sep 25, 2006 5:44 pm
You can fnd a lot of example programs in one of the appendices of the course text.
Here are two other programs that were written during the computer turorial session on Monday, September25.
Here are two other programs that were written during the computer turorial session on Monday, September25.
Code: Select all
program prog
c this is a comment
real x(3),f(2),t,dt,m,b,k,lam,v,junk(3)
dt = 0.1
m = 1
b = 0.8
k = 4
lam = 10
v = 10
h = 0.1
x(1) = 0
x(2) = 0
open(13,file="output.d")
do 10 t=0,26,dt
f(1) = x(2)
junk(1) = k*h*sin(2*3.1415926*v*t/lam)
junk(2) = 2*3.1415926*v*h*b/lam*cos(2*3.1415926*v*t/lam)
junk(3) = -b*x(2)-k*x(1)
f(2) = 1/m*(junk(1)+junk(2)+junk(3))
x(1) = x(1) + f(1)*dt
x(2) = x(2) + f(2)*dt
write(13,*) x(1),t
10 continue
stop
end
Code: Select all
program hw5p1
real t,x(2),m,b,k,force,dt,f(2),omega
dt = 0.001
m = 1
b = 0.2
k = 4
force = 3
omega = 1
x(1) = 0
x(2) = 0
open(12,file="hw5p1.d")
do 13 t=0,30,dt
f(1) = x(2)
f(2) = 1/m*(-b*x(2) - k*x(1) + force*sin(omega*t))
x(1) = x(1) + f(1)*dt
x(2) = x(2) + f(2)*dt
write(12,*) x(1),t,force*b*omega/((k - m*omega**2)**2 +
* (b*omega)**2)*cos(omega*t) + force*(k - m*omega**2)/
* ((k - m*omega**2)**2 +(b*omega)**2)*sin(omega*t)
13 continue
stop
end