2014-05-17 7 views
0

물리학 수업을위한 튜토리얼을 진행하고 있습니다.스프링을 물리 치고 물리 현상을 늦추십시오.

나는 봄에 의해 움직이고 멈추어서야하는 상자에 카트가 있어야하는 프로그램을 만들었지 만, 나는 그것을 실행할 때 스프링이 카트를 가속하고있는 것처럼 보였다. 나는 무효화한다.)

vPython이 반올림 한 숫자가 가속화되는 문제가있을 수 있다고 들었는데, 이것이 사실이라면 나는 모든 숫자를 1000 배 더 크게 만들 수 있고 그것을 고칠 수 있는가?

감사합니다.

from visual import * 
from visual.graph import * 

length=1.0 

track=box(pos=vector(0,-0.05,0), 
      size=(length, 0.05, 0.10), 
      material=materials.bricks,) 

# creates the track which is "length"meters in the 
# x direction, 0.05m tall, and 1m deep 
start=-0.5*length+0.05 

cart=box(pos=vector(start+0.01,0,0), 
     size=(0.1,0.05,0.1), 
     color=color.green) 
k=-4 
#spring constant 

sprL=(start-0.05)-0.1 

#sets position of left end of spring 
spring=helix(pos=(sprL,0,0), 
      axis=((cart.x-0.05)-sprL,0,0), 
      radius=0.02, 
      color=color.yellow) 

cart.m=0.70 
#mass of cart 
cart.vel=vector(0,0,0) 
#initial velocity of cart 
cart.force = k*(cart.x)*vector(1,0,0) 
#force of the spring 
cart.accel=cart.force/cart.m 
#acceleration of the cart taking into account the fan 
t=0 
deltat=0.01 
end=0.5*length-0.05 
#defining the end of the track 
gdisplay(x=100, 
     y=500, 
     xtitle='time (sec)', 
     ytitle='X (cyan), Px (red)') 

xcurve = gcurve(color=color.cyan) 
pcurve= gcurve (color=color.red) 

while cart.x<end+0.01 and (cart.x>(start-0.01)): 
    #we include -0.01 so the cart does not fail immediately upon start... 
    cart.pos = cart.pos + cart.vel*deltat+(0.5)*(cart.accel)*deltat**2 
    #x equals x naught plus v times delta t plus one half a delta t squared 
    #note that ** means "to the power of" 
    xcurve.plot(pos=(t,cart.x)) 
    pcurve.plot(pos=(t,cart.vel.x)) 
    cart.vel=cart.vel+cart.accel*deltat 
    #new velocity is old velocity plus acceleration times time 
    cart.force=k*(cart.x)*vector(1,0,0) 
    cart.accel=cart.force/cart.m 
    spring.axis=((cart.x-0.05)-sprL,0,0)  
    t=t+deltat 
    #increments time 
    rate(100) 
    #rate means no more than 100 loops per second 
+0

코드에서 소산력을 설정하는 부분이 어디인지 모르겠습니까? 이 상자는 절대로 에너지를 잃지 않습니다. – SirGuy

+0

나는 스프링 상수 (k)를 음수로 만들었으므로 cart.force는 음수가되어 cart.accel이 음수가되어 cat.acceleration이 차감되어 cart.pos가 감소합니다 (while 루프에서). 스프링을 양수로하면 프로그램이 멈추고 작은 시간 동안 왼쪽으로 이동합니다. – hoytick

+0

[감쇠 된 고조파 발진기] (http://en.wikipedia.org/wiki/Harmonic_oscillator#Damped_harmonic_oscillator)를 찾고 계십니까? – SirGuy

답변

2

시스템에 소멸되는 힘 (에너지가 누출되는 힘)이 없습니다. 방정식 F = -kx은 에너지를 보존합니다 (이것은 방정식으로 다소 회로화되어 있으며 스프링이 물체에 가하는 힘을 나타냅니다). 방정식은 힘이 항상 음수라는 의미는 아니며 단지 반대 방향으로 cart.pos을 가리키고 있음을 유의하십시오. 이것이 사인 운동을 얻는 방법입니다.

물체가 실제로 감속하는 데 소산력이 필요합니다. 이것의 전형적인 예는 b에 대해 F = -kx -bv으로 표시되고 v은 객체의 속도입니다. 이것은 당신의 봄이 유체 (공기/물/당신이 좋아하는 것)에 의해 느려지는 것을 나타냅니다.

이 경우 코드에 최소한의 변화는 당신의 루프 내에서 다음과 같습니다

cart.force=(k*(cart.x)-0.1*cart.vel.x)*vector(1,0,0) 

이가 감쇄 시스템을 생산, 당신은 대신 0.1 10을 설정할 수 있습니다 과도 감쇄 시스템을 시도 할 수 있습니다.