# Feedback Linearization

Feedback linearization is an exact linearization process that computes state and feedback transformations to linearize a nonlinear system and allows for the design of nonlinear controllers using linear techniques. Compare controller designs based on exact and approximate linearizations for a magnetically levitated system. The affine model can be obtained directly from the governing equations.

 In:= Xpars = {R -> 10, L -> 0.05, m -> 0.05, g -> 9.8, c -> 0.05, Subscript[x, 0] -> 0.1};
 In:= Xassm = AffineStateSpaceModel[{m x''[t] == m g - c (i[t]/x[t])^2, R i[t] + L i'[t] == V[t]}, {{x[t], Subscript[x, 0]}, {x'[t], 0}, {i[t], Subscript[x, 0] Sqrt[(m g)/c]}}, {{V[t], R Subscript[x, 0] Sqrt[(m g)/c]}}, x[t], t] /. pars
 Out= It is completely feedback linearizable, since there are no residual dynamics.

 In:= X\[ScriptCapitalF] = FeedbackLinearize[ assm, {{Subscript[z, 1], Subscript[z, 2], Subscript[z, 3]}, v}];
 In:= X\[ScriptCapitalF]["ResidualSystem"]
 Out= Compute the stabilizing feedback gains using the exactly linearized system.

 In:= X\[Kappa]1 = StateFeedbackGains[\[ScriptCapitalF][ "LinearSystem"], {-1.5, -2 + I, -2 - I}]
 Out= Simulate the closed-loop system for given initial conditions.

 In:= Xcsys1 = \[ScriptCapitalF][{"ClosedLoopSystem", \[Kappa]1}]; ics = {0.3, 0, 0.31305};
 In:= Xcsys1 = \[ScriptCapitalF][{"ClosedLoopSystem", \[Kappa]1}]; ics = {0.3, 0, 0.31305};; or1 = OutputResponse[{csys1, ics}, 0, {t, 0, 35}]; Plot[%, {t, 0, 6}]
 Out= Compute stabilizing feedback gains using the approximately linearized system.

 In:= X\[Kappa]2 = StateFeedbackGains[assm, {-1.5, -2 + I, -2 - I}]
 Out= The design based on exact linearization has a better response.

 In:= Xcsys2 = SystemsModelStateFeedbackConnect[assm, \[Kappa]2]; or2 = OutputResponse[{csys2, ics}, 0, {t, 0, 35}];
 In:= XPlot[{or1, or2}, {t, 0, 35}, PlotLegends -> {"Exact", "Approximate"}]
 Out= The nonlinear controller used in the exact linearization design.

 In:= Xc1 = \[ScriptCapitalF][{"OriginalSystemFullController", \[Kappa]1}]
 Out= The control effort expended.

 In:= Xinps1 = Join[{0}, sr1 = StateResponse[{csys1, ics}, 0, {t, 0, 35}]]; ce1 = OutputResponse[c1, inps1, {t, 0, 35}];
 In:= XPlot[ce1, {t, 0, 35}, PlotRange -> All]
 Out= The effort expended for the exact case is much lower than that of the approximate.

 In:= Xce2 = -\[Kappa]2 /. Thread[{Subscript[\[FormalX], 1][t], Subscript[\[FormalX], 2][t], Subscript[\[FormalX], 3][t]} -> StateResponse[{csys2, ics}, 0, {t, 0, 35}]];
 In:= XPlot[{ce1, ce2}, {t, 0, 35}, PlotLegends -> {"Exact", "Approximate"}]
 Out= An animation of the ball being levitated using the nonlinear controller. Play AnimationStop Animation

## Mathematica

Questions? Comments? Contact a Wolfram expert »