From: Richard M. <mu...@cd...> - 2013-08-30 20:58:04
|
Thanks, Ryan. I'll look through this and try to put the patch into the repository soon (hopefully this weekend). -richard On 28 Aug 2013, at 9:33 , Ryan Krauss <rk...@si...> wrote: > I left the original code intact for cases when s is a 1D array, but that isn't really necessary. My second patch eliminates this unnecessary case in the if statement: > > def horner(self, s): > """Evaluate the systems's transfer function for a complex variable > > Returns a matrix of values evaluated at complex variable s. > """ > > # Preallocate the output. > if getattr(s, '__iter__', False): > dim = [self.outputs, self.inputs] > dim.extend(shape(s)) > out = empty(dim, dtype=complex) > else: > out = empty((self.outputs, self.inputs), dtype=complex) > > for i in range(self.outputs): > for j in range(self.inputs): > out[i][j] = (polyval(self.num[i][j], s) / > polyval(self.den[i][j], s)) > > return out > > A second patch is attached. > > > -- > Ryan Krauss, Ph.D. > Associate Professor > Mechanical Engineering > Southern Illinois University Edwardsville > > > On Wed, Aug 28, 2013 at 11:28 AM, Ryan Krauss <rk...@si...> wrote: > This might be slightly hackish, but I think it solves the problem. The core issue is the size of the out matrix created at the beginning of the horner method. out needs to be 4D is s is a 2D array. I think this works for any dimension of s. > > def horner(self, s): > """Evaluate the systems's transfer function for a complex variable > > Returns a matrix of values evaluated at complex variable s. > """ > > # Preallocate the output. > if getattr(s, '__iter__', False): > if len(shape(s)) == 1: > out = empty((self.outputs, self.inputs, len(s)), dtype=complex) > else: > dim = [self.outputs, self.inputs] > dim.extend(shape(s)) > out = empty(dim, dtype=complex) > else: > out = empty((self.outputs, self.inputs), dtype=complex) > > for i in range(self.outputs): > for j in range(self.inputs): > out[i][j] = (polyval(self.num[i][j], s) / > polyval(self.den[i][j], s)) > > return out > > I am attaching a patch of my hack. > > > > -- > Ryan Krauss, Ph.D. > Associate Professor > Mechanical Engineering > Southern Illinois University Edwardsville > > > On Wed, Aug 28, 2013 at 11:06 AM, Ryan Krauss <rk...@si...> wrote: > I need to calculate 3D bode plots (contour plots) for my work. I am getting this error: > > /usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/control-0.6d-py2.7.egg/control/xferfcn.pyc in __call__(self, s) > 245 else: > 246 # SISO transfer function, return a scalar > --> 247 return self.horner(s)[0][0] > 248 > 249 def _truncatecoeff(self): > > /usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/control-0.6d-py2.7.egg/control/xferfcn.pyc in horner(self, s) > 560 for j in range(self.inputs): > 561 out[i][j] = (polyval(self.num[i][j], s) / > --> 562 polyval(self.den[i][j], s)) > 563 > 564 return out > > ValueError: could not broadcast input array from shape (2,2) into shape (2) > > > Here is code that recreates the problem: > > import control > test = control.TransferFunction(1,[1,1]) > s_mat = array([[2j*pi, 3j*pi],[-0.1+2j*pi, -0.1+3j*pi]]) > > > > -- > Ryan Krauss, Ph.D. > Associate Professor > Mechanical Engineering > Southern Illinois University Edwardsville > > > <krauss_horner_patch_2.diff>------------------------------------------------------------------------------ > Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more! > Discover the easy way to master current and previous Microsoft technologies > and advance your career. Get an incredible 1,500+ hours of step-by-step > tutorial videos with LearnDevNow. Subscribe today and save! > http://pubads.g.doubleclick.net/gampad/clk?id=58040911&iu=/4140/ostg.clktrk_______________________________________________ > python-control-discuss mailing list > pyt...@li... > https://lists.sourceforge.net/lists/listinfo/python-control-discuss |