Notes for Roller Coaster Applet
The coaster follows a path described by a parametric curve [x(s),y(s)], so that the coaster's position along the path can be described by the single variable s. Lagrangian mechanics can be used to determine the equations of motion. The kinetic energy is given by
![]()
where primes indicate differentiation with respect to s and dots indicate differentiation with respect to time (t).
The potential energy is given by
![]()
and the Lagrangian is given by L = T-V.
Lagrange's equation
![]()
yields
![]()
or
![]()
The dynamics are integrated numerically using Euler's Method:
![]()
To add frictionto the dynamics, Rayleigh's dissipation function F is added (see Goldstein's Classical Mechanics, e.g.) where
![]()
The modified Lagrange Equation becomes
![]()
which yields
![]()
or

Because roundoff error in the numerical integration is significant, and because energy conservation is one of the principles being illustrated, kinetic energy is adjusted each iteration to ensure the total energy constant. At each iteration, the work done by friction is
![]()
so that for each iteration the total energy is "adjusted" by taking E = E+dWf. Finally, the "speed" of the particle is adjusted at the end of each iteration to ensure the energy is correct ( T + V = E ):
PE=g*ys(coaster_s);
E=Math.max(PE,E-k*(xsp(coaster_s)*xsp(coaster_s)+ysp(coaster_s)*ysp(coaster_s))*coaster_sv*coaster_sv*dt);
KE_est=E-PE;
if(KE_est>=1.0E-6) {
KE=.5*(xsp(coaster_s)*xsp(coaster_s)
+ysp(coaster_s)*ysp(coaster_s))*coaster_sv*coaster_sv;
coaster_sv=coaster_sv*Math.sqrt(KE_est/KE);
}
The reaction force is estimated from the acceleration of the coaster and the force of gravity. However, only the component of the reaction force estimate that is perpendicular top the track is shown in the simulation.
The friction force is shown, but it will generally be small in magnitude compared to the other forces. This may be a nuisance visual.