As a first example, we consider the problem of modeling the dynamics of a mass on a string of unit length in 2-D Cartesian coordinates (the pendulum problem). We let be the position of the mass on the string, and the velocity:
Since the mass is on a string of fixed length , we have the constraint:
Now we want to construct the DAE system using the Euler-Lagrange formulation, so we compute the kinetic energy and the potential energy as:
where is the mass, and is the gravitational constant (we will use 9.8). The Lagrangian and modified Lagrangian are given by:
We can then construct the Euler-Lagrange formulation via:
Now we have the equations of motion for the pendulum. Next, we need to determine consistent initial conditions. To do so, we must identify any hidden constraints of the system. These are easy to find, as we have only one constraint.
Our initial conditions must satisfy , , and at the initial point, leaving only 2 degrees of freedom for the conditions. So for a pendulum starting at the minimum value of having an initial horizontal velocity of , we get:
So we consider the above with a pendulum of unit length having unit mass and an initial horizontal velocity of , giving us the DAE system and initial conditions:
We can then obtain the solution as:
Solution with rosenbrock_dae:
Solution with mebdfi:
Now consider a similar problem as above, but in addition add a second mass supported from the first by another string, this one of length 1/2 (the double pendulum). The system can be obtained and solved as:
The trajectory of the second mass can be plotted via:
Note that we did not specify initial conditions for and as we were using an extension method, and the system was sufficiently linear in the lambda.