2016-04-05 11 views
0

Bir dalgıç dikey olarak aşağıya doğru suya atlar.Bir dalgıç, bir diğerinden sonra gerçek zamanlı bir grafiği çizin

Bir dalgıcın suya dalmadan önce hareketini çizmek istiyorum (t = 0'dan t = Tc'ye, suya temas ettiği anda T), her iki ekseni de zamana göre değişir, onun hareketini takip edin suya daldırıldıktan sonra (t> Tc) suya dalmadan önce hareketini betimleyen gerçek zaman grafiğini çizmeyi başardım ama suya girdiği andan sonra başka bir denklemle nasıl eklenir/değiştirilir?

Bu arada, sabit bir yatay çizgi olan su seviyesinin nasıl izlenmesi y = 0?

# -*- coding: utf-8 -*- 
from math import * 
import numpy as np 
from matplotlib import pyplot as plt 
from matplotlib import animation 


print ("Height of diver (m) and weight of diver (kg)") 
h = float(input(" height = ")) 

m = float(input(" mass = ")) 
g = 9.81     #gravity = 10 m/s^2 

Tc = sqrt(2*h/g) #Tc = the time the diver touches water 
Tc = round(Tc,2)  

Ve = g*Tc   #Ve = His initial velocity before plunging into water 
Ve = round (Ve,2) 


## movement in the water 
#calculation of velocity's limit 
dh = 0.9 #bouyancy, dh=0.9 
k = 250 #coefficient of friction , k =250 kg/s 
rate = m/k 
Vlim = rate*g*(1-(1/dh)) 

# First set up the figure, the axis, and the plot element we want to animate 
fig = plt.figure() 
ax = plt.axes(xlim=(0, 2), ylim=(-30, h+1)) #ymax : initial height+1 
line, = ax.plot([], [], ' o', lw=2) 

step = 0.1 # animation step 
xs = [1] # the vertical position is fixed on x-axis 
ys = [h] 

# animation function. This is called sequentially 
def animate(y): 
    ys[-1] = y 
    line.set_data(xs, ys) 
    return line, 

def get_y(): 
    t = 0 
    while t <= Tc: 
     y = -0.5 * g * t**2 + h # the equation of diver's displacement on y axis 
     yield y 
     t += step 

    while t > Tc: 
     y = rate*Ve*(exp(-Tc/rate)-exp(-t/rate)) + rate*(abs(Vlim))*(exp(-Tc/rate)-exp(-t/rate)) + (abs(Vlim))*(Tc-t) # equation of diver's displacement in water on y axis 
     yield y 
     t += step # Indentation Error fixed 

# call the animator. blit=True means only re-draw the parts that have changed. 
anim = animation.FuncAnimation(fig, animate, frames=get_y, interval=100) 

plt.show() 
+0

kodun 'IndentationError 'özelliği vardır; t + = step' –

+0

' taux' tanımlı değil –

+0

Üzgünüz, onu oranla değiştirdim. –

cevap

1

Şimdi kod çalışıyor:

İşte benim kodudur. I

y = -(t - Tc) 

yerine

y = rate*Ve*(exp(-Tc/rate)-exp(-t/rate)) + rate*(abs(Vlim))*(exp(-Tc/rate)-exp(-t/rate)) + (abs(Vlim))*(Tc-t) 

ve sabit bir hızla hareket eder partikül ikame test edilmiştir. Bu yüzden dalgıcınızın su uygulamasında yer değiştirmesi yanlış bir şey var gibi görünüyor.

+0

Haklısınız! Bu arada, arka planda sabit bir yatay çizgi nasıl y = 0? –

+0

Bu konu kapalı, kodunuza 'plt.axhline (0)' eklemek zorundasınız. Sorununuzu çözdüyseniz, cevabı onaylayın. –

İlgili konular