Skip to content

Error in conversion of a MIMO transfer function model into state space #141

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
gpannocchia opened this issue Mar 27, 2017 · 12 comments
Closed

Comments

@gpannocchia
Copy link

Dear python-control developers,

Thank you very much for the toolbox, which I am using in a process control course at the University of Pisa.

I am having problems in converting a 2-input, 2-output transfer function model into state space.
Here is the minimal code:


import control as cnt

Defining a MIMO system in TF

NUM = [[[12.8], [-18.9]],[[6.6], [-19.4]]]
DEN = [[[16.7, 1.], [21.,1.]],[[10.9,1.], [14.4,1.]]]
G = cnt.TransferFunction(NUM, DEN)
print "MIMO system = ", G

Conversion to state-space

Gss = cnt.tf2ss(G)


Running this code (MacOS X, python 2.7, python-control 0.70) indicates that the transfer function model is properly defined, but then the conversion function returns he following error:


File "/Users/gp/anaconda/lib/python2.7/site-packages/spyder/utils/site/sitecustomize.py", line 866, in runfile
execfile(filename, namespace)

File "/Users/gp/anaconda/lib/python2.7/site-packages/spyder/utils/site/sitecustomize.py", line 94, in execfile
builtins.execfile(filename, *where)

File "/Users/gp/Desktop/MIMOexample.py", line 17, in
Gss = cnt.tf2ss(G)

File "/Users/gp/anaconda/lib/python2.7/site-packages/control/matlab.py", line 764, in tf2ss
return _convertToStateSpace(sys)

File "/Users/gp/anaconda/lib/python2.7/site-packages/control/statesp.py", line 667, in _convertToStateSpace
lti_sys = lti(squeeze(sys.num), squeeze(sys.den))

File "/Users/gp/anaconda/lib/python2.7/site-packages/scipy/signal/ltisys.py", line 761, in init
self.num, self.den = normalize(*system)

File "/Users/gp/anaconda/lib/python2.7/site-packages/scipy/signal/filter_design.py", line 1080, in normalize
raise ValueError("Denominator polynomial must be rank-1 array.")


Is there any error in my code or is this indeed a bug?

Thank you in advance for your time and reply.

Best regards,

Gabriele Pannocchia

@murrayrm
Copy link
Member

murrayrm commented Mar 29, 2017

This seems to be working correctly in the current master branch (ctr.__version__ = 0.7.0.post98). Specifically, I get the following output:

Input 1 to output 1:
   12.8
----------
16.7 s + 1

Input 1 to output 2:
    6.6
----------
10.9 s + 1

Input 2 to output 1:
  -18.9
--------
21 s + 1

Input 2 to output 2:
  -19.4
----------
14.4 s + 1

The value of Gss at the end is

A = [[  6.59035825e-02   3.44749990e-16  -2.83940355e-02  -3.09834555e-16]
 [ -3.32547182e-16   6.17600374e-02   4.18652925e-16  -3.00648692e-02]
 [  5.02898234e-01  -1.11438636e-14  -1.73402870e-01   1.71714604e-15]
 [  0.00000000e+00   6.69894887e-01   1.73674365e-15  -2.22947601e-01]]

B = [[ 0.1741107  -0.22652535]
 [ 0.1188204  -0.3093011 ]
 [ 0.77129964 -0.9056745 ]
 [ 0.6066651  -1.34980432]]

C = [[  0.00000000e+00   0.00000000e+00   9.93734502e-01  -3.33066907e-16]
 [  0.00000000e+00   0.00000000e+00   0.00000000e+00   9.98087058e-01]]

D = [[ 0.  0.]
 [ 0.  0.]]

Can you try grabbing the current master branch via git and see if that works? If so, a good indication that it is time to post a new release to SourceForge.

@murrayrm
Copy link
Member

Also: can you post what version of scipy you are using? It could be the problem is there (since scipy.normalize is throwing the error). My tests above were done with scipy v0.18.1.

@gpannocchia
Copy link
Author

gpannocchia commented Mar 29, 2017 via email

@gpannocchia
Copy link
Author

gpannocchia commented Mar 29, 2017 via email

@murrayrm
Copy link
Member

murrayrm commented Mar 29, 2017

For posterity, the lack of error message when slycot is missing is related to issue #120 and was fixed in commit c90a399.

@murrayrm
Copy link
Member

On Mar 29, 2017, at 02:35, Gabriele Pannocchia <gabriele.pannocchia@unipi.it> wrote:

Do I need python3.x for slycot, right? (see below)

I am using python2.7 but if necessary, I should have no problem is switching to python3.x...

Gabrieles-MBP:site-packages gp$ conda install -c python-control -c cyclus slycot control
Fetching package metadata ...............
Solving package specifications: .


UnsatisfiableError: The following specifications were found to be in conflict:
  - python 2.7*
  - slycot -> python 3.5*
Use "conda info <package>" to see the dependencies for each package.

Thanks,

	Gabriele

There is some discussion of this in issue #136 and #106. While not required, the issue is that we have not (yet) build slycot for the python 2.7 distribution. Installing with pip as describe in #136 might work.

@gpannocchia
Copy link
Author

gpannocchia commented Mar 29, 2017 via email

@murrayrm
Copy link
Member

Can you confirm that slycot is installed and that python is finding it? Something like

import slycot
import control
print control.slycot_check()

should work (return True). If that is working, then try installing the latest version of python-control (from GitHub) and see if that fixes the problem. (It could be that tf2ss requires both slycot and latest version of python-control)

@gpannocchia
Copy link
Author

gpannocchia commented Mar 29, 2017 via email

@murrayrm
Copy link
Member

It looks like the problem is that slycot is expecting a GCC installation with libgfortran and it is not finding it. Strictly speaking, this is not a python-control problem, but a slycot problem.

There are a couple of possible fixes.

  • You can install slycot from source. You'll need a FORTRAN compiler. See the README file in the slycot source distribution. It's possible that once you install FORTRAN, slycot will start working without recompiling (because the gfortran library might be in place.
  • You can find someone who has installed slycot on a machine with the same architecture and try to copy over the missing library file.
  • You can write a backup tf2ss function that handles MIMO and doesn't use slycot.

Sorry this is such a hassle, but one of the consequences of our choice to rely on slycot is that you have to install it and we haven't yet found a good way to make this work automatically across operating systems.

Suggestions from others welcome!

@gpannocchia
Copy link
Author

gpannocchia commented Mar 30, 2017 via email

@murrayrm
Copy link
Member

Issue tracked down to problems with slycot installation. I verified that latest code generates an error message if slycot is not installed. Closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants