question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Incorrect rootlocus plot

See original GitHub issue

I’m using the control package in a modified jupyter/scipy docker container. The modification to the container were just to install the controls package (RUN pip3 install control). When i try to plot the root locus of a inverted pendulum with 2 roots at 0, it outputs the wrong rootlocus.

Minimal working example:

import numpy as np
import control

A = np.array([[0,1,0,0],[0,0,-1,0],[0,0,0,1],[0,0,5,0]])
B = np.array([[0],[1],[0],[-2]])
C = np.array([1,0,0,0])
D = 0
sys = control.ss(A,B,C,D)
r = control.root_locus(sys, xlim=[-2,2],ylim=[-7,7])

The above code results in the following plot image When the same system in plotted in octave, it gives the following rlocus image

As can be seen there should be no branch immediately to the left of 0

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
murrayrmcommented, Mar 28, 2022

I chased this down a bit more. The difference seems to come from the way that slycot creates the transfer function representation of the system versus the way that SciPy carries out the calculation (via scipy.signal.ss2tf).

Slycot:

  • Poles: array([ 2.23606798e+00, -2.23606798e+00, 1.26650220e-17, 1.26650216e-17])
  • Zeros: array([ 1.73205081, -1.73205081])

SciPy:

  • Poles: array([-2.23606798, 2.23606798, 0. , 0. ])
  • Zeros: array([-2.68871620e+14, 1.73205081e+00, -1.73205081e+00])

Interestingly, SciPy throws a warning when computing the poles:

/Users/murray/anaconda3/envs/python3.9-slycot/lib/python3.9/site-
packages/scipy/signal/filter_design.py:1630: BadCoefficients: Badly
conditioned filter coefficients (numerator): the results may be meaningless

So it looks like the problem is the (fast, stable) zero at -2.689e+14, which completely throws off the root locus plot. Not sure how to fix without implementing our own transfer function calculation rather than rely on SciPy.

I looked at the source code for the SciPy function and the basic calculation is:

den = poly(A)
num[k] = poly(A - dot(B, C[k:k+1, :])) + (D[k] - 1) * den

The Slycot computation for tb04ad (the function that gets calls) says:

The method for transfer matrices factorized by rows will be described here: T(s) factorized by columns is dealt with by operating on the dual of the original system. Each row of T(s) is simply a single-output relatively left prime polynomial matrix representation, so can be calculated by applying a simplified version of the Orthogonal Structure Theorem to a minimal state-space representation for the corresponding row of the given system. A minimal state-space representation is obtained using the Orthogonal Canonical Form to first separate out a completely controllable one for the overall system and then, for each row in turn, applying it again to the resulting dual SIMO (single-input multi-output) system. Note that the elements of the transformed matrix A so calculated are individually scaled in a way which guarantees a monic denominator polynomial.

0reactions
warlock31415commented, Mar 28, 2022

Doesn’t work without slycot with the pacakage versions you mentioned. Works with the mentioned packages with slycot

Read more comments on GitHub >

github_iconTop Results From Across the Web

Which of the following statement is incorrect for root locus ...
The root locus diagram is plotted by using the open-loop poles but not the closed-loop poles. This method is very much useful because...
Read more >
Why is the Root Locus Plot Important? - Swarthmore College
As an engineer the problem is typically the reverse. You know what kind of system response you want, and it is your job...
Read more >
Root Locus Technique (Problems) - YouTube
Rules to Plot Root Locus - Root Locus Analysis - Control Systems · root locus in control system · Root locus for complex...
Read more >
EXAMPLE PROBLEMS AND SOLUTIONS - ResearchGate
The root-locus plot for this system is shown in Figure 6-3Y(h). Note that this system is stable for m y ... This fact...
Read more >
Root Locus Analysis & Design
Mechatronics. Root Locus Analysis and Design. K. Craig. 9. Problem: Determine the roots of the characteristic equation for all values of K and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found