# This program uses the Euler-Cromer method to update the position of a ball in response to # a force, here defined as a spring force in the x direction. It has three types of output; # it annimates a ball and traces it's trajectory, it plots the x component of the ball's # positon against time, and it prints the final momentum and position of the ball. # This current version gives the ball a mass of 1kg so that the ball's velocity is numerically # equal to its momentum. This should be a useful 'shell' for you to modify to address a # variety of computational problems. from __future__ import division from visual import * from visual.graph import * # Constants k=5 b=0 t=0 tmax = 10 dt=0.001 # Objects ball=sphere(pos = (10,0,0), p=vector(0,0,0), m=1, radius = 0.1, color=color.red) # the above line defines a ball with initial position (10,0,0)m, # initial momentum (0,0,0)kg m/s, a radius of 0.1 m, and a mass of 1 kg. trail=curve(color = ball.color) # This sets up the program for creating a curve which we will, # inside the loop below, choose to trace the path of the ball funct1 = gcurve(color=color.cyan) funct1.plot(pos=(t,ball.x)) # Plot the initial point trail.append(pos=ball.pos) # Start's tracing the ball's trail at it's initial position #Execution while t