A Mechanical System with Algebraic Constraints
A Mechanical System with Algebraic Constraints
This mass-spring-damper system includes a rigid bar that can prevent the motion of the second mass.
dynamics = {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]) + α μ[t]};
constraint = {0 == α (Subscript[x, 1][t] + Subscript[x, 2][t]) + (1 - α)μ[t]};pars = {Subscript[m, 1] -> 1, Subscript[m, 2] -> .5, Subscript[k, 1] -> 5, Subscript[k, 2] -> 2, Subscript[b, 1] -> .7, Subscript[b, 2] -> .3};Obtain a descriptor StateSpaceModel representation:
msd = StateSpaceModel[Join[dynamics, constraint], {Subscript[x, 1][t], Subscript[x, 2][t], μ[t]}, {u[t]}, {Subscript[x, 1][t], Subscript[x, 2][t]}, t, DescriptorStateSpace -> True] /. parsUse OutputResponse to simulate the system both when the bar is locked and unlocked:
constrainedResponse = OutputResponse[msd /. α -> 1, {1}, {t, 0, 20}];
freeResponse = OutputResponse[msd /. α -> 0, {1}, {t, 0, 20}];Plot[constrainedResponse, {t, 0, 20}, PlotRange -> All]Plot[freeResponse, {t, 0, 20}, PlotRange -> All]