From: <kk...@us...> - 2011-02-08 22:14:19
|
Revision: 55 http://python-control.svn.sourceforge.net/python-control/?rev=55&view=rev Author: kkchen Date: 2011-02-08 22:14:13 +0000 (Tue, 08 Feb 2011) Log Message: ----------- Added xTransferFunction.__str__ in xferfcn.py. Appears to work well. Kevin K. Chen <kk...@pr...> Modified Paths: -------------- branches/control-0.4a/src/xferfcn.py Modified: branches/control-0.4a/src/xferfcn.py =================================================================== --- branches/control-0.4a/src/xferfcn.py 2011-02-08 22:14:08 UTC (rev 54) +++ branches/control-0.4a/src/xferfcn.py 2011-02-08 22:14:13 UTC (rev 55) @@ -111,14 +111,43 @@ self.den = den Lti2.__init__(self, inputs, outputs) - self.truncatecoeff() + self._truncatecoeff() def __str__(self): """String representation of the transfer function.""" + + mimo = self.inputs > 1 or self.outputs > 1 + outstr = "" + + for i in range(self.inputs): + for j in range(self.outputs): + if mimo: + outstr += "\nInput %i to output %i:" % (i + 1, j + 1) + + lablen = 0 + + # Convert the numerator and denominator polynomials to strings. + numstr = _tfpolyToString(self.num[j][i]); + denstr = _tfpolyToString(self.den[j][i]); + + # Figure out the length of the separating line + dashcount = max(len(numstr), len(denstr)) + dashes = '-' * dashcount + + # Center the numerator or denominator + if (len(numstr) < dashcount): + numstr = ' ' * \ + int(round((dashcount - len(numstr))/2) + lablen) + \ + numstr + if (len(denstr) < dashcount): + denstr = ' ' * \ + int(round((dashcount - len(denstr))/2) + lablen) + \ + denstr + + outstr += "\n" + numstr + "\n" + dashes + "\n" + denstr + "\n" + return outstr - pass - - def truncatecoeff(self): + def _truncatecoeff(self): """Remove extraneous zero coefficients from polynomials in numerator and denominator matrices.""" This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |