I'm designing a function in Python similar to MATLAB's 'feedback(T)' command. I know modules already exist, but it's something I want to do for myself for fun. However, I am running into issues. Let's say I have the transfer function of some arbitrary plant $$T(s) = {s + 5\over s^2 + 4s + 7}$$ Let's also say I have some arbitrary PID/PI/PD controller (Not to imply this controller is actually good, this is more to demonstrate the concept, so keep that in mind!)
$$C(s) ={2.3802s + 7.7309 \over s}$$
We know that the Closed Loop Feedback Transfer Function has the form of $$CLTF ={T(s)C(s) \over 1 + T(s)C(s)}$$
When CLTF computed above in Matlab, we get ... $$CLTF = {2.38 s^5 + 29.15 s^4 + 133.8 s^3 + 292 s^2 + 270.6 s\over s^6 + 10.38 s^5 + 59.15 s^4 + 189.8 s^3 + 341 s^2 + 270.6 s}$$
However, using MATLAB and feedback(T*C,1), we get the result of ... $$2.38 s^2 + 19.63 s + 38.65 \over s^3 + 6.38 s^2 + 26.63 s + 38.65$$
I already realize I can take my CLTF in MATLAB, put it in pole/zero (zpk) and things will cancel to get the same result as MATLAB's feedback command. However, no symbolic program seems to be able to factor these polynomials. MATLAB is clearly doing something I don't know about then. Does anyone have a clue how matlab's algorithm works? Or how I could code this same function?