""" Ex 5.13 from 'A primer on...' We shall plot the trajectory of the ball, given by y = f(x), for f(x)>0. To find the range of x-values satisfying f(x) > 0 we solve the equation f(x) = 0, which is a standard quadratic equation. """ import sys import numpy as np import matplotlib.pyplot as plt from math import tan, cos, sqrt #unpack arguments and convert to float in one line: y0, theta, v0 = [float(e) for e in sys.argv[1:]] g = 9.81 a = -g/(2 * v0**2 * cos(theta)**2) b = tan(theta) c = y0 x1 = (-b + sqrt(b**2 - 4 * a * c)) / (2 * a) x2 = (-b - sqrt(b**2 - 4 * a * c)) / (2 * a) #pick the largest root as the end point for x: max_x = max(x1, x2) x = np.linspace(0, max_x, 101) y = a * x**2 + b * x + c plt.plot(x, y) plt.show() """Terminal> python plot_trajectory.py 2 0.8 4 (output is a plot) """