Я использую Python, и у меня есть для l oop, как показано ниже.
def calculateTrajectories(masses, positions, velocities, T, dt):
#create lists for where we want to know positions, velocities at some time and convert them to np arrays
current_positions = []
new_positions = np.array(current_positions)
current_velocities = []
new_velocities = np.array(current_velocities)
#call updateParticles function to get new positions, velocities at each step
#loop starts at 0, ends at T, has step value of dt
for i in range(0, int(T), int(dt)):
#show all the time steps in the total time range
steps = np.array(i)
#call updateParticles
Positions, Velocities = updateParticles(masses, positions, velocities, dt)[i]
#assign the position and velocity results to their respective lists to get turned into arrays
current_positions.append(Positions)
current_velocities.append(Velocities)
return steps, current_positions, current_velocities
return steps, new_positions, new_velocities
Я пытаюсь использовать эту функцию с для для l oop, чтобы сделать этот расчет который должен дать 3 массива с именем, steps, new_positions, new_velocities.
T4 = 8.64e7
dt4 = 8640
masses = [1.989e30, 5.972e24]
positions = [(-448794, 0.0, 0.0),(1.4959742e11, 0.0, 0.0)]
velocities = [(0.0, -8.94e02, 0.0),(0.0, 2.98e4, 0.0)]
calculation4 = calculateTrajectories(masses, positions, velocities, T4, dt4)
print(calculation4)
И это то, что я получаю из этого.
(0, [array([ -448793.33565708, -7724160. , 0. ])], [array([1.49597199e+11, 2.57472000e+08, 0.00000000e+00])])
updateParticles - это еще одна функция, но я Я проверил, и проблема не связана с этим, это определенно с функцией, которую я пытаюсь сделать здесь, называемой CalcuTrajectories. Я не понимаю, почему мой l oop проходит только один раз, когда я дал ему диапазон значений до go through. Кроме того, в range () для l oop я должен был сделать значения stop и step целыми числами, используя int (), потому что я получил ошибку типа, если я их оставил, так как float не может быть интерпретирован как целое число.
Как я могу исправить свой l oop, чтобы он проходил столько раз, сколько запрашивает функция диапазона? Спасибо за любую помощь.