You will write a simplified model of a bouncing ball using numpy. Assume the bal
ID: 3845125 • Letter: Y
Question
You will write a simplified model of a bouncing ball using numpy. Assume the ball is dropped on Venus under constant acceleration g=8.87 m/s^2 from the limit of its atmosphere, a height of 250km. Model the ball's motion for one hour and 15 minutes (include second 0 and second 4,500 in your data points). After the initial state, simulate 5,000 updates to the state (for a total of 5,001 points.) Your simulation should use float64 numpy arrays for time (t) and height (y). Time should be represented in seconds and height should be represented in meters.
Bouncing
To simulate bouncing, we'll make some simplifying assumptions (since collision detection can be complicated). If the ball's height is ever less than or equal to 0, we will assume that the ball hit the ground before the time step we are simulating and already started bouncing. You should:
instantly set its height to 0
update its velocity to 90% (0.9) of its velocity from the previous time slice of the simulation
change the direction of travel (up instead of down)
Count the number of times the ball bounces in an integer variable named bounces.
Plotting y v. t may be useful for you to understand what results your code is producing.
Explanation / Answer
F(x) = { 0 if x > 0 { big_number if x < 0 import numpy as np from scipy.integrate import odeint import matplotlib.pyplot as plt big_number = 10000.0 width = 0.0001 ts = np.linspace(0, 10, 2000) def f(X, t): dx0 = X[1] dx1 = -9.8 dx1 += big_number / (1 + np.exp(X[0]/width)) return [dx0, dx1] with np.errstate(over='ignore'): # don't print overflow warning messages from exp(), # and limit the step size so that the solver doesn't step too deep # into the forbidden region X = odeint(f, [2, 0], ts, hmax=0.01) plt.plot(ts, X[:, 0]) plt.show()Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.