#Exer. 5.11 from "A primer on..." import numpy as np import matplotlib.pyplot as plt import sys """ We are asked to seet the lengths of the coordinate axes, and to do this we need to find the maximum values of t and y. We use a simple and general method to do this. For this particular case it could be done much smarter, but the approach shown here is very general and useful to know about. """ v0_list = sys.argv[1:] g = 9.81 max_t = 0 max_y = 0 for v0 in v0_list: v0 = float(v0) t_stop = 2*v0/g t = np.linspace(0,t_stop,101) y = v0*t - 0.5*g*t**2 if max(t) > max_t: max_t = max(t) if max(y) > max_y: max_y = max(y) plt.plot(t,y) plt.title('Ball plot 2') plt.xlabel('time (s)') plt.ylabel('height (m)') plt.axis([0, max_t, 0, max_y*1.05]) plt.show() """ Terminal> python plot_ball3.py 3 5 9 output is a plot """