|
77 | 77 | from .. import freqplot |
78 | 78 | from .. import timeresp |
79 | 79 | from .. import margins |
80 | | -from ..statesp import StateSpace, _rss_generate, _convertToStateSpace |
| 80 | +from ..statesp import * |
81 | 81 | from ..xferfcn import TransferFunction, _convertToTransferFunction |
82 | 82 | from ..lti import LTI # base class of StateSpace, TransferFunction |
83 | 83 | from ..lti import issiso |
|
387 | 387 |
|
388 | 388 | """ |
389 | 389 |
|
390 | | -def ss(*args): |
391 | | - """ |
392 | | - Create a state space system. |
393 | | -
|
394 | | - The function accepts either 1, 4 or 5 parameters: |
395 | | -
|
396 | | - ``ss(sys)`` |
397 | | - Convert a linear system into space system form. Always creates a |
398 | | - new system, even if sys is already a StateSpace object. |
399 | | -
|
400 | | - ``ss(A, B, C, D)`` |
401 | | - Create a state space system from the matrices of its state and |
402 | | - output equations: |
403 | | -
|
404 | | - .. math:: |
405 | | - \dot x = A \cdot x + B \cdot u |
406 | | -
|
407 | | - y = C \cdot x + D \cdot u |
408 | | -
|
409 | | - ``ss(A, B, C, D, dt)`` |
410 | | - Create a discrete-time state space system from the matrices of |
411 | | - its state and output equations: |
412 | | -
|
413 | | - .. math:: |
414 | | - x[k+1] = A \cdot x[k] + B \cdot u[k] |
415 | | -
|
416 | | - y[k] = C \cdot x[k] + D \cdot u[ki] |
417 | | -
|
418 | | - The matrices can be given as *array like* data types or strings. |
419 | | - Everything that the constructor of :class:`numpy.matrix` accepts is |
420 | | - permissible here too. |
421 | | -
|
422 | | - Parameters |
423 | | - ---------- |
424 | | - sys: StateSpace or TransferFunction |
425 | | - A linear system |
426 | | - A: array_like or string |
427 | | - System matrix |
428 | | - B: array_like or string |
429 | | - Control matrix |
430 | | - C: array_like or string |
431 | | - Output matrix |
432 | | - D: array_like or string |
433 | | - Feed forward matrix |
434 | | - dt: If present, specifies the sampling period and a discrete time |
435 | | - system is created |
436 | | -
|
437 | | - Returns |
438 | | - ------- |
439 | | - out: :class:`StateSpace` |
440 | | - The new linear system |
441 | | -
|
442 | | - Raises |
443 | | - ------ |
444 | | - ValueError |
445 | | - if matrix sizes are not self-consistent |
446 | | -
|
447 | | - See Also |
448 | | - -------- |
449 | | - tf |
450 | | - ss2tf |
451 | | - tf2ss |
452 | | -
|
453 | | - Examples |
454 | | - -------- |
455 | | - >>> # Create a StateSpace object from four "matrices". |
456 | | - >>> sys1 = ss("1. -2; 3. -4", "5.; 7", "6. 8", "9.") |
457 | | -
|
458 | | - >>> # Convert a TransferFunction to a StateSpace object. |
459 | | - >>> sys_tf = tf([2.], [1., 3]) |
460 | | - >>> sys2 = ss(sys_tf) |
461 | | -
|
462 | | - """ |
463 | | - |
464 | | - if len(args) == 4 or len(args) == 5: |
465 | | - return StateSpace(*args) |
466 | | - elif len(args) == 1: |
467 | | - sys = args[0] |
468 | | - if isinstance(sys, StateSpace): |
469 | | - return deepcopy(sys) |
470 | | - elif isinstance(sys, TransferFunction): |
471 | | - return tf2ss(sys) |
472 | | - else: |
473 | | - raise TypeError("ss(sys): sys must be a StateSpace or \ |
474 | | -TransferFunction object. It is %s." % type(sys)) |
475 | | - else: |
476 | | - raise ValueError("Needs 1 or 4 arguments; received %i." % len(args)) |
477 | | - |
478 | 390 |
|
479 | 391 | def tf(*args): |
480 | 392 | """ |
@@ -679,148 +591,6 @@ def ss2tf(*args): |
679 | 591 | else: |
680 | 592 | raise ValueError("Needs 1 or 4 arguments; received %i." % len(args)) |
681 | 593 |
|
682 | | -def tf2ss(*args): |
683 | | - """ |
684 | | - Transform a transfer function to a state space system. |
685 | | -
|
686 | | - The function accepts either 1 or 2 parameters: |
687 | | -
|
688 | | - ``tf2ss(sys)`` |
689 | | - Convert a linear system into transfer function form. Always creates |
690 | | - a new system, even if sys is already a TransferFunction object. |
691 | | -
|
692 | | - ``tf2ss(num, den)`` |
693 | | - Create a transfer function system from its numerator and denominator |
694 | | - polynomial coefficients. |
695 | | -
|
696 | | - For details see: :func:`tf` |
697 | | -
|
698 | | - Parameters |
699 | | - ---------- |
700 | | - sys: LTI (StateSpace or TransferFunction) |
701 | | - A linear system |
702 | | - num: array_like, or list of list of array_like |
703 | | - Polynomial coefficients of the numerator |
704 | | - den: array_like, or list of list of array_like |
705 | | - Polynomial coefficients of the denominator |
706 | | -
|
707 | | - Returns |
708 | | - ------- |
709 | | - out: StateSpace |
710 | | - New linear system in state space form |
711 | | -
|
712 | | - Raises |
713 | | - ------ |
714 | | - ValueError |
715 | | - if `num` and `den` have invalid or unequal dimensions, or if an |
716 | | - invalid number of arguments is passed in |
717 | | - TypeError |
718 | | - if `num` or `den` are of incorrect type, or if sys is not a |
719 | | - TransferFunction object |
720 | | -
|
721 | | - See Also |
722 | | - -------- |
723 | | - ss |
724 | | - tf |
725 | | - ss2tf |
726 | | -
|
727 | | - Examples |
728 | | - -------- |
729 | | - >>> num = [[[1., 2.], [3., 4.]], [[5., 6.], [7., 8.]]] |
730 | | - >>> den = [[[9., 8., 7.], [6., 5., 4.]], [[3., 2., 1.], [-1., -2., -3.]]] |
731 | | - >>> sys1 = tf2ss(num, den) |
732 | | -
|
733 | | - >>> sys_tf = tf(num, den) |
734 | | - >>> sys2 = tf2ss(sys_tf) |
735 | | -
|
736 | | - """ |
737 | | - |
738 | | - if len(args) == 2 or len(args) == 3: |
739 | | - # Assume we were given the num, den |
740 | | - return _convertToStateSpace(TransferFunction(*args)) |
741 | | - |
742 | | - elif len(args) == 1: |
743 | | - sys = args[0] |
744 | | - if not isinstance(sys, TransferFunction): |
745 | | - raise TypeError("tf2ss(sys): sys must be a TransferFunction \ |
746 | | -object.") |
747 | | - return _convertToStateSpace(sys) |
748 | | - else: |
749 | | - raise ValueError("Needs 1 or 2 arguments; received %i." % len(args)) |
750 | | - |
751 | | -def rss(states=1, outputs=1, inputs=1): |
752 | | - """ |
753 | | - Create a stable **continuous** random state space object. |
754 | | -
|
755 | | - Parameters |
756 | | - ---------- |
757 | | - states: integer |
758 | | - Number of state variables |
759 | | - inputs: integer |
760 | | - Number of system inputs |
761 | | - outputs: integer |
762 | | - Number of system outputs |
763 | | -
|
764 | | - Returns |
765 | | - ------- |
766 | | - sys: StateSpace |
767 | | - The randomly created linear system |
768 | | -
|
769 | | - Raises |
770 | | - ------ |
771 | | - ValueError |
772 | | - if any input is not a positive integer |
773 | | -
|
774 | | - See Also |
775 | | - -------- |
776 | | - drss |
777 | | -
|
778 | | - Notes |
779 | | - ----- |
780 | | - If the number of states, inputs, or outputs is not specified, then the |
781 | | - missing numbers are assumed to be 1. The poles of the returned system |
782 | | - will always have a negative real part. |
783 | | -
|
784 | | - """ |
785 | | - |
786 | | - return _rss_generate(states, inputs, outputs, 'c') |
787 | | - |
788 | | -def drss(states=1, outputs=1, inputs=1): |
789 | | - """ |
790 | | - Create a stable **discrete** random state space object. |
791 | | -
|
792 | | - Parameters |
793 | | - ---------- |
794 | | - states: integer |
795 | | - Number of state variables |
796 | | - inputs: integer |
797 | | - Number of system inputs |
798 | | - outputs: integer |
799 | | - Number of system outputs |
800 | | -
|
801 | | - Returns |
802 | | - ------- |
803 | | - sys: StateSpace |
804 | | - The randomly created linear system |
805 | | -
|
806 | | - Raises |
807 | | - ------ |
808 | | - ValueError |
809 | | - if any input is not a positive integer |
810 | | -
|
811 | | - See Also |
812 | | - -------- |
813 | | - rss |
814 | | -
|
815 | | - Notes |
816 | | - ----- |
817 | | - If the number of states, inputs, or outputs is not specified, then the |
818 | | - missing numbers are assumed to be 1. The poles of the returned system |
819 | | - will always have a magnitude less than 1. |
820 | | -
|
821 | | - """ |
822 | | - |
823 | | - return _rss_generate(states, inputs, outputs, 'd') |
824 | 594 |
|
825 | 595 | def pole(sys): |
826 | 596 | """ |
@@ -1449,6 +1219,7 @@ def ssdata(sys): |
1449 | 1219 | (A, B, C, D): list of matrices |
1450 | 1220 | State space data for the system |
1451 | 1221 | ''' |
| 1222 | + from ..statesp import _convertToStateSpace |
1452 | 1223 | ss = _convertToStateSpace(sys) |
1453 | 1224 | return (ss.A, ss.B, ss.C, ss.D) |
1454 | 1225 |
|
|
0 commit comments