D [7/71 Simulating bounc C | e l https://relate.cs..llinois.edu/course/cs101-spl
ID: 3728683 • Letter: D
Question
D [7/71 Simulating bounc C | e l https://relate.cs..llinois.edu/course/cs101-splenorsession/39142/6/ Simulating bouncing with different gravity 5 points For this homework assignment, 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 from the limit of its atmosphere, a height of 250km. Model the ball's motion for one hour and 5 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 e, 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 e . update its velocity to 90% (09) of its velocity and reverse the direction of travel-in this case, please use the now-current velocity, i.e., vc[ i ] 0.9 vcl i 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 DO NOT try to write your code here. Debugging it here will be very difficult. You should write and test your code on your own computer Write a program to calculate the problem as specified above. Your submission should include arrays t and y of the proper dimensions and values, and an int named bouncesExplanation / Answer
CODE:
#define a header class
import matplotlib.pyplot as plt
import numpy as np
# assign an array "y"
array_y = 250.0*1000.0;
# assign an array "t"
array_t = 0.0;
# assign an dt value
dt = 4500.0/5000.0;
# initilaize the und value
und = 0.0;
# initilaize the x value
x = -8.87;
# assign the "y" value to s
s = array_y;
# initilaize the value
a = 0;
# set the flag to true
flag = True
HEIGHT = []
# performs loop, until
while(a < 5001):
# add
a = a + 1
# calculate the values
s = array_y + (und*array_t + (1.0/2.0)*x*array_y*array_y);
v = und + x*array_y;
# define append value for an height
HEIGHT.append(s)
# add
array_t = array_y + dt
# checks whether true, then
if(s <= 0 and flag == True):
# assign value
x = 0.0
y = -0.9*v
u = 0.0
flag = False
# then
elif(v <= 0 and flag == False):
flag = True
y = s;
ut = 0.0;
t = 0.0;
# plot the graph
plt.plot(HEIGHT)
# set the labels for bouncing the values
plt.ylabel(' height At Instance of t')
# shows the axis
plt.axis([0,5002 , 0, 250000])
plt.show()
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.