|
From: <kk...@us...> - 2011-02-08 22:17:09
|
Revision: 89
http://python-control.svn.sourceforge.net/python-control/?rev=89&view=rev
Author: kkchen
Date: 2011-02-08 22:17:03 +0000 (Tue, 08 Feb 2011)
Log Message:
-----------
Bug fixes in convertToStateSpace; new TestConvert.py
Kevin K. Chen <kk...@pr...>
Modified Paths:
--------------
branches/control-0.4a/src/TestStateSp.py
branches/control-0.4a/src/statesp.py
Added Paths:
-----------
branches/control-0.4a/src/TestConvert.py
Added: branches/control-0.4a/src/TestConvert.py
===================================================================
--- branches/control-0.4a/src/TestConvert.py (rev 0)
+++ branches/control-0.4a/src/TestConvert.py 2011-02-08 22:17:03 UTC (rev 89)
@@ -0,0 +1,36 @@
+#!/usr/bin/env python
+
+import numpy as np
+import matlab
+import unittest
+
+class TestConvert(unittest.TestCase):
+ """Test state space and transfer function conversions."""
+
+ def setUp(self):
+ """Set up testing parameters."""
+
+ # Number of times to run each of the randomized tests.
+ self.numTests = 10
+ # Maximum number of states to test + 1
+ self.maxStates = 5
+ # Maximum number of inputs and outputs to test + 1
+ self.maxIO = 5
+
+ def testConvert(self):
+ """Test state space to transfer function conversion."""
+
+ for states in range(1, self.maxStates):
+ for inputs in range(1, self.maxIO):
+ for outputs in range(1, self.maxIO):
+ sys = matlab.rss(states, inputs, outputs)
+ print "sys1:\n", sys
+ sys2 = matlab.tf(sys)
+ print "sys2:\n", sys2
+ sys3 = matlab.ss(sys2)
+ print "sys3:\n", sys3
+ sys4 = matlab.tf(sys3)
+ print "sys4:\n", sys4
+
+if __name__ == "__main__":
+ unittest.main()
Property changes on: branches/control-0.4a/src/TestConvert.py
___________________________________________________________________
Added: svn:executable
+ *
Modified: branches/control-0.4a/src/TestStateSp.py
===================================================================
--- branches/control-0.4a/src/TestStateSp.py 2011-02-08 22:16:57 UTC (rev 88)
+++ branches/control-0.4a/src/TestStateSp.py 2011-02-08 22:17:03 UTC (rev 89)
@@ -1,9 +1,9 @@
#!/usr/bin/env python
import numpy as np
+import unittest
import matlab
from statesp import StateSpace
-import unittest
class TestStateSpace(unittest.TestCase):
"""Tests for the StateSpace class."""
Modified: branches/control-0.4a/src/statesp.py
===================================================================
--- branches/control-0.4a/src/statesp.py 2011-02-08 22:16:57 UTC (rev 88)
+++ branches/control-0.4a/src/statesp.py 2011-02-08 22:17:03 UTC (rev 89)
@@ -433,13 +433,18 @@
# function matrix has a common denominator.
num, den = sys._common_den()
# Make a list of the orders of the denominator polynomials.
- index = [len(den) for i in range(sys.outputs)]
+ index = [len(den) - 1 for i in range(sys.outputs)]
# Repeat the common denominator along the rows.
den = array([den for i in range(sys.outputs)])
+ print "outputs = %g\n" % sys.outputs
ssout = td04ad(sys.inputs, sys.outputs, index, den, num)
- return StateSpace(ssout[1], ssout[2], ssout[3], ssout[4])
+ states = ssout[0]
+ return StateSpace(ssout[1][:states, :states],
+ ssout[2][:states, :sys.inputs],
+ ssout[3][:sys.outputs, :states],
+ ssout[4])
elif isinstance(sys, (int, long, float, complex)):
if "inputs" in kw:
inputs = kw["inputs"]
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|