2012-02-21 99 views
0

我在lti transient response analysis using Python(numpy, scipy, matplotlib)中獲得了以下代碼。我是python中的新成員。我有一個轉移矩陣,我必須繪製。ValueError(「分母多項式必須是rank-1數組。」)

我碰到了mathwork: tf。我想如下:

from numpy import min, max 
from scipy import linspace 
from scipy.signal import lti, step, impulse 

num00 = [0.0] 
den00 = [0.0] 

num01 = [-2383.3] 
den01 = [1.0,160.3460,-1962.0,-314598.852] 

num10 = [1.0] 
den10 = [1.0] 

num11 = [31.9361,0,111320.0] 
den11 = [1.0,160.3460,-1962.0,-314598.852] 

num = [[num00,num01],[num10,num11]] 
den = [[den00,den01],[den10,den11]] 

tf = lti(num,den) 

t = 0  
s = 0 

# get t = time, s = unit-step response 
t , s = step(tf) 

t , s = step(tf, T = linspace(min(t), t[-1], 1000)) 

t , i = impulse(tf, T = linspace(min(t), t[-1], 1000)) 

from matplotlib import pyplot as plt 

plt.plot(t, s, t, i) 

plt.title('Transient-Response Analysis') 
plt.xlabel('Time(sec)') 
plt.ylabel('Amplitude') 
plt.hlines(1, min(t), max(t), colors='r') 
plt.hlines(0, min(t), max(t)) 
plt.xlim(xmax=max(t)) 
plt.legend(('Unit-Step Response', 'Unit-Impulse Response'), loc=0) 
plt.grid() 
plt.show() 

我收到以下錯誤:問題的

>>> tf = lti(num,den) 
Traceback (most recent call last): 
    File "<stdin>", line 1, in <module> 
    File "C:\Python26\lib\site-packages\scipy\signal\ltisys.py", line 236, in __init__self.__dict__['num'], self.__dict__['den'] = normalize(*args) 
    File "C:\Python26\lib\site-packages\scipy\signal\filter_design.py", line 276, in normalize raise ValueError("Denominator polynomial must be rank-1 array.") ValueError: Denominator polynomial must be rank-1 array. 
+0

正如您對鏈接博客評論的回覆所述,您需要一個'numpy.array',而不是一個列表。你有沒有經歷numpy教程? – geoffspear 2012-02-21 11:21:06

+0

'num00 = np.array(0.0) den00 = np.array(0.0) num01 = np.array(-2383.3) den01 = np.array([1.0,160.3460,-1962.0,-314598.852]) num10 = np.array([1.0]) den10 = np.array([1.0]) num11 = np.array([31.9361,0,111320.0]) den11 = np.array([1.0,160.3460, -1962.0,-314598.852]) num0010 = np.array([num00,num10]) num0011 = np.array([num01,num11])'從這裏只有它的列表。似乎變量不能更改爲數組。 – Rick2047 2012-02-21 13:33:04

+0

現在我做了如下:'num = np.array([[[0.0],[1.0]],[[ - 2383.3],[31.9361,0,111320.0]]]) den = np.array([ [0.0],[1.0]],[[1.0,160.3460,-1962.0,-314598.852],[1.0,160.3460,-1962.0,-314598.852]])) tf = lti(num,den) '仍然是它的相同。 :| – Rick2047 2012-02-21 14:24:20

回答

0

部分是要傳遞的num/den的是不是一個能夠形成矩陣。在你的代碼有:

num01 = [-2383.3] 
den01 = [1.0,160.3460,-1962.0,-314598.852] 

因爲據numpy的來講,你想創建一個矩陣,我知道這只是一個傳遞函數矩陣的組成部分,只有1這將不能很好地工作分子中的元素和分母中的四個元素。所以你需要這樣的東西:

num01 = [ 0,  0,  0,-2383.3] 

無論是你或你的意思是有一個非常高的分子。當我嘗試一步,我得到: Step 這可能不是你所期望的。我也建議看看python-control包。當然,你需要獲得這個包的所有prerequists,比如SLICOT python package。我相信它最終會爲你服務。

+0

我試過,因爲你提到過。相同。我正在嘗試從ss(a,b,c,d)。現在米堅持ImportError:沒有名爲slycot的模塊。我的系統是MIMO。 – Rick2047 2012-02-23 14:27:22

+0

@ Rahul2047看我的編輯。 – macduff 2012-02-23 14:49:48

相關問題