Previous section-----Next section

2.4.2 Constraints

The actual constraint expressions that are generated by SetConstraints can be extracted with Constraints. Constraints can be very useful for debugging a model because it is often possible to read the constraint expressions directly and relate them to the function of the model.

Constraints function.

This loads the Modeler2D package.

Consider the 2D crankshaft-piston model of Section 1.2. This model is built with various settings for the options for SetConstraints to show their affect on the resulting equations.

Here is the crankshaft-piston model rebuilt.

The first constraint cs[1] is a two degree of freedom constraint that constrains the origin of the crankshaft to lie at the global origin.

Here is the expression generated by the Revolute2 constraint.

Obviously, when these two expressions are driven to zero, the desired result is achieved, the coordinates of the local origin of the crankshaft {X2, Y2} are zero.
The third constraint cs[3] is a two degree of freedom constraint that allows the piston to translate along a vertical axis, but constrains its rotation and its translation in the X direction.

Here is the expression generated by the Translate2 constraint.

The first expression, 10 Sin[CapitalTheta3], constrains the rotation of the piston; this expression can be equal to zero if CapitalTheta3 is any integer multiple of Pi. The reason that the solution CapitalTheta3 -> 0 is found is because the default initial guess is CapitalTheta3 -> 0. If a different initial guess were used, such as CapitalTheta3 -> 3, the model would converge to CapitalTheta3 -> N[Pi] instead.
The second expression in the list constrains the X coordinate of the piston to be zero. Notice that at any value of CapitalTheta3 that satisfies the first expression, the second expression reduces to  or  , either of which will drive X3 to zero.