From: Richard M. <mu...@cd...> - 2013-06-07 02:37:11
|
Good call on __call__. This seems like a fine thing to integrate in. -richard On 6 Jun 2013, at 12:36 , Ryan Krauss <rk...@si...> wrote: > poly1d makes it naturally vectorize so that the __call__ method could also be used in Bode-type calculations: > > In [16]: w = arange(1,5,0.5) > > In [17]: control.freqresp(test,w) > Out[17]: > (array([[[ 0.31622777, 0.2981424 , 0.2773501 , 0.25607376, 0.23570226, > 0.21693046, 0.2 , 0.18490007]]]), > array([[[-0.32175055, -0.46364761, -0.5880026 , -0.69473828, -0.78539816, > -0.86217005, -0.92729522, -0.98279372]]]), > array([ 1. , 1.5, 2. , 2.5, 3. , 3.5, 4. , 4.5])) > > In [18]: s_vect = 1.0j*w > > In [18.5]: test(s_vect) > Out[18.5]: > array([ 0.30000000-0.1j , 0.26666667-0.13333333j, > 0.23076923-0.15384615j, 0.19672131-0.16393443j, > 0.16666667-0.16666667j, 0.14117647-0.16470588j, > 0.12000000-0.16j , 0.10256410-0.15384615j]) > > > In [19]: freq_test = test(s_vect) > > In [20]: abs(freq_test) > Out[20]: > array([ 0.31622777, 0.2981424 , 0.2773501 , 0.25607376, 0.23570226, > 0.21693046, 0.2 , 0.18490007]) > > In [21]: angle(freq_test) > Out[21]: > array([-0.32175055, -0.46364761, -0.5880026 , -0.69473828, -0.78539816, > -0.86217005, -0.92729522, -0.98279372]) > > > > -- > Ryan Krauss, Ph.D. > Associate Professor > Mechanical Engineering > Southern Illinois University Edwardsville > > > On Thu, Jun 6, 2013 at 2:31 PM, Ryan Krauss <rk...@si...> wrote: > FYI, I made this change in my local checkout code and ran a simple test and it is working: > > In [8]: test = control.TransferFunction(1,[1,3]) > > In [9]: s1 = -1+2.0j > > In [10]: test(s1) > Out[10]: (0.25-0.25j) > > In [11]: 1.0/(s1+3) > Out[11]: (0.25-0.25j) > > Nothing too fancy, but solves my issue. > > > -- > Ryan Krauss, Ph.D. > Associate Professor > Mechanical Engineering > Southern Illinois University Edwardsville > > > On Thu, Jun 6, 2013 at 1:47 PM, Ryan Krauss <rk...@si...> wrote: > I would like to submit some minor patches over the course of the summer to help me completely get rid of my old controls module and switch over to python-control for everything. My most immediate need is for a __call__ method. This method might not make any sense for a state-space system, but for certain aspects of my modeling work, I need to evaluate transfer functions at certain numerical values of s. > > I would propose something like this: > > def __call__(self, s): > """Evaluate a transfer function at s.""" > N_poly = poly1d(squeeze(self.num)) > D_poly = poly1d(squeeze(self.den)) > return N_poly(s)/D_poly(s) > > > It could also include a check that self is SISO and possibly throw an exception if it is not (pretty sure that poly1d will throw one if we pass in a vector of coefficients that isn't 1d). > > Would this be welcome? Is there anything I should tweak? > > Thanks, > > Ryan > > -- > Ryan Krauss, Ph.D. > Associate Professor > Mechanical Engineering > Southern Illinois University Edwardsville > > > ------------------------------------------------------------------------------ > How ServiceNow helps IT people transform IT departments: > 1. A cloud service to automate IT design, transition and operations > 2. Dashboards that offer high-level views of enterprise services > 3. A single system of record for all IT processes > http://p.sf.net/sfu/servicenow-d2d-j_______________________________________________ > python-control-discuss mailing list > pyt...@li... > https://lists.sourceforge.net/lists/listinfo/python-control-discuss |