Published on 29 Apr 2019

Department

Physics

Course

PHYSICS 140

Professor

Solutions to sample modeling problems

1. Consider the following snippet of VPython code (with line numbers inserted) that purports to carry

out part of a 3-second simulation of a 3-kg object launched from the origin at an angle of 60 degrees

from the horizontal at time t = 0 in the presence of a drag force of the form

F

drag

= −αv

:

1) m = 3.0

2) g = vector(0, -9.8, 0)

3) alpha = 2

4) v0 = 15.

5) thetadeg = 60.

6) theta = thetadeg/180.*pi

7) vel = vector(v0*cos(theta), v0*sin(theta), 0.)

8) p = m*vel

9) ballpos = vector(0., 0., 0.)

10) t = 0.

11) dt = 0.01

12) while ballpos.y >= 0:

13) ballpos = ballpos + vel*dt

14) Fgrav = m*g

15) Fdrag = −alpha*vel

16) p = p + (Fgrav + Fdrag)*dt

17) vel = vel + p/m

18) t = t + dt

Which line contains a serious bug?

a) Line 13)

b) Line 14)

c) Line 15)

d) Line 16)

e) Line 17)

The instantaneous velocity is simply the instantaneous momentum divided by mass. One should not

increment by p/m each time.