I have the following closed-loop system: $$sys=\frac{0.009211 s^6 + 10.58 s^5 + 55.97 s^4 - 82.77 s^3 - 774.1 s^2 - 871.8 s}{7.656e-07 s^8 + 0.00175 s^7 + 1.009 s^6 + 10.53 s^5 + 28.37 s^4 - 82.44 s^3 - 583.6 s^2- 871.8 s}$$ analysis stability by positioning of poles with Matlab gives that one pole has positive real part:
in Matlab
pole(sys)
ans =
1.0e+03 *
0.0000 + 0.0000i
-1.1429 + 0.0000i
-1.1323 + 0.0000i
0.0037 + 0.0000i (unstable)
-0.0034 + 0.0023i
-0.0034 - 0.0023i
-0.0038 + 0.0000i
-0.0037 + 0.0000i
while the step response of the system is stable
That system is a second order plant with PID controller; the plant is
a=[0 1;13.8 0];
b=[0;-2.568];
c=[1 0];
d=0;
[f,g]=ss2tf(a,b,c,d);
plant=tf(f,g);
The PID controller:
s=tf('s');
Kp=-21.8;
Ki=-24.6;
Kd=-4.08;
Tf=0.000875;
u=Kp+Ki*(1/s)+Kd*(s/(Tf*s+1));
The closed loop system;
sys=u * plant/(1+u*plant);
After that you can check poles and step response as above.

There are two different problems here.
1.) If you don't pass a time vector to the step function, Matlab can't know how long it should simulate. So, it makes a guess, based on heuristics with the goal to simulate long enough to capture everything that is "interesting".
This guess can be wrong: Let's take the transfer function from your question:
This code reproduces your problem. Now, instead of
step(G);use:And you will see that the output diverges, i.e. the transfer function is not stable.
However, there are also numerical problems (especially when dealing with high order polynomials), which leads to your second problem.
2.) Numerical pole-zero cancellation. You know something is wrong here because closing the loop should not increase the system order. Your open loop transfer function is of order $4$, so should your closed loop transfer function. But it is actually of order $8$.
You can solve this numerically by using
G = minreal(G);. This will reduce the order to $4$ and this transfer function will also be stable.To ensure that with
minrealno actual unstable poles are cancelled out, it is always good to use symbolic calculations as a double check (for example the symbolic toolbox, if you have access to it):This will show
Check the roots:
Stable.