Question: Original parameters: home / study / engineering / computer science / computer science questions and answers / assignment if you drop an anvil from a

Original parameters:

home / study / engineering / computer science / computer science questions and answers / assignment if you drop an anvil from a great height, it accelerates downward... write a program ...

Your question has been answered

Let us know if you got a helpful answer. Rate this answer

Question: Assignment If you drop an anvil from a great height, it accelerates downward... Write a program c...

Assignment

If you drop an anvil from a great height, it accelerates downward... Write a program containing two functions: one that returns v(t) and another that returns y(t) for the anvil. Your program should plot both these functions on one graph, for time ranging from 0 to 5 seconds. Have the program label the axes appropriately and put ANVIL in the title.

Hint

Actually, everything you need code-wise is on this page, except the physics. Don't forget to import matplotlib.pyplot and numpy! Here's a sample program that puts together much of this example code.

import matplotlib.pyplot as plt import numpy as np def silly(x): y = np.sqrt(x**2 + 9) return y a = np.linspace(0, 10, 100) plt.plot(a, silly(a), 'go') plt.plot(a, silly(a) + 1, 'rx') plt.show() 

Pls correct or redo my code pls and take screenshot of output?

My code:

import numpy as np import matplotlib.pyplot as plt

def time_to_hit_ground(y0, v0, a): discriminant = np.sqrt(v0**2 - 2*a*y0)

t1 = (-v0 - discriminant) / a t2 = (-v0 + discriminant) / a if t1 >= 0: return t1 return t2 def drop(y0, v0=0.0, dt=0.1, g=-9.8): if y0 < 0: print('Object is underground.')

return

# if you also allow the user to change `dt` and `g` from the arguments, t_ground = time_to_hit_ground(y0, v0, g) t = np.arange(0, t_ground+dt, dt) v = v0 + g * t y = y0 + v0 * t + g * t**2 / 2. plt.plot(t, y, '.') plt.axvline(t_ground, color='g') plt.axhline(0, color='g') plt.xlabel('Time (s)') plt.ylabel('Height (m)') plt.title('ANVIL') plt.show()

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!