La pallina cade da 10 metri di altezza, per 2 secondi


from vpython import *
y0 = 10 # posizione imiziale
g = 9.8 # accelerazione di gravità
palla = sphere(color = color.red, make_trail = True)
graph(fast = False, xtitle = "tempo", ytitle = "posizione")
grafico = gcurve(color = color.blue, dot = True, markers = True)
t = 0
dt = 0.05
while(t < 2):
rate(20)
y = y0 - 1/2*g*t**2
palla.pos.y = y
grafico.plot(t, y)
t = t+dt
Un grafico in più dedicato all’andamento della velocità



from vpython import *
y0 = 10 # posizione iniziale
v0 = 0 # velocità iniziale
g = 9.8 # accelerazione di gravità
palla = sphere(color = color.red, make_trail = True)
g_p = graph(fast = False, xtitle = "tempo", ytitle = "posizione")
grafico_p = gcurve(color = color.blue , dot = True, markers = True)
g_v = graph(fast = False, xtitle = "tempo", ytitle = "velocità")
grafico_v = gcurve(color = color.green, dot = True, markers = True)
y = y0
v = v0
t = 0
dt = 0.05
while(t < 2):
rate(20)
dv = -g * dt
v = v + dv
dy = v * dt
y = y + dy
palla.pos.y = y
grafico_p.plot(t, y)
grafico_v.plot(t, v)
t = t+dt