## Coupled accelerating point masses

Example of a two accelerating point masses which are coupled with a bidirectional spring. In this model we see how to create an edge between two nodes which defines additional dynamics on the state variable of each node. This type of coupling can be represented in a very natural way in codyn, by separation of the coupling terms into edges.

1 2 3 4 5 6 7 8 9 |
g = 9.81 node "n1" { y = 10 m = 0.6 y'' = "-m * g" } node "n2" { y = 8 m = 0.4 y'' = "-m * g" } # Create a bidirectional edge between the two nodes # implementing a simple, bidirectional spring, # applying a force resulting in additional # acceleration <bidirectional> edge from "n1" to "n2" { # Stiffness of the spring. Variables can be # defined inside edges as well and allow for # convenient definitions of constants and # temporary expressions. K = "5" # Additional acceleration due to the force of # the spring. Note that we have to apply the # acceleration to the differential equation of # the velocity from inside the edge. dy' += "K * (input.y - output.y)" } |