|
75 | 75 |
|
76 | 76 | from numpy import all, angle, any, array, asarray, concatenate, cos, delete, \
|
77 | 77 | dot, empty, exp, eye, matrix, ones, pi, poly, poly1d, roots, shape, sin, \
|
78 |
| - zeros |
| 78 | + zeros, squeeze |
79 | 79 | from numpy.random import rand, randn
|
80 | 80 | from numpy.linalg import inv, det, solve
|
81 | 81 | from numpy.linalg.linalg import LinAlgError
|
@@ -459,28 +459,37 @@ def _convertToStateSpace(sys, **kw):
|
459 | 459 | # Already a state space system; just return it
|
460 | 460 | return sys
|
461 | 461 | elif isinstance(sys, xferfcn.TransferFunction):
|
462 |
| - from slycot import td04ad |
463 |
| - if len(kw): |
464 |
| - raise TypeError("If sys is a TransferFunction, _convertToStateSpace \ |
465 |
| -cannot take keywords.") |
| 462 | + try: |
| 463 | + from slycot import td04ad |
| 464 | + if len(kw): |
| 465 | + raise TypeError("If sys is a TransferFunction, _convertToStateSpace \ |
| 466 | + cannot take keywords.") |
| 467 | + |
| 468 | + # Change the numerator and denominator arrays so that the transfer |
| 469 | + # function matrix has a common denominator. |
| 470 | + num, den = sys._common_den() |
| 471 | + # Make a list of the orders of the denominator polynomials. |
| 472 | + index = [len(den) - 1 for i in range(sys.outputs)] |
| 473 | + # Repeat the common denominator along the rows. |
| 474 | + den = array([den for i in range(sys.outputs)]) |
| 475 | + # TODO: transfer function to state space conversion is still buggy! |
| 476 | + #print num |
| 477 | + #print shape(num) |
| 478 | + ssout = td04ad('R',sys.inputs, sys.outputs, index, den, num,tol=0.0) |
| 479 | + |
| 480 | + states = ssout[0] |
| 481 | + return StateSpace(ssout[1][:states, :states], |
| 482 | + ssout[2][:states, :sys.inputs], |
| 483 | + ssout[3][:sys.outputs, :states], |
| 484 | + ssout[4]) |
| 485 | + except ImportError: |
| 486 | + lti_sys = lti(squeeze(sys.num), squeeze(sys.den))#<-- do we want to squeeze first |
| 487 | + # and check dimenations? I think |
| 488 | + # this will fail if num and den aren't 1-D |
| 489 | + # after the squeeze |
| 490 | + return StateSpace(lti_sys.A, lti_sys.B, lti_sys.C, lti_sys.D) |
| 491 | + |
466 | 492 |
|
467 |
| - # Change the numerator and denominator arrays so that the transfer |
468 |
| - # function matrix has a common denominator. |
469 |
| - num, den = sys._common_den() |
470 |
| - # Make a list of the orders of the denominator polynomials. |
471 |
| - index = [len(den) - 1 for i in range(sys.outputs)] |
472 |
| - # Repeat the common denominator along the rows. |
473 |
| - den = array([den for i in range(sys.outputs)]) |
474 |
| - # TODO: transfer function to state space conversion is still buggy! |
475 |
| - #print num |
476 |
| - #print shape(num) |
477 |
| - ssout = td04ad('R',sys.inputs, sys.outputs, index, den, num,tol=0.0) |
478 |
| - |
479 |
| - states = ssout[0] |
480 |
| - return StateSpace(ssout[1][:states, :states], |
481 |
| - ssout[2][:states, :sys.inputs], |
482 |
| - ssout[3][:sys.outputs, :states], |
483 |
| - ssout[4]) |
484 | 493 | elif isinstance(sys, (int, long, float, complex)):
|
485 | 494 | if "inputs" in kw:
|
486 | 495 | inputs = kw["inputs"]
|
@@ -627,8 +636,8 @@ def _mimo2siso(sys, input, output, warn_conversion):
|
627 | 636 |
|
628 | 637 | If ``sys`` is already a SISO system, it will be returned unaltered.
|
629 | 638 |
|
630 |
| - Parameters: |
631 |
| - |
| 639 | + Parameters |
| 640 | + ---------- |
632 | 641 | sys: StateSpace
|
633 | 642 | Linear (MIMO) system that should be converted.
|
634 | 643 | input: int
|
|
0 commit comments