Skip to content

miso tf2ss fails without slycot #120

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
jgoppert opened this issue Nov 14, 2016 · 3 comments
Closed

miso tf2ss fails without slycot #120

jgoppert opened this issue Nov 14, 2016 · 3 comments
Assignees
Labels

Comments

@jgoppert
Copy link
Contributor

jgoppert commented Nov 14, 2016

This looks like it is failing to throw the warning to the user about it being miso and not supported without slycot for some reason.

tf = control.tf([[[-235, 1.146e4],
    [-235, 1.146E4],
    [-235, 1.146E4, 0]]],
    [[[1, 48.78, 0],
      [1, 48.78, 0, 0],
      [0.008, 1.39, 48.78]]])
tf
Out[80]:

Input 1 to output 1:
-235 s + 1.146e+04
------------------
  s^2 + 48.78 s

Input 2 to output 1:
-235 s + 1.146e+04
------------------
  s^3 + 48.78 s^2

Input 3 to output 1:
  -235 s^2 + 1.146e+04 s
--------------------------
0.008 s^2 + 1.39 s + 48.78
In [81]:

​
control.tf2ss(tf)
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
/home/jgoppert/anaconda3/lib/python3.5/site-packages/control-dev-py3.5.egg/control/statesp.py in _convertToStateSpace(sys, **kw)
    646         try:
--> 647             from slycot import td04ad
    648             if len(kw):

ImportError: No module named 'slycot'

During handling of the above exception, another exception occurred:

ValueError                                Traceback (most recent call last)
<ipython-input-81-c8ef26438f31> in <module>()
      1 
----> 2 control.tf2ss(tf)

/home/jgoppert/anaconda3/lib/python3.5/site-packages/control-dev-py3.5.egg/control/statesp.py in tf2ss(*args)
   1082             raise TypeError("tf2ss(sys): sys must be a TransferFunction \
   1083 object.")
-> 1084         return _convertToStateSpace(sys)
   1085     else:
   1086         raise ValueError("Needs 1 or 2 arguments; received %i." % len(args))

/home/jgoppert/anaconda3/lib/python3.5/site-packages/control-dev-py3.5.egg/control/statesp.py in _convertToStateSpace(sys, **kw)
    671             # I think this will fail if num and den aren't 1-D after
    672             # the squeeze
--> 673             lti_sys = lti(squeeze(sys.num), squeeze(sys.den))
    674             return StateSpace(lti_sys.A, lti_sys.B, lti_sys.C, lti_sys.D,
    675                               sys.dt)

/home/jgoppert/anaconda3/lib/python3.5/site-packages/scipy/signal/ltisys.py in __init__(self, *system, **kwargs)
    759         self._den = None
    760 
--> 761         self.num, self.den = normalize(*system)
    762 
    763     def __repr__(self):

/home/jgoppert/anaconda3/lib/python3.5/site-packages/scipy/signal/filter_design.py in normalize(b, a)
   1084     if len(b.shape) == 1:
   1085         b = asarray([b], b.dtype.char)
-> 1086     while a[0] == 0.0 and len(a) > 1:
   1087         a = a[1:]
   1088     outb = b * (1.0) / a[0]

ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
@jgoppert jgoppert changed the title mimo ss2tf fails without slycot miso ss2tf fails without slycot Nov 14, 2016
@jgoppert jgoppert changed the title miso ss2tf fails without slycot miso tf2ss fails without slycot Nov 14, 2016
@roryyorke
Copy link
Contributor

Scipy doesn't seem to like SIMO or MISO, including when denominators are matched. Note the error in that last case: I get the feeling scipy.signal.lti is intended for SISO.

import sys
import numpy
import scipy
print('sys.version:',sys.version)
print('numpy.__version__:',numpy.__version__)
print('scipy.__version__:',scipy.__version__)

import numpy as np
from control.matlab import *
import scipy.signal

def testit(sys):
    print('sys is ',sys.outputs,'x',sys.inputs)
    try:
        scipy.signal.lti(np.squeeze(sys.num),np.squeeze(sys.den))
        print('success!')
    except ValueError as e:
        print('gives ValueError',e)

# 1x1
testit(tf([1],[1,1]))
# 1x1 as list-of-list-of-vectors
testit(tf([[[1]]],[[[1,1]]]))

# 1x3
testit(tf([[[-235, 1.146e4],
         [-235, 1.146E4],
         [-235, 1.146E4, 0]]],
         [[[1, 48.78, 0],
           [1, 48.78, 0, 0],
           [0.008, 1.39, 48.78]]]))

# 3x1
testit(tf([[[-235, 1.146e4]],
        [[-235, 1.146E4]],
        [[-235, 1.146E4, 0]]],
         [[[1, 48.78, 0]],
           [[1, 48.78, 0, 0]],
           [[0.008, 1.39, 48.78]]]))

# 3x1 with matched denominators
testit(tf([[[-235, 1.146e4]],
        [[-235, 1.146E4]],
        [[-235, 1.146E4, 0]]],
         [[[1, 48.78, 0]],
           [[1, 48.78, 0]],
           [[1, 48.78, 0]]]))

gives

$ python sample.py 
sys.version: 3.5.2 |Continuum Analytics, Inc.| (default, Jul  2 2016, 17:53:06) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)]
numpy.__version__: 1.11.1
scipy.__version__: 0.18.0
sys is  1 x 1
success!
sys is  1 x 1
success!
sys is  1 x 3
gives ValueError The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
sys is  3 x 1
gives ValueError The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
sys is  3 x 1
gives ValueError Denominator polynomial must be rank-1 array.

murrayrm added a commit to murrayrm/python-control that referenced this issue Dec 26, 2016
@murrayrm
Copy link
Member

Since I was fixing up some errors associated with not having slycot installed, I went ahead and addressed this in c90a399. Should be fine to resolve once PR #122 is accepted.

@murrayrm murrayrm added the bug label Dec 26, 2016
@murrayrm murrayrm self-assigned this Dec 26, 2016
@slivingston
Copy link
Member

addressed by commit c90a399, now in master branch from PR #122

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

No branches or pull requests

4 participants