MCPcopy Create free account
hub / github.com/Apress/python-for-matlab-development / run_simulation

Function run_simulation

code/plots/bouncing_ball.py:61–79  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

59 return new_pos, new_vel
60
61def run_simulation():
62 nX = 21
63 pos = np.zeros((n_iter,2))
64 pos[0,:] = np.array([-3., 3.]) # initial position, m
65 vel = np.array([0.5, 0]) # initial velocity, m/s
66 bowl = np.zeros((nX,2))
67 bowl[:,0] = np.linspace(-3.5, 3.5, num=nX)
68 X = bowl[:,0]
69 bowl[:,1] = A*X**2
70 # centerline is the curve offset from the parabolic
71 # bowl by the radius of the ball; it is where the
72 # ball's center appears to bounce
73 den = 1/np.sqrt(1 + (2*A*X)**2)
74 centerline = np.zeros((nX,2))
75 centerline[:,0] = X + 2*A*ball_radius*X*den
76 centerline[:,1] = A*X**2 - ball_radius*den
77 for i in range(1,n_iter):
78 pos[i], vel = timestep(pos[i-1],vel)
79 return bowl, centerline, pos, vel
80
81def init(bowl, centerline):
82 global point, trace

Callers 1

bouncing_ball.pyFile · 0.85

Calls 1

timestepFunction · 0.85

Tested by

no test coverage detected