GIDForums  

Go Back   GIDForums > Computer Programming Forums > Python Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 29-May-2009, 14:30
Zane Zane is offline
New Member
 
Join Date: May 2009
Posts: 1
Zane is on a distinguished road

Modeling physics


I am programming in python and know some C++ as well so I can interpret something similar to those two. I have written a programme that models a mass on a spring in harmonic motion with a damping force. It displays a graph in phase space and on a velocity and position vs. time graph. I would like to add in an extra force that will only activate if the amplitude of the velocity and position curve drops below some minimum. Essentially like giving the spring a little push when it's velocity drops too low. Any help on how to do so would be greatly appreciated. The program is below in python programming language which is similar to C++, comments follow #

Python Code:
from scipy import *
from pylab import *

k=0.05        #Define constants (k=spring constant,b=damping force,m=mass on spring)
b=0.1
m=5
npts= 100000
v=zeros(npts) #Define arrays for velocity, position, and time
x=zeros(npts)
t=zeros(npts)
v[0]=30.00    #Initialize arrays      
x[0]=5.00
t[0]=0.00
dt=0.01
for i in arange(npts-1):
    v[i+1]=v[i]+dt*(-k*x[i]-b*v[i]+sin(0.01*t[i]))/m #Difference equation for velocity
    x[i+1]=x[i]+ v[i]*dt  #Difference equation for position
    t[i+1]=t[i]+dt        #time euation
figure(1)            #the phase plot
plot(v,x)
grid(True)           #shows grid on the graph
ylabel('velocity')
xlabel('position')
figure(2)            #time plots of v and x
plot(t,v,'-',label='velocity')
plot(t,x,'--',label='position')
legend()             #shows the labels on graph
xlabel('Time')
show()
Last edited by admin : 30-May-2009 at 04:16. Reason: Please insert your example Python codes between [PY] and [/PY] tags
 
 

Recent GIDBlogProblems with the Navy (Enlisted) by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Make my modeling portfolio! keme15 Open Discussion Forum 1 19-Oct-2008 15:26
My First Attempted at 3D Modeling pcxgamer Graphics Forum 24 21-Nov-2003 18:02
3D Modeling pcxgamer Graphics Forum 7 17-Aug-2003 05:28

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 18:54.


vBulletin, Copyright © 2000 - 2010, Jelsoft Enterprises Ltd.