# A Mechanical System with Algebraic Constraints

#### This mass-spring-damper system includes a rigid bar that can prevent the motion of the second mass.

 In[1]:= Xdynamics = {Subscript[m, 1] Subscript[x, 1]''[t] == -Subscript[b, 1] Subscript[x, 1]'[t] - Subscript[k, 1] Subscript[x, 1][t] + Subscript[b, 2] (Subscript[x, 2]'[t] - Subscript[x, 1]'[t]) + Subscript[k, 2] (Subscript[x, 2][t] - Subscript[x, 1][t]) + u[t], Subscript[m, 2] Subscript[x, 2]''[ t] == -Subscript[b, 2] (Subscript[x, 2]'[t] - Subscript[x, 1]'[t]) - Subscript[k, 1] (Subscript[x, 2][t] - Subscript[x, 1][t]) + \[Alpha] \[Mu][ t]}; constraint = {0 == \[Alpha] (Subscript[x, 1][t] + Subscript[x, 2][t]) + (1 - \[Alpha]) \[Mu][t]};

#### Obtain a StateSpaceModel representation.

 In[2]:= Xmsd = StateSpaceModel[ Join[dynamics, constraint], {Subscript[x, 1][t], Subscript[x, 2][t], Subscript[x, 1]'[t], Subscript[x, 2]'[t], \[Mu][t]}, {u[t]}, {Subscript[x, 1][t], Subscript[x, 2][t]}, t] /. {Subscript[m, 1] -> 1, Subscript[m, 2] -> .5, Subscript[k, 1] -> 5, Subscript[k, 2] -> 2, Subscript[b, 1] -> .7, Subscript[b, 2] -> .3}
 Out[2]=

#### Use OutputResponse to simulate the system both when the bar is locked and when it is unlocked.

 In[3]:= XconstrainedResponse = OutputResponse[msd /. \[Alpha] -> 1, {1}, {t, 0, 20}]; freeResponse = OutputResponse[msd /. \[Alpha] -> 0, {1}, {t, 0, 20}];
 In[4]:= XPlot[constrainedResponse, {t, 0, 20}, PlotRange -> All]
 Out[4]=
 In[5]:= XPlot[freeResponse, {t, 0, 20}, PlotRange -> All]
 Out[5]=