Question: Please use python 3 answer this. Someone answered this question on Chegg but it is incorrect. Just as reference the incorrect code is: import matplotlib.pyplot
Please use python 3 answer this. Someone answered this question on Chegg but it is incorrect. Just as reference the incorrect code is:
import matplotlib.pyplot as plt import numpy as np from math import pi, tan, sin, cos
g, v0 = 9.8, 4 x = list(np.arange(0,2,0.05)) def y_x(x, th): xs, ys = list(), list() th = th*pi/180 for i in x: y = i*tan(th) - g*i*i/(2*v0*v0*cos(th)*cos(th)) if y
def R(th): th = th*pi/180 return v0*v0*sin(2*th)/g
(x45, y45) = y_x(x, 45) (x60, y60) = y_x(x, 60) R45 = R(45) R60 = R(60) print('Range (theta = 45):', R45) print('Range (theta = 60):', R60)
plt.figure() plt.plot(x60, y60, 'b', x45, y45, 'r') plt.vlines(x60, min(y60), max(y60), 'b', 'dashed') plt.vlines(x45, min(y45), max(y45), 'r', 'dashed') plt.title('y(x) vs x') plt.xlabel('x'), plt.ylabel('y(x)') plt.axis((0,2,0,1)) plt.legend(('theta = 60','theta = 45')) plt.show()
Now an exercise in simple two-dimensional ballistics. We'll start by recalling two textbook formulas for the trajectoryy(x) and for the maximum range R of an object moving in 2d under the influence of gravity, starting at y 0: 215 cos2 U6 sin(20) A great way to test these formulas against each other is with a plot! Let's fix g = 9.8 m/s2 and 10-4 ms, and then create a plot with the following properties Show y(x) as a solid line for two trajectories, -20 degrees and = 40 degrees. . . Show R for each trajectory as a dashed, vertical line on the same plot, with the same color as the corresponding y(x) .Include a legend to show which trajectory is which The simplest way to add a vertical line to your plot is the plt.vlines() function, for things like color and line style, it takes the same options that plt.plot) does. Choosing the plot range, colors, etc. are up to you: the only requirement is that your plot should be easily usable to see that y(x) and R agree on the maximum range of your projectile in both cases
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
