Skip to content

miso tf2ss fails without slycot #120

Description

@jgoppert

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()

Activity

  1. changed the title [-]mimo ss2tf fails without slycot[/-] [+]miso ss2tf fails without slycot[/+] on Nov 14, 2016
  2. changed the title [-]miso ss2tf fails without slycot[/-] [+]miso tf2ss fails without slycot[/+] on Nov 14, 2016
  3. roryyorke commented on Dec 26, 2016

    @roryyorke
    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.
    
  4. murrayrm commented on Dec 26, 2016

    @murrayrm
    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.

  5. self-assigned this
    on Dec 26, 2016
  6. slivingston commented on Jan 1, 2017

    @slivingston
    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

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions