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}


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


$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:



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:

enter image description here

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

I will be glad to help.


1 Answer 1


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).

 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.

  • $\begingroup$ how to remove the dots under the variables, and leave only $x_1...x_4" $\endgroup$
    – dtn
    May 16, 2021 at 15:50
  • 2
    $\begingroup$ @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)). $\endgroup$
    – Michael E2
    May 16, 2021 at 16:03
  • $\begingroup$ Thank you very much ) $\endgroup$
    – dtn
    May 16, 2021 at 17:05
  • $\begingroup$ 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? $\endgroup$
    – dtn
    May 24, 2021 at 13:03
  • 1
    $\begingroup$ @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? $\endgroup$
    – Michael E2
    May 24, 2021 at 23:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.