# Wrong answers while trying to analyze stability

I want to analyze the stability of a closed-loop system (with feedback). The idea is to choose a proper gain kc for the controller. The code is the following:

Clear[tfm, stableQ, charPoly, AA, BB, kc, A, B, Cc]
A = {{-64.383, 0, -22.35, 0}, {0, 0, 27.65, -50}, {1788, -2212, 0,
0}, {0, 4000, 0, -333.333}};
B = {3619.3, 3619.3, -29800, 0} ;
Cc = {0, 0, 0, 1} ;
AA = A - Outer[Times, B ka kst kc, Cc];
ka = 1/20
BB = B ka kc;
kst = 1/10;

ssm = TransferFunctionModel[
StateSpaceModel[{AA, Transpose@{BB} , {Cc}}], s]
charPoly =
Denominator[SystemsModelFeedbackConnect[ssm][s][[1, 1]]] == 0
stableQ[k_] := AllTrue[s /. NSolve[charPoly /. kc -> k, s], Re[#] < 0 &]

TableForm[Table[{k, stableQ[k]}, {k, 2, 3, 0.1}],


I'm using AA and BB because they are the matrices for the closed-loop system. The table should start returning "False" when the real part of the roots of the char. polynomial are greater or equal zero. However, the table just returns "False" for all the values of kc. That isn't true because if we get get eigenvalues of AA,there are values of kc that makes the real part less than zero. (i.e for kc <2.6).

Actually, for kc=2,

Eigenvalues[AA]
{-188.638 + 612.413 I, -188.638 - 612.413 I, -10.2203 +
221.148 I, -10.2203 - 221.148 I}


Clearly for kc=2, the real part is negative so the system is stable. But as I said above, when I run the code the table is:

The results of the table doesn't match what I see with the eigenvalues.

$\textbf{UPDATE}$

I solved it using different commands:

Clear[x1, x2, x3, x4, x11, x22, x33, x44, sol1, sol2, yd, AA, kc, BB, \
Cc, B, A, charPoly, ssm, stableQ]
kst = 1/10;
ka = 1/20;
BB = B ka kc;
A = {{-64.383, 0, -22.35, 0}, {0, 0, 27.65, -50}, {1788, -2212, 0,
0}, {0, 4000, 0, -333.333}};
B = {3619.3, 3619.3, -29800, 0} ;
Cc = {0, 0, 0, 1} ;
AA = A - Outer[Times, B ka kst kc, Cc];
(*NRoots[Re[Eigenvalues[A-Outer[Times,B ka kst kc,Cc]]] \[Equal]0,kc]
FindInstance[Re[Eigenvalues[A-Outer[Times,B ka kst kc,Cc]]]<0,kc,Reals]
Eigenvalues[A-Outer[Times,B ka kst 210,Cc]]*)
\
(*ssm=TransferFunctionModel[StateSpaceModel[{A,Transpose@{B}ka kc \
kst,{Cc}}],s];
charPoly=Denominator[SystemsModelFeedbackConnect[ssm][s][[1,1]]]\
\[Equal]0;
*)
Charpol = CharacteristicPolynomial[AA, s]
stableQ[k_] := AllTrue[s /. NSolve[Charpol /. kc -> k, s], Re[#] < 0 &]
TableForm[Table[{k, stableQ[k]}, {k, 2, 3, 0.1}],

• stableQ[k_] := AllTrue[s /. NSolve[char /. kc -> k, s], Re[#] < 0 &] I do not see char defined any where in your code. – Nasser Sep 9 '17 at 23:03
• Your kst is undefined. – Nasser Sep 9 '17 at 23:16
• however if I get the Eigenvalues for, say, k=0.8 it is not clear what you are referring to. eigenvalue of what? Can you show what you did there? Please add more words to make the description clear. It is clear that the roots of your char poly for the closed loop system is not stable for these gains you selected? – Nasser Sep 10 '17 at 1:19