« View all new features in
Mathematica
9
◄
previous
|
next
►
New in
Mathematica
9
›
Advanced Hybrid and Differential Algebraic Equations
Proportional-Derivative Controller
Model the position of a moving body with 1 kg mass and use a sampled proportional-derivative (PD) controller to keep the position at a constant reference value.
In[1]:=
X
system = {x''[t] == u[t], x'[0] == x[0] == 0, u[0] == 1}; control = WhenEvent[Mod[t, \[Tau]], u[t] -> kp (xref - x[t] - td x'[t])]; params = {kp -> 1, td -> 1, \[Tau] -> 1, xref -> 1};
In[2]:=
X
sol = NDSolve[{system, control} /. params, {x, u}, {t, 0, 12}, DiscreteVariables -> u];
In[3]:=
X
Plot[Evaluate[{xref /. params, x[t], u[t]} /. sol], {t, 0, 12}, PlotLegends -> {"xref", "x(t)", "u(t)"}, ImageSize -> Medium]
Out[3]=