Let y(t) be the altitude of the missile at time t. The gravity g = 9.8 m/s^2. We want to have the missile at 50 m off the ground after t = 5 s after launch.
Find the velocity at launch v0=y'(0)? Ignore the drag of the air resistance.
Boundary conditions are y(0) = 0 and y(5) = 50.
d^2y/dt^2=-g
or
dy/dt=v
dv/dt=-g
The result should be y'(0)=34.5 m/s.
import numpy as np import matplotlib.pyplot as plt from scipy.integrate import solve_ivp from scipy.optimize import fsolve import warnings warnings.filterwarnings("ignore", category=np.VisibleDeprecationWarning) plt.style.use("seaborn-poster") F = lambda t, s: np.dot(np.array([[0,1],[0,-9.8/s[1]]]),s) t_span = np.linspace(0, 5, 100) y0 = 0 t_eval = np.linspace(0, 5, 100) def objective(v0): sol = solve_ivp(F, [0, 5], [y0, v0], t_eval = t_eval) y = sol.y[0] return y[-1] - 50 v0, = fsolve(objective, 10) print("v0 =",v0) sol = solve_ivp(F, [0, 5], [y0, v0], t_eval = t_eval) plt.figure(figsize = (10, 8)) plt.plot(sol.t, sol.y[0]) plt.plot(5, 50, "ro") plt.xlabel("time (s)") plt.ylabel("altitude (m)") plt.title(f"root finding v={v0} m/s") plt.savefig('ex224.png', dpi=72) plt.show()
Recent Comments