- #1
ChrisVer
Gold Member
- 3,378
- 464
I am trying to solve the problem 4.8 found http://phys.csuchico.edu/ayars/312/Handouts/comp-phys-python.pdf at pdf's page 115-6 [book's page 107-8].
My code so far is:
My problem is that I cannot see how I can make the w a variable... So that I could plot the amplitude vs the omega...
My code so far is:
Python:
from mytools import rungekuta4
from pylab import *
#set globals
G=9.81
MASS=1.0
K=42.0
MU=0.15
A=1.
OMEGA=0.01
#set diff solver variables
N=1000
tau=5.
dt= tau/float(N-1)
t=linspace(0,tau,N)
def Fexternal(A,w,t):
return A*cos(w*t)
def springmass(xv_vector,time):
# x' =v
# v' = -k/m x +/- mu g + F[t]
diff0= xv_vector[1]
if diff0>0:
diff1= -(K/MASS)*xv_vector[0] - MU*G + F(A,OMEGA,time) / MASS
else:
diff1= -(K/MASS)*xv_vector[0] + MU*G + F(A,OMEGA,time) / MASS
return array([diff0,diff1])
xo=1.0
vo=0.0
y=zeros([N,2])
y[0,0]=xo
y[0,1]=vo
for i in range(N-1):
y[i+1]= rungekuta4(y[i],t[i],dt,springmass)
plot(t,y[:,0],'r-')
show()
My problem is that I cannot see how I can make the w a variable... So that I could plot the amplitude vs the omega...
Last edited by a moderator: