Consider the following code snippet (assume that the parameters T_max, N, etc., are already defined):
dt = T_max/N
y = np.zeros(N)
t = np.zeros(N)
for j in range(N):
t[j] = j*dt
y[j] = y0 + v0*t[j] – 0.5*g*t[j]**2
How could you rewrite this using numpy methods so that the for loop can be removed?
import numpy as np dt = T_max/N # declaring 2 arrays y = np.zeros(N) t = np.zeros(N) # creating array for range 1 to N ind = np.arange(N) # using numpy updating the array values sequentially t = t + (ind * dt) y = y + (y0 + (v0 * t) - (0.5 * g * (t**2))) # FOR HELP PLEASE COMMENT. # THANK YOU
Get Answers For Free
Most questions answered within 1 hours.