""" Ex 5.13 from A primer on... """ import sys import numpy as np import matplotlib.pyplot as plt from math import cos, tan, sqrt """ We should plot for y=f(x)>0, so we must solve a quadratic equation a*x**2 +b*x + c = 0 to find the right range of x values. """ #Assume the arguments are given in the order y0, theta, v0 y0 = float(sys.argv[1]) theta = float(sys.argv[2]) v0 = float(sys.argv[3]) g = 9.81 a = -1.0/(2*v0**2)*g/(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) x_stop = max(x1,x2) x = np.linspace(0,x_stop,101) y = a*x**2+b*x+c plt.plot(x,y) plt.show() """ Terminal> python plot_trajectory.py 0.75 0.78 5 output is a plot """