Section 1.7 and 1.11 in Matter and Interactions (4th edition)
There is a restricted class of motion that can be modeled or explained with analytical tools (i.e., algebra and calculus). Most modern scientific research (and, indeed, engineering work) uses computational modeling as a significant part of the scientific endeavor. VPython is a Python-based programming language that allows you to create short programs that model the motion of physical systems. In these notes, you will read about how to write your programs so that they follow a common structure, which will make it easier to write new programs in the future. You will develop these computational models in class with the help of your classmates and the guidance of instructors.
Below is the code that was written in the lecture video above. There are 4 major components to this code that you will repeat in each program that you write:
Note that in this example, the cart was moving at constant velocity, so we didn't need to do much step 4 above. In future weeks, there will be examples of how to use Glowscript to model motion when there is nonzero net force.
Web VPython 3.2 # object setup road = box(pos = vec(0,0,0), size = vec(10,0.5,1)) cart = box(pos = vec(-4,0.5,0), size = vec(1,1,0.9), color = color.red, velocity = vec(0,0,0)) # parameters and initial conditions cart.velocity = vec(5,0,0) # m/s # time setup t = 0 dt = 0.01 tf = 2 # loop to do physics while cart.pos.x < 4: rate(100) cart.pos = cart.pos + cart.velocity*dt t = t + dt print('t = ', t, 's')