O'Reilly logo

Learning to Program with MATLAB: Building GUI Tools by Craig S. Lent

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

images

6.1   Basic animation

6.2   Animating function plots

6.3   Kinematics of motion

Computational models are often enhanced by including an animation of model behavior. An animation can give the user an immediate sense of the system’s dynamics. It also acts as a first intuitive check on the correctness of our model. For example, we all have some experience of how balls bounce, so an animation that shows a ball moving faster at the top of the bounce and slower near the bottom makes us immediately suspicious of the model. A correctly functioning model, including perhaps an animation and other analytical plots (e.g., showing the potential and kinetic energies of the bouncing ball), can enhance our understanding of the behavior.

Basic animation works the way a flip-book animation works—a series of still pictures with small differences between them are rapidly displayed to give the illusion of motion. This can be accomplished in MATLAB by repeatedly drawing with the plot command followed by the drawnow command, usually in a for loop. There are several tips and techniques offered here for making animations work well.

We try out these animation techniques by modeling the motion of particles being acted upon by specific forces. The motion is described by Newton’s second law, F = ma = m dv/dt. We start with the simplest case, F = 0 and consider bounce conditions. The case when F is constant ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required