I want to find statespace model of calculated dynamic equations from given equations and eliminations in Mathematica (all the commands should be in one line), but it does not work properly, here is a simple example of my case:

StateSpaceModel[{Flatten@Solve[Eliminate[{a == b1 + c *x1''[t], 
b2 == e* (x2[t] - y[t]) + f *(x2'[t] - y'[t]) + d *x2''[t],
g*y''[t] + e*(y[t] - x2[t]) + f*(y'[t] - x2'[t]) + m == 0,
n *z''[t] == m - R, b1 == b2, y[t] == 2* z[t], y'[t] == 2 *z'[t],
y''[t] == 2 *z''[t], x1[t] == x2[t], x1'[t] == x2'[t], x1''[t] == x2''[t]}, 
{b1, b2, y[t], y'[t], y''[t], m, x2[t], x2'[t], x2''[t]}],
{x1''[t], z''[t]}]}, {{x1'[t], 0}, {x1[t], 0}, {z'[t], 0},
{z[t], 0}}, {{a, 0}}, {z'[t], 0}]

Calculating dynamic equations from equations and elimination is giving a result for x1''[t] and z''[t] perfectly as desired, but the rest of the code which is to calculate state space model using the defined states to be x1'[t], x1[t], z'[t], z[t] and the output of z'[t] with an input of a is not working. Any ideas would be appreciated.


1 Answer 1


There are some syntactical errors.

  • You need to specify equations and not rules.

  • If $a$ is an input variable, it should be specified as $a[t]$.

  • Only the operating values of states and inputs need to be specified. The output operating value is determined based on that.

  • The temporal variable needs to be specified as well.

     StateSpaceModel[Equal @@@ 
     Flatten[Solve[Eliminate[{a[t] == b1 + c*x1''[t], 
     b2 == e*(x2[t] - y[t]) + f*(x2'[t] - y'[t]) + d*x2''[t], 
     g*y''[t] + e*(y[t] - x2[t]) + f*(y'[t] - x2'[t]) + m == 0, 
     n*z''[t] == m - R, b1 == b2, y[t] == 2*z[t], y'[t] == 2*z'[t], 
     y''[t] == 2*z''[t], x1[t] == x2[t], x1'[t] == x2'[t], 
     x1''[t] == x2''[t]}, {b1, b2, y[t], y'[t], y''[t], m, x2[t], 
     x2'[t], x2''[t]}], {x1''[t], z''[t]}]], 
     {{x1'[t], 0}, {x1[t], 0}, {z'[t], 0}, {z[t], 0}}, 
     {{a[t], 0}}, 

enter image description here

  • $\begingroup$ thanks for your answer, now it works, but I am wondering does this work for nonlinear dynamic equations as well, if I just change the command to NonlinearStateSpaceModel? @Suba Thomas $\endgroup$
    – F R
    Nov 14, 2016 at 18:02
  • $\begingroup$ Essentially, yes. It is the same usage. StateSpaceModel will throw out all nonlinear terms. NonlinearStateSpaceModel will only throw out nonlinearities in the highest order derivatives. $\endgroup$ Nov 14, 2016 at 18:23
  • $\begingroup$ You can give nonlinear equations to both StateSpaceModel and NonlinearStateSpaceModel (and also AffineStateSpaceModel). The difference is what information each will discard to get the final result. $\endgroup$ Nov 14, 2016 at 18:25
  • $\begingroup$ Thanks for your comment, but NonlinearStateSpaceModel command does not give an answer in matrix form (the way that StateSpaceModel command does), so I was wondering is there a way in mixed of nonlinear and linear equations to linearize the nonlinear ones around an applied point and calculate the state space model for both nonlinear and linear differential equations in one line command? @Suba Thomas $\endgroup$
    – F R
    Nov 15, 2016 at 9:34
  • $\begingroup$ Of course, NonlinearStateSpaceModel will not linearize completely, so there are no matrices there. Just use StateSpaceModel. It will linearize mixed linear and nonlinear equations. I think you are missing that StateSpaceModel is basically a linear model. It will throw away nonlinear terms to do the linearization and get the matrices. $\endgroup$ Nov 15, 2016 at 14:31

Your Answer

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

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