# State-Space Transformation

Obtain the governing equations of a spherical pendulum in Cartesian coordinates, put them into the affine state-space form, and convert them to spherical coordinates. The governing equations from the Lagrangian.

 In:= X\[ScriptCapitalL] = 1/2 m (x'[t]^2 + y'[t]^2 + (x[t] x'[t] + y[t] y'[t])^2/( r^2 - x[t]^2 - y[t]^2)) + m g Sqrt[r^2 - x[t]^2 - y[t]^2];
 In:= XShort[eqns = Table[D[D[\[ScriptCapitalL], q'[t]], t] - D[\[ScriptCapitalL], q[t]] == Subscript[F, q][t], {q, {x, y}}]]
 Out//Short= The affine representation with states and inputs .

 In:= XShort[eqns = Table[D[D[\[ScriptCapitalL], q'[t]], t] - D[\[ScriptCapitalL], q[t]] == Subscript[F, q][t], {q, {x, y}}]]; AffineStateSpaceModel[ eqns, {x[t], y[t], x'[t], y'[t]}, {Subscript[F, x][t], Subscript[F, y][t]}, {Sqrt[r^2 - x[t]^2 - y[t]^2]}, t]; assm = AffineStateSpaceModel[%, {x, y, Subscript[x, d], Subscript[y, d]}] // Simplify
 Out= The transformation between spherical and Cartesian coordinates.

 In:= Xctrans = Most@ CoordinateTransform[ "Spherical" -> "Cartesian", {r, \[Theta][t], \[Phi][t]}]
 Out= The transformation of the coordinate derivatives.

 In:= Xctransd = D[ctrans, t] /. {\[Theta]' -> Subscript[\[Theta], d], \[Phi]' -> Subscript[\[Phi], d]}
 Out= The complete state transformation.

 In:= Xtrans = Thread[{x[t], y[t], Subscript[x, d][t], Subscript[y, d][t]} -> Join[ctrans, ctransd]]
 Out= The expressions in spherical coordinates are much simpler.

 In:= XStateSpaceTransform[ assm, {trans, {\[Theta][t], Subscript[\[Theta], d][t], \[Phi][t], Subscript[\[Phi], d][t]}}] // PowerExpand
 Out= ## Mathematica

Questions? Comments? Contact a Wolfram expert »