# The nonlinear state-space model of a spherical pendulum cannot be linearized and cannot be controlled?

I am attempting to model and control a spherical pendulum. I have derived the equations as follows:

The positions of the mass m:

x = \[ScriptL] Sin[\[Theta][t]] Cos[\[Phi][t]];

y = \[ScriptL] Sin[\[Theta][t]] Sin[\[Phi][t]];

z = \[ScriptL] Cos[\[Theta][t]];


The velocities are hence:

{
\!$$\*OverscriptBox[\(x$$, $$.$$]\),
\!$$\*OverscriptBox[\(y$$, $$.$$]\),
\!$$\*OverscriptBox[\(z$$, $$.$$]\)} = Table[D[q, t], {q, {x, y, z}}]


The Lagrangian is L=T-V and can now be constructed:

T = 1/2 m \[ScriptV]^2

V = -m g z

\[ScriptCapitalL] = T - V


The equations of motion are derived from the Euler-Lagrange formula:

eqns = Table[\!$$\*SubscriptBox[\(\[PartialD]$$, $$t$$]$$D[\[ScriptCapitalL], \(q'$$[t]]\)\) -
D[\[ScriptCapitalL], q[t]] == Subscript[\[ScriptCapitalT],
q], {q, {\[Theta], \[Phi]}}] /. {Subscript[\[ScriptCapitalT], \[Theta]] ->
Subscript[\[ScriptCapitalT], 1][t],
Subscript[\[ScriptCapitalT], \[Phi]] -> Subscript[\[ScriptCapitalT], 2][t]}


The parameters of the system as a list of replacement rules:

pars = {g -> 9.8, m -> 0.5, \[ScriptL] -> 1};


The nonlinear state-space model:

spend = NonlinearStateSpaceModel[
eqns, {\[Theta][t], \[Theta]'[t], \[Phi][t], \[Phi]'[
t]}, {Subscript[\[ScriptCapitalT], 1][t],
Subscript[\[ScriptCapitalT], 2][t]}, {\[Theta][t], \[Phi][t]}, t]/.pars


Linearizing results in error:

ssm = StateSpaceModel[spend]


Curiously, the output response can be simulated:

OutputResponse[{spend, {0.1, 0.3, 0.6, 0.01}}, {0, 0}, {t, 0, 10}];
Plot[%, {t, 0, 10}, PlotRange -> All]


Can anyone help figure out what's wrong with this system? Thanks!

• Euler-Lagrange gives second order equations of motion. But help does not show an example where NonlinearStateSpaceModel accepts such second order odes. The equations of motion have to be in state space form. i.e. first order. See the help example under Aerospace systems for example. Are you sure you are passing NonlinearStateSpaceModel the equations of motion as first order (i.e. state space form) and not the standard second order equations generated from Euler-Lagrange? (Hard to read you code, since you are using lots of fancy notations). Apr 24, 2022 at 7:50

This is because there is no standard linear state-space representation for a spherical pendulum.

Compute the nonlinear Euler-Lagrange equations.

x = ℓ Sin[θ[t]] Cos[ϕ[t]];
y = ℓ Sin[θ[t]] Sin[ϕ[t]];
z = ℓ Cos[θ[t]];
\[ScriptV] = Table[D[q, t], {q, {x, y, z}}];
T = Simplify[1/2 m \[ScriptV] . \[ScriptV]];
V = -m g z;
ℒ = T - V;
eqns = Table[D[D[ℒ, Derivative[1][q][t]], t] - D[ℒ, q[t]] ==
Subscript[\[ScriptCapitalT], q][t], {q, {θ, ϕ}}]


$$\left\{g m \ell \sin (\theta (t))+m \ell ^2 \theta ''(t)-m \ell ^2 \sin (\theta (t)) \cos (\theta (t)) \phi '(t)^2=\mathcal{T}_{\theta }(t),\\2 m \ell ^2 \theta '(t) \sin (\theta (t)) \cos (\theta (t)) \phi '(t)+m \ell ^2 \sin ^2(\theta (t)) \phi ''(t)=\mathcal{T}_{\phi }(t)\right\}$$

Look at the second equation. If we linearize it we are left with $$0=\mathcal{T}_{\phi }(t)$$.

If we convert it to a StateSpaceModel, we see the same equation is the last one in the descriptor state-space model.

StateSpaceModel[eqns, {θ[t], θ'[t], ϕ[t], ϕ'[t]}, {Subscript[\[ScriptCapitalT], θ][t],
Subscript[\[ScriptCapitalT], ϕ][t]}, {θ[t], ϕ[t]}, t]


So at best, we can get this rather wanting linear descriptor state-space representation of the system. It cannot be converted to the standard form because the descriptor matrix is singular.

However, we can have a standard NonlinearStateSpaceModel representation of the system.

nssm = NonlinearStateSpaceModel[eqns, {θ[t], θ'[t], ϕ[t], ϕ'[t]}, {Subscript[\[ScriptCapitalT], θ][t],
Subscript[\[ScriptCapitalT], ϕ][t]}, {θ[t], ϕ[t]}, t]


What happens if we try to linearize this to get a standard linear state-space representation as you have attempted to do? First the Jacobian is computed and then evaluated at the operating points. And you can see the source of the messages that you are encountering.

Normal[nssm][[1, 1]]
jacobian = D[%, {{θ[t], Subscript[\[FormalX], 1][t], ϕ[t], Subscript[\[FormalX], 2][t]}}];
jacobian /. Thread[{θ[t], Subscript[\[FormalX], 1][t], ϕ[t], Subscript[\[FormalX], 2][t]} -> 0]


In summary, a linear state-space representation is not adequate to model a nonlinear spherical pendulum.

• Thanks this is very helpful… does this mean that the model cannot be controlled? So far, I have been unsuccessful Apr 26, 2022 at 21:04
• The linear approximation cannot be controlled. The nonlinear model should be controllable. Apr 27, 2022 at 13:03
• with which method can it be controlled? LQRegulatorGains and StateFeedbackGains return the error "Complex infinity encountered". PIDtune doesn't work either because the system cannot be expressed as a transfer function (TransferFunctionModel yields the same error). How would you go about implementing a controller? Apr 27, 2022 at 17:05
• You need to try something that doesn't rely on Taylor linearization. FeedbackLinearize, for example. Apr 28, 2022 at 13:21
• FeedbackLinearize worked, thanks! Apr 30, 2022 at 8:48