0

Okay so I'm making a code for simulating projectile motion in python, ideal case, we need to graph the difference between the velocity when the projectile is launched at 9 different angles. So I'm wondering if there is a way to avoid making 9 different arrays to store the results for graphing, like it would be nice if i could make the calculation and print the graph, store it, and use the same array for the next angle value. ill leave my lil code.

import matplotlib.pyplot as plt
import math

print('Movimiento de un Proyectil')
v = eval(input('Ingrese el valor de la velocidad inicial '))  #pedimos valor inicial
dt = eval(input('Ingrese el salto que desee '))

g = 9.81
pasos = 200
angulos = [10,20,30,40,50,60,70,80,85]
n = 9

x = []
y = []
ti = []
vx = []
vy = []
t = 0

a1= math.radians(10)
vi = v*(math.cos(a1))
vj = v*(math.sin(a1))

for i in range(pasos):
    vx.append(vi)
    vy.append(vj)
    ti.append(t)

    t = t + dt
    vi = vi
    vj = vj-(g*dt)

    if vj < 0:
        break

plot1 = plt.figure(1) #va a graficar la 1ra grafica
plt.plot(ti,vy,label="Velocidad sin resistencia del aire a 10 grados")
plt.xlabel("Tiempo [s]")
plt.ylabel("Vel [m/s]")
plt.legend(loc="upper left")
plt.grid()

plt.show()
Kobayashi
  • 2,402
  • 3
  • 16
  • 25
  • plot the graphs using `plt.plot()` for each iteration and call `plt.show()` whenever you want to show the plot. – NKN Feb 23 '22 at 15:27
  • Place a loop around your calculation `for angulo in angulos: ` collect your calculated arrays in a list, then plot all of them against the common x-axis in one go. And [`eval` is evil](https://stackoverflow.com/q/1832940/8881141). – Mr. T Feb 23 '22 at 16:09

0 Answers0