Skip to main content
Improved formatting
Source Link
Suba Thomas
  • 8.8k
  • 1
  • 17
  • 33

The resulting expressions (formatted for readability):

\[ScriptE]// MatrixForm

{{1, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 1, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 1, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 1, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 1, 0}, {0, 1, 0, -l0 Cos[Subscript[[FormalX], 3][t]] Sin[ Subscript[[FormalX], 5][t]], 0, -l0 Cos[Subscript[[FormalX], 5][t]] Sin[ Subscript[[FormalX], 3][t]], 0, 0, 0, 0}, {0, 0, 0, l0 Cos[Subscript[[FormalX], 3][t]] Cos[ Subscript[[FormalX], 5][t]], 0, -l0 Sin[Subscript[[FormalX], 3][t]] Sin[ Subscript[[FormalX], 5][t]], 0, 1, 0, 0}, {0, 0, 0, l0 Sin[Subscript[[FormalX], 3][t]], 0, 0, 0, 0, 0, 1}, {0, -l0 Cos[Subscript[[FormalX], 3][t]] Sin[ Subscript[[FormalX], 5][t]], 0, l0^2, 0, 0, 0, l0 Cos[Subscript[[FormalX], 3][t]] Cos[ Subscript[[FormalX], 5][t]], 0, l0 Sin[Subscript[[FormalX], 3][t]]}, {0, -l0 Cos[ Subscript[[FormalX], 5][t]] Sin[Subscript[[FormalX], 3][t]], 0, 0, 0, l0^2 Sin[Subscript[[FormalX], 3][t]]^2, 0, -l0 Sin[Subscript[[FormalX], 3][t]] Sin[ Subscript[[FormalX], 5][t]], 0, 0}}

enter image description here

\[ScriptF]{D[\[ScriptX], t], Table["\[DoubleLeftRightArrow]", 

{Subscript[[FormalX], 2][t], Subscript[[FormalX], 4][t], Subscript[[FormalX], 6][t], Subscript[[FormalX], 8][t], Subscript[[FormalX], 10][t], 2 l0 Cos[Subscript[[FormalX], 3][t]] Cos[ Subscript[[FormalX], 5][t]] Subscript[[FormalX], 4][ t] Subscript[[FormalX], 6][t] - l0 Sin[Subscript[[FormalX], 3][t]] Sin[ Subscript[[FormalX], 5][t]] (Subscript[[FormalX], 4][t]^2 + Subscript[[FormalX], 6][t]^2), 2 l0 Cos[Subscript[[FormalX], 3][t]] Sin[ Subscript[[FormalX], 5][t]] Subscript[[FormalX], 4][ t] Subscript[[FormalX], 6][t] + l0 Cos[Subscript[[FormalX], 5][t]] Sin[ Subscript[[FormalX], 3][t]] (Subscript[[FormalX], 4][t]^2 + Subscript[[FormalX], 6][t]^2), -l0 Cos[ Subscript[[FormalX], 3][t]] Subscript[[FormalX], 4][t]^2, l0 (g m Cos[Subscript[[FormalX], 3][t]] + l0 Cos[Subscript[[FormalX], 3][t]] Sin[ Subscript[[FormalX], 3][t]] Subscript[[FormalX], 6][ t]^2), -2 l0^2 Cos[Subscript[[FormalX], 3][t]] Sin[ Subscript[[FormalX], 3][t]] Subscript[[FormalX], 4][ t] Subscript[[FormalX], 6][t]}

\[ScriptX]10], \[ScriptF]}\[Transpose] // TableForm

{Subscript[[FormalX], 1][t], Subscript[[FormalX], 2][t], Subscript[[FormalX], 3][t], Subscript[[FormalX], 4][t], Subscript[[FormalX], 5][t], Subscript[[FormalX], 6][t], Subscript[[FormalX], 7][t], Subscript[[FormalX], 8][t], Subscript[[FormalX], 9][t], Subscript[[FormalX], 10][t]}

enter image description here

The resulting expressions:

\[ScriptE]

{{1, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 1, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 1, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 1, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 1, 0}, {0, 1, 0, -l0 Cos[Subscript[[FormalX], 3][t]] Sin[ Subscript[[FormalX], 5][t]], 0, -l0 Cos[Subscript[[FormalX], 5][t]] Sin[ Subscript[[FormalX], 3][t]], 0, 0, 0, 0}, {0, 0, 0, l0 Cos[Subscript[[FormalX], 3][t]] Cos[ Subscript[[FormalX], 5][t]], 0, -l0 Sin[Subscript[[FormalX], 3][t]] Sin[ Subscript[[FormalX], 5][t]], 0, 1, 0, 0}, {0, 0, 0, l0 Sin[Subscript[[FormalX], 3][t]], 0, 0, 0, 0, 0, 1}, {0, -l0 Cos[Subscript[[FormalX], 3][t]] Sin[ Subscript[[FormalX], 5][t]], 0, l0^2, 0, 0, 0, l0 Cos[Subscript[[FormalX], 3][t]] Cos[ Subscript[[FormalX], 5][t]], 0, l0 Sin[Subscript[[FormalX], 3][t]]}, {0, -l0 Cos[ Subscript[[FormalX], 5][t]] Sin[Subscript[[FormalX], 3][t]], 0, 0, 0, l0^2 Sin[Subscript[[FormalX], 3][t]]^2, 0, -l0 Sin[Subscript[[FormalX], 3][t]] Sin[ Subscript[[FormalX], 5][t]], 0, 0}}

\[ScriptF]

{Subscript[[FormalX], 2][t], Subscript[[FormalX], 4][t], Subscript[[FormalX], 6][t], Subscript[[FormalX], 8][t], Subscript[[FormalX], 10][t], 2 l0 Cos[Subscript[[FormalX], 3][t]] Cos[ Subscript[[FormalX], 5][t]] Subscript[[FormalX], 4][ t] Subscript[[FormalX], 6][t] - l0 Sin[Subscript[[FormalX], 3][t]] Sin[ Subscript[[FormalX], 5][t]] (Subscript[[FormalX], 4][t]^2 + Subscript[[FormalX], 6][t]^2), 2 l0 Cos[Subscript[[FormalX], 3][t]] Sin[ Subscript[[FormalX], 5][t]] Subscript[[FormalX], 4][ t] Subscript[[FormalX], 6][t] + l0 Cos[Subscript[[FormalX], 5][t]] Sin[ Subscript[[FormalX], 3][t]] (Subscript[[FormalX], 4][t]^2 + Subscript[[FormalX], 6][t]^2), -l0 Cos[ Subscript[[FormalX], 3][t]] Subscript[[FormalX], 4][t]^2, l0 (g m Cos[Subscript[[FormalX], 3][t]] + l0 Cos[Subscript[[FormalX], 3][t]] Sin[ Subscript[[FormalX], 3][t]] Subscript[[FormalX], 6][ t]^2), -2 l0^2 Cos[Subscript[[FormalX], 3][t]] Sin[ Subscript[[FormalX], 3][t]] Subscript[[FormalX], 4][ t] Subscript[[FormalX], 6][t]}

\[ScriptX]

{Subscript[[FormalX], 1][t], Subscript[[FormalX], 2][t], Subscript[[FormalX], 3][t], Subscript[[FormalX], 4][t], Subscript[[FormalX], 5][t], Subscript[[FormalX], 6][t], Subscript[[FormalX], 7][t], Subscript[[FormalX], 8][t], Subscript[[FormalX], 9][t], Subscript[[FormalX], 10][t]}

The resulting expressions (formatted for readability):

\[ScriptE]// MatrixForm

enter image description here

{D[\[ScriptX], t], Table["\[DoubleLeftRightArrow]", 
10], \[ScriptF]}\[Transpose] // TableForm

enter image description here

Updated answer after equations were fixed
Source Link
Suba Thomas
  • 8.8k
  • 1
  • 17
  • 33

(Update after Jens fixed the equations. Thanks Jens for fixing them.)

If we try to solve these equations for the highest order derivatives we see that there is no solution.

Solve[eqs, {x''[t], y''[t], z''[t], θ''[t], ϕ''[t]}]

{}

Thus it cannot be put into the form $\dot{\mathit{x}}=\mathit{f}( \mathit{x})$.

The equations are still linear in the highest order derivatives, and so it can be put in the form $\mathit{e}.\dot{\mathit{x}}=\mathit{f}( \mathit{x})$. You can use an internal function to do this calculation for you.

{{\[ScriptF], \[ScriptH], \[ScriptE]}, \[ScriptX]} =                        
Control`DEqns`nonaffinestatespaceForm[
eqs, {x[t], y[t], z[t], θ[t], ϕ[t]}, {}, {}, t, #[[1 ;; 2]] &,                                                
DescriptorStateSpace -> False];

The resulting expressions:

\[ScriptE]

{{1, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 1, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 1, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 1, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 1, 0}, {0, 1, 0, -l0 Cos[Subscript[[FormalX], 3][t]] Sin[ Subscript[[FormalX], 5][t]], 0, -l0 Cos[Subscript[[FormalX], 5][t]] Sin[ Subscript[[FormalX], 3][t]], 0, 0, 0, 0}, {0, 0, 0, l0 Cos[Subscript[[FormalX], 3][t]] Cos[ Subscript[[FormalX], 5][t]], 0, -l0 Sin[Subscript[[FormalX], 3][t]] Sin[ Subscript[[FormalX], 5][t]], 0, 1, 0, 0}, {0, 0, 0, l0 Sin[Subscript[[FormalX], 3][t]], 0, 0, 0, 0, 0, 1}, {0, -l0 Cos[Subscript[[FormalX], 3][t]] Sin[ Subscript[[FormalX], 5][t]], 0, l0^2, 0, 0, 0, l0 Cos[Subscript[[FormalX], 3][t]] Cos[ Subscript[[FormalX], 5][t]], 0, l0 Sin[Subscript[[FormalX], 3][t]]}, {0, -l0 Cos[ Subscript[[FormalX], 5][t]] Sin[Subscript[[FormalX], 3][t]], 0, 0, 0, l0^2 Sin[Subscript[[FormalX], 3][t]]^2, 0, -l0 Sin[Subscript[[FormalX], 3][t]] Sin[ Subscript[[FormalX], 5][t]], 0, 0}}

\[ScriptF]

{Subscript[[FormalX], 2][t], Subscript[[FormalX], 4][t], Subscript[[FormalX], 6][t], Subscript[[FormalX], 8][t], Subscript[[FormalX], 10][t], 2 l0 Cos[Subscript[[FormalX], 3][t]] Cos[ Subscript[[FormalX], 5][t]] Subscript[[FormalX], 4][ t] Subscript[[FormalX], 6][t] - l0 Sin[Subscript[[FormalX], 3][t]] Sin[ Subscript[[FormalX], 5][t]] (Subscript[[FormalX], 4][t]^2 + Subscript[[FormalX], 6][t]^2), 2 l0 Cos[Subscript[[FormalX], 3][t]] Sin[ Subscript[[FormalX], 5][t]] Subscript[[FormalX], 4][ t] Subscript[[FormalX], 6][t] + l0 Cos[Subscript[[FormalX], 5][t]] Sin[ Subscript[[FormalX], 3][t]] (Subscript[[FormalX], 4][t]^2 + Subscript[[FormalX], 6][t]^2), -l0 Cos[ Subscript[[FormalX], 3][t]] Subscript[[FormalX], 4][t]^2, l0 (g m Cos[Subscript[[FormalX], 3][t]] + l0 Cos[Subscript[[FormalX], 3][t]] Sin[ Subscript[[FormalX], 3][t]] Subscript[[FormalX], 6][ t]^2), -2 l0^2 Cos[Subscript[[FormalX], 3][t]] Sin[ Subscript[[FormalX], 3][t]] Subscript[[FormalX], 4][ t] Subscript[[FormalX], 6][t]}

\[ScriptX]

{Subscript[[FormalX], 1][t], Subscript[[FormalX], 2][t], Subscript[[FormalX], 3][t], Subscript[[FormalX], 4][t], Subscript[[FormalX], 5][t], Subscript[[FormalX], 6][t], Subscript[[FormalX], 7][t], Subscript[[FormalX], 8][t], Subscript[[FormalX], 9][t], Subscript[[FormalX], 10][t]}

The complication here is that $\mathit{e}$ is not invertible.

(Update after Jens fixed the equations. Thanks Jens for fixing them.)

If we try to solve these equations for the highest order derivatives we see that there is no solution.

Solve[eqs, {x''[t], y''[t], z''[t], θ''[t], ϕ''[t]}]

{}

Thus it cannot be put into the form $\dot{\mathit{x}}=\mathit{f}( \mathit{x})$.

The equations are still linear in the highest order derivatives, and so it can be put in the form $\mathit{e}.\dot{\mathit{x}}=\mathit{f}( \mathit{x})$. You can use an internal function to do this calculation for you.

{{\[ScriptF], \[ScriptH], \[ScriptE]}, \[ScriptX]} =                        
Control`DEqns`nonaffinestatespaceForm[
eqs, {x[t], y[t], z[t], θ[t], ϕ[t]}, {}, {}, t, #[[1 ;; 2]] &,                                                
DescriptorStateSpace -> False];

The resulting expressions:

\[ScriptE]

{{1, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 1, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 1, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 1, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 1, 0}, {0, 1, 0, -l0 Cos[Subscript[[FormalX], 3][t]] Sin[ Subscript[[FormalX], 5][t]], 0, -l0 Cos[Subscript[[FormalX], 5][t]] Sin[ Subscript[[FormalX], 3][t]], 0, 0, 0, 0}, {0, 0, 0, l0 Cos[Subscript[[FormalX], 3][t]] Cos[ Subscript[[FormalX], 5][t]], 0, -l0 Sin[Subscript[[FormalX], 3][t]] Sin[ Subscript[[FormalX], 5][t]], 0, 1, 0, 0}, {0, 0, 0, l0 Sin[Subscript[[FormalX], 3][t]], 0, 0, 0, 0, 0, 1}, {0, -l0 Cos[Subscript[[FormalX], 3][t]] Sin[ Subscript[[FormalX], 5][t]], 0, l0^2, 0, 0, 0, l0 Cos[Subscript[[FormalX], 3][t]] Cos[ Subscript[[FormalX], 5][t]], 0, l0 Sin[Subscript[[FormalX], 3][t]]}, {0, -l0 Cos[ Subscript[[FormalX], 5][t]] Sin[Subscript[[FormalX], 3][t]], 0, 0, 0, l0^2 Sin[Subscript[[FormalX], 3][t]]^2, 0, -l0 Sin[Subscript[[FormalX], 3][t]] Sin[ Subscript[[FormalX], 5][t]], 0, 0}}

\[ScriptF]

{Subscript[[FormalX], 2][t], Subscript[[FormalX], 4][t], Subscript[[FormalX], 6][t], Subscript[[FormalX], 8][t], Subscript[[FormalX], 10][t], 2 l0 Cos[Subscript[[FormalX], 3][t]] Cos[ Subscript[[FormalX], 5][t]] Subscript[[FormalX], 4][ t] Subscript[[FormalX], 6][t] - l0 Sin[Subscript[[FormalX], 3][t]] Sin[ Subscript[[FormalX], 5][t]] (Subscript[[FormalX], 4][t]^2 + Subscript[[FormalX], 6][t]^2), 2 l0 Cos[Subscript[[FormalX], 3][t]] Sin[ Subscript[[FormalX], 5][t]] Subscript[[FormalX], 4][ t] Subscript[[FormalX], 6][t] + l0 Cos[Subscript[[FormalX], 5][t]] Sin[ Subscript[[FormalX], 3][t]] (Subscript[[FormalX], 4][t]^2 + Subscript[[FormalX], 6][t]^2), -l0 Cos[ Subscript[[FormalX], 3][t]] Subscript[[FormalX], 4][t]^2, l0 (g m Cos[Subscript[[FormalX], 3][t]] + l0 Cos[Subscript[[FormalX], 3][t]] Sin[ Subscript[[FormalX], 3][t]] Subscript[[FormalX], 6][ t]^2), -2 l0^2 Cos[Subscript[[FormalX], 3][t]] Sin[ Subscript[[FormalX], 3][t]] Subscript[[FormalX], 4][ t] Subscript[[FormalX], 6][t]}

\[ScriptX]

{Subscript[[FormalX], 1][t], Subscript[[FormalX], 2][t], Subscript[[FormalX], 3][t], Subscript[[FormalX], 4][t], Subscript[[FormalX], 5][t], Subscript[[FormalX], 6][t], Subscript[[FormalX], 7][t], Subscript[[FormalX], 8][t], Subscript[[FormalX], 9][t], Subscript[[FormalX], 10][t]}

The complication here is that $\mathit{e}$ is not invertible.

Source Link
Suba Thomas
  • 8.8k
  • 1
  • 17
  • 33

To convert ODEs (or difference equations) to state-space form you can use the functions StateSpaceModel, AffineStateSpaceModel, or NonlinearStateSpaceModel.

The input signatures of all three functions are the same. The first argument is the set of equations, the second argument is the set of states, the third argument is the set of inputs, the fourth argument is the outputs (which are a combination of the state and input variables) and the last argument is the temporal variable. The second and third argument also allows you to specify non-zero operating points (the default is zero). The set of states and inputs are mutually exclusive and all variables that depend on the temporal variable must belong to one of these two sets.

As of now, only StateSpaceModel supports DAEs. Before converting to the state-space representation, StateSpaceModel completely linearizes the system, AffineStateSpaceModel linearizes the input variables and the highest order state derivatives, and NonlinearStateSpaceModel linearizes the highest order state derivatives.

Basic examples of these can be found on the reference pages for StateSpaceModel(link), AffineStateSpaceModel (link), and NonlinearStateSpaceModel(link).