""" Alternative "sequential" version of the forward Euler method for a specific ODE system. Instead of coding the rhs as a vector-valued function and then pass the function to the solver, the solution components are stepped forward one-by-one using the forward Euler update formula for each of them. This approach may be a bit easier to grasp, but the downside is that it mingles solver and model. Changing the model, or switching to a more accurate solver, is therefore difficult. The other, more general, approach to solving ODEs is highly recommended. """ import numpy as np import matplotlib.pyplot as plt T = 1 n = 100 dt = T / n g = 9.81 t = np.zeros(n+1) x = np.zeros(n+1) vx = np.zeros(n+1) y = np.zeros(n+1) vy = np.zeros(n+1) #initial velocity 5, angle = 80 degrees v0 = 5 theta = 80 * np.pi / 180 vx[0] = v0*np.cos(theta) vy[0] = v0*np.sin(theta) for k in range(n): t[k + 1] = t[k] + dt x[k + 1] = x[k] + dt * vx[k] vx[k + 1] = vx[k] y[k + 1] = y[k] + dt * vy[k] vy[k + 1] = vy[k] - dt * g plt.plot(x, y) plt.show()