# System of ODE $\rightarrow$ Affine State-Space $\rightarrow$ System of ODE in Cauchy form

Given simple system of ODE:

$$\begin{cases} \dot{x}=G \\ \dot{z}=-z+\dot{f} \\ \dot{g}=-g+z \cdot s+u \\ \ddot{h}+\dot{h}+h=z \cdot m \end{cases}$$

where:

$$x,z,g,h$$ - state-space variables

$$f=-(x+s)^2$$

$$s=\alpha \sin(\omega t)$$

$$m=(\frac{16}{\alpha^2}(\sin(\omega t)-\frac{1}{2}))$$

This is my code transforming this system of equations into an affine state-space:

Clear["Derivative"]

ClearAll["Global*"]

s[t] = \[Alpha] Sin[\[Omega] t];
m[t] = 16/\[Alpha]^2 (Sin[\[Omega] t]^2 - 1/2);

f = -(x[t] + s[t])^2;

asys = AffineStateSpaceModel[{x'[t] == g[t], z'[t] == -z[t] + D[f, t],
g'[t] == -g[t] + z[t] s[t] + u[t],
h''[t] + h'[t] + h[t] == z[t] m[t]}, {{x[t], 1}, {z[t], 0}, {g[t],
0}, {h[t], 0}}, {u[t]}, {g[t], h[t]}, t] // Simplify


And there is my result:

Question: how to transform affine state-space to system of ODE, i.e. inverse tranform?

I will be glad to help.

I'm not very familiar with using state space models, but the following approach is deduced from the docs:

AffineStateSpaceModel[{a,b,...},x,u,y,t] explicitly specifies the input variables u, output variables y, and independent variable t,

where the first argument {a, b, c, d} provides

the state equations x'(t)==a(x(t))+b(x(t)).u(t) and output equation y(t)==c(x(t))+d(x(t)).u(t).

ClearAll[stateEqs];
stateEqs[
Verbatim[AffineStateSpaceModel][{a_, b_, c_, d_}, x0_, u0_, y_, t_]
] :=
Module[{u, x},
x = Replace[x0, {xx_, x1_} :> xx, 1];
u = Replace[u0, {uu_, u1_} :> uu, 1];
D[x, t] == a + b . u
];


With asys as in the OP and ode being the differential equations from the OP, we have the following:

newode = asys // stateEqs // Thread;
newode // ExpandAll // MapAt[Simplify, #, {All, 2}] & // Column

Reduce[ode, {x'[t], z'[t], g'[t], h''[t]}] /.
Thread[{x, z, g, h} -> Array[Subscript[\[FormalX], #] &, 4]] //
Apply[List] //
ExpandAll // MapAt[Simplify, #, {All, 2}] & // Column


Except for the first-orderization by AffineStateSpaceModel and the condition added by Reduce, the systems are the same. Since the state space models produces by the first-order system and the OP's system are identical, it's impossible to deduce from the state space model whether or not the 4th and 5th equations should be composed to produce a second order equation.

• how to remove the dots under the variables, and leave only \$x_1...x_4"
– dtn
May 16, 2021 at 15:50
• @dtn The dotted letters are "formal symbols" such as \[FormalX]. So expr /. \[FormalX] -> x will replace all occurrences of \[FormalX] with x. And newode /. Thread[Array[Subscript[\[FormalX], #] &, 5] -> {x, z, g, h, h'}] // DeleteCases[True] gives a system in the original terms (with x'[t]` eliminated from equation (2)). May 16, 2021 at 16:03
• Thank you very much )
– dtn
May 16, 2021 at 17:05
• I have one more small question. How can you use this code to turn the transfer function into a dissent equation in the Cauchy form?
– dtn
May 24, 2021 at 13:03
• @dtn I’m afraid I don’t know what a dissent equation is. And it doesn’t show up on Google for me. Does it have another name or an short definition? May 24, 2021 at 23:08