Integration Algorithm

29 views
Skip to first unread message

Gabriel Villalobos

unread,
Apr 23, 2015, 4:59:48 PM4/23/15
to vpytho...@googlegroups.com
Hello all, 

I've been looking into the documentation, but I haven't found which is the integration algorithm that is used in animations. For instance, the bouncing ball example shows the movement of the ball but, does it integrate by means of verlet? rk4? Is it possible to change the integration algorithm?

Thanks!

Aaron Titus

unread,
Apr 23, 2015, 5:38:35 PM4/23/15
to vpytho...@googlegroups.com
In python, you must write your own code to integrate.

In an introductory course, we often teach students to use the Euler-Cromer method. For example, if you define the velocity of a ball as a vector, then you can update its position using

while 1:
rate(100)
ball.pos=ball.pos + v*dt

This solves the equation:

v=d/dt (ball.pos)

You can use other algorithms, but you will have to write them.

Here’s a YouTube video that explains how to make animations in VPython.


This video is directed at a beginner’s level so it doesn’t go into other algorithms.

Another good resource is the set of demo programs for Matter and Interactions, Vol. I.



AT

--
You received this message because you are subscribed to the Google Groups "VPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vpython-user...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Bruce Sherwood

unread,
Apr 23, 2015, 6:46:06 PM4/23/15
to vpytho...@googlegroups.com
In the bouncing ball program, inspect the code, where you'll find 

    ball.pos = ball.pos + (ball.p/ball.mass)*dt

So there's no mystery about what integration algorithm is being used: here it's the simplest first-order integration.

In the orbit program you'll find this:

  dist = dwarf.pos - giant.pos
  force = G * giant.mass * dwarf.mass * dist / mag(dist)**3
  giant.p = giant.p + force*dt
  dwarf.p = dwarf.p - force*dt

  for star in [giant, dwarf]:
    star.pos = star.pos + star.p/star.mass * dt

This is first-order Euler-Cromer, which Aaron mentioned, in which you calculate the forces in terms of the initial positions, then update the momenta, then update the positions using the updated momentum. This particular sequence of operations can be shown to give better results among first-order integration algorithms than other sequences. (Note that the statements are vector statements.)

The example programs use simple first-order algorithms in order to bring out the main ideas clearly. This is also the motivation for using first-order algorithms with students if it is their first encounter with numerical integration, leaving for more advanced courses improved techniques such as fourth-order Runge-Kutta. Happily, today's computers are so fast that for introductory purposes it is sufficient to teach just one simple numerical analysis procedure: cut the step size until the behavior no longer changes.

Gabriel Villalobos

unread,
Apr 24, 2015, 10:45:31 AM4/24/15
to vpytho...@googlegroups.com
Thanks for the quick and informative answers. I agree with you that first order integration can be the simplest to teach to beginners. 
Reply all
Reply to author
Forward
0 new messages