1
$\begingroup$

I have noted that sometimes state variables may change (thanks Thomas’s help :)), due to the Mathematica’s internal automatic transformation from a descriptor state-space model to a standard state-space model.

I think that the relationship x’ = a.x + b.u, y = c . x + d.u should hold in any state-space.

However, this relationship doesn’t hold in the following state-space model. Instead, I found that x’ = a.x - b.u, y = - c . x + d.u hold in my state-space model. Why does this happen?

By the way, I believe that I used the right state variable in my code.


code:

Remove["Global`*"] // Quiet;

m = {{Subscript[\[ScriptM], 1], 0, 0}, {0, Subscript[\[ScriptM], 2], 
    0}, {0, 0, Subscript[\[ScriptM], 3]}};
k = Array[Subscript[\[ScriptK], #1, #2] &, {3, 3}];
c = Array[Subscript[\[ScriptC], #1, #2] &, {3, 3}];
bs = {{1, -1, 0}, {0, 1, -1}, {0, 0, 1}};
\[CapitalLambda] = {{1, 1, 1}}\[Transpose];

uf = {uf1[t], uf2[t], uf3[t]};
ue = {ue1[t], ue2[t], ue3[t]};
pN = {pN1[t], pN2[t], pN3[t]};
mN = {mN1[t], mN2[t], mN3[t]};
u = Flatten@{uf, ue, pN, mN};
lhs = Flatten[
   m.{x1''[t], x2''[t], x3''[t]} + c.{x1'[t], x2'[t], x3'[t]} + 
    k.{x1[t], x2[t], x3[t]}];
rhs = Flatten[+m.ue + bs.uf + m.\[CapitalLambda] pN];
eq = lhs - rhs == 0 // Thread;

y = {x1''[t], x2''[t], x3''[t]} + ue + mN;
z = {x3'[t], x3[t], x2'[t], x2[t], x1'[t], x1[t]};

ss = StateSpaceModel[eq, z, u, y, t, 
   SystemsModelLabels -> {ToString /@ u, ToString /@ y, 
     ToString /@ z}];
{AA, BB, CC, DD} = Normal[ss];
ddxEQ = Flatten[Solve[eq, {x3''[t], x2''[t], x1''[t]}]][[All, 2]];
ddxSS = (AA.z - BB.u)[[1 ;; -1 ;; 2]];


ddxEQ - ddxSS // Simplify
Reverse[ddxEQ] + ue + mN - Flatten[-CC.z + DD.u] // Simplify

result of code

$\endgroup$
1
$\begingroup$

This is the same issue I had pointed out in an earlier post.

In general, the variables you give in the second argument to StateSpaceModel are not the states. In this case they are $\left\{-\text{x3}'(t),-\text{x3}(t),-\text{x2}'(t),-\text{x2}(t),-\text{x1}'(t),-\text{x1}(t)\right\}$. You can determine that from the computations below.

states = Array[v, 6];
ssPrelim = StateSpaceModel[eq, {x3'[t], x3[t], x2'[t], x2[t], x1'[t], x1[t]}, u, 
  Join[vars = {x1[t], x2[t], x3[t], x1'[t], x2'[t], x3'[t]}, y], t];
z = states /. Solve[Thread[vars == Normal[ssPrelim][[3, 1 ;;Length@vars]].states], states][[1]]
ss = StateSpaceModel[SystemsModelDelete[ssPrelim, None, Range[6]], 
  SystemsModelLabels -> {ToString /@ u, ToString /@ y, ToString /@ z}];

enter image description here

And then the verification works.

{AA, BB, CC, DD} = Normal[ss];
ddxEQ = Flatten[Solve[eq, {x3''[t], x2''[t], x1''[t]}]][[All, 2]];
ddxSS = -(AA.z + BB.u)[[1 ;; -1 ;; 2]];
ddxEQ - ddxSS // Simplify
Reverse[ddxEQ] + ue + mN - Flatten[CC.z + DD.u] // Simplify

{0, 0, 0}

{0, 0, 0}

Update

In v12.1, the states will be the specified variables. Earlier, when possible, this worked for standard state-space systems. Now it also does so for descriptor systems.

ss = StateSpaceModel[eq, z, u, y, t, 
     SystemsModelLabels -> {ToString /@ u, ToString /@ y, ToString /@ z}];
{AA, BB, CC, DD} = Normal[ss];
ddxEQ = Flatten[Solve[eq, {x3''[t], x2''[t], x1''[t]}]][[All, 2]];
ddxSS = (AA.z + BB.u)[[1 ;; -1 ;; 2]];
ddxEQ - ddxSS // Simplify
Reverse[ddxEQ] + ue + mN - Flatten[CC.z + DD.u] // Simplify

{0, 0, 0}

{0, 0, 0}

The above calculation now works because the resulting states in fact the specified variables z.

states = Array[v, 6]; 
ssPrelim = StateSpaceModel[eq, z, u, 
           Join[vars = {x1[t], x2[t], x3[t], x1'[t], x2'[t], x3'[t]}, y], t];
states /. Solve[Thread[vars == Normal[ssPrelim][[3, 1 ;;Length@vars]].states], states][[1]]
z

enter image description here

| improve this answer | |
$\endgroup$
  • $\begingroup$ Thanks, your answer perfectly solved my problem and greatly enhanced my understanding of state space model :) $\endgroup$ – xinxin guo Nov 7 '19 at 1:44
  • $\begingroup$ Glad to be of help. For a system like StateSpaceModel[x''[t]==u[t],{x'[t],x[t]},u[t],x[t],t], the states are correctly ordered. I think we can do the same for descriptor systems, as the one in your example. Thanks much for your question, it has given me something to chew on. $\endgroup$ – Suba Thomas Nov 7 '19 at 14:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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