From: <gor...@us...> - 2011-04-16 23:45:52
|
Revision: 155 http://python-control.svn.sourceforge.net/python-control/?rev=155&view=rev Author: goretkin Date: 2011-04-16 23:45:46 +0000 (Sat, 16 Apr 2011) Log Message: ----------- Support for the **,/ operator. >> s = control.tf.TransferFunction([1, 0],[1]) sys = s/(s**2+s+1) #works as expected Modified Paths: -------------- trunk/setup.py trunk/src/xferfcn.py Modified: trunk/setup.py =================================================================== --- trunk/setup.py 2011-04-07 20:12:28 UTC (rev 154) +++ trunk/setup.py 2011-04-16 23:45:46 UTC (rev 155) @@ -1,6 +1,7 @@ #!/usr/bin/env python -from distutils.core import setup +#from distutils.core import setup +from setuptools import setup setup(name = 'control', version = '0.4c', Modified: trunk/src/xferfcn.py =================================================================== --- trunk/src/xferfcn.py 2011-04-07 20:12:28 UTC (rev 154) +++ trunk/src/xferfcn.py 2011-04-16 23:45:46 UTC (rev 155) @@ -372,9 +372,13 @@ def __div__(self, other): """Divide two LTI objects.""" - # Convert the second argument to a transfer function. - other = _convertToTransferFunction(other) + if isinstance(other, (int, float, long, complex)): + other = _convertToTransferFunction(other, inputs=self.inputs, + outputs=self.inputs) + else: + other = _convertToTransferFunction(other) + if (self.inputs > 1 or self.outputs > 1 or other.inputs > 1 or other.outputs > 1): raise NotImplementedError("TransferFunction.__div__ is currently \ @@ -388,6 +392,11 @@ # TODO: Division of MIMO transfer function objects is not written yet. def __rdiv__(self, other): """Right divide two LTI objects.""" + if isinstance(other, (int, float, long, complex)): + other = _convertToTransferFunction(other, inputs=self.inputs, + outputs=self.inputs) + else: + other = _convertToTransferFunction(other) if (self.inputs > 1 or self.outputs > 1 or other.inputs > 1 or other.outputs > 1): @@ -395,6 +404,16 @@ implemented only for SISO systems.") return other / self + def __pow__(self,other): + if not type(other) == int: + raise ValueError("Exponent must be an integer") + if other == 0: + return TransferFunction([1],[1]) #unity + if other > 0: + return self * (self**(other-1)) + if other < 0: + return (TransferFunction([1],[1]) / self) * (self**(other+1)) + def evalfr(self, omega): """Evaluate a transfer function at a single angular frequency. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |