lti transient response analysis using Python(numpy, scipy, matplotlib)に次のコードがあります。私はPythonで新しいです。私はプロットしなければならない伝達行列を持っています。ValueError( "分母多項式はランク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.
リンクされたブログのあなたのコメントに対する返答には、リストではなく、numpy.arrayが必要です。あなたは気が散ったチュートリアルを終えましたか? – geoffspear
'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、 (num01、num11)) num0010 = np.array([num00、num10]) num0011 = np.array([num01、num11]) 'ここからはそのリストのみです。変数が配列に変更できないようです。 – Rick2047
私は次のようにしました: 'num = np.array([[[0.0]、[1.0]]、[[ - 2383.3]、[31.9361,0,111320.0]]) den = np.array [0,1]、[1.0]]、[[1.0,160.3460、-1962.0、-314598.852]、[1.0,160.3460、-1962.0、-314598.852]]) tf = lti(num、den) 同じ。 :| – Rick2047