from control.matlab import *
Np = [0, 1] # 伝達関数の分子多項式の係数 (0*s + 1)
Dp = [1, 2, 3] # 伝達関数の分母多項式の係数 (1*s^2 + 2*s + 3)
P = tf(Np, Dp)
print('P(s)=', P)
P = tf([0, 1], [1, 2, 3])
print('P(s)=', P)
P = tf([1, 2], [1, 5, 3, 4])
P
分母多項式の展開
import sympy as sp
sp.init_printing()
s = sp.Symbol('s')
sp.expand( (s+1)*(s+2)**2, s)
P = tf([1, 3],[1, 5, 8, 4])
P
P1 = tf([1, 3], [0, 1])
P2 = tf([0, 1], [1, 1])
P3 = tf([0, 1], [1, 2])
P = P1 * P2 * P3**2
P
print(P.num)
print(P.den)
[[numP]], [[denP]] = tfdata(P)
print(numP)
print(denP)
A = '0 1; -1 -1'
B = '0; 1'
C = '1 0'
D = '0'
P = ss(A, B, C, D)
print(P)
A = [ [0, 1], [-1, -1] ]
B = [ [0], [1] ]
C = [ 1, 0 ]
D = [ 0 ]
P = ss(A, B, C, D)
print(P)
A = '1 1 2; 2 1 1; 3 4 5'
B = '2; 0; 1'
C = '1 1 0'
D = '0'
P = ss(A, B, C, D)
print(P)
print('A=', P.A)
print('B=', P.B)
print('C=', P.C)
print('D=', P.D)
sysA, sysB, sysC, sysD = ssdata(P)
print('A=', sysA)
print('B=', sysB)
print('C=', sysC)
print('D=', sysD)
S1 = tf( [0, 1], [1, 1])
S2 = tf( [1, 1], [1, 1, 1])
print(S1)
print(S2)
S = S2 * S1
print('S=', S)
S = series(S1, S2)
print('S=', S)
分母分子の共通因子 s+1 が約分されない この場合は,minreal を使う
S.minreal()
あるいは,状態空間モデルに変換してから結合する
S1ss = ss(S1) # 状態空間モデルへの変換
S2ss = ss(S2) # 状態空間モデルへの変換
S = S1ss * S2ss
print(tf(S))
S = series(S1ss, S2ss)
print(tf(S))
S = S1 + S2
print('S=', S)
S = parallel(S1, S2)
print('S=', S)
S = S1*S2 / (1 + S1*S2)
print('S=', S)
S = feedback(S1*S2, 1)
print('S=', S)
print('S=', S.minreal())
ポジティブフィードバックの場合
S = feedback(S1*S2, 1, sign = 1)
print(S.minreal())
S1 = tf(1, [1, 1])
S2 = tf(1, [1, 2])
S3 = tf([3, 1], [1, 0])
S4 = tf([2, 0], [0, 1])
print('S1=', S1)
print('S2=', S2)
print('S3=', S3)
print('S4=', S4)
S12 = feedback(S1, S2)
S123 = series(S12, S3)
S = feedback(S123, S4)
print('S=', S)
P = tf( [0, 1], [1, 1, 1])
Pss = tf2ss(P) # 伝達関数モデルから状態空間モデルへの変換
print(Pss)
Ptf = ss2tf(Pss) # 状態空間モデルから伝達関数モデルへの変換
print(Ptf)
from control import canonical_form
A = '1 2 3; 3 2 1; 4 5 0'
B = '1; 0; 1'
C = '0 2 1'
D = '0'
Pss = ss(A, B, C, D)
Pr, T = canonical_form(Pss, form='reachable')
print(Pss)
print('------------')
print(Pr)
### 可観測正準形
Po, T = canonical_form(Pss, form='observable')
print(Po)
S1 = tf([1, 1], [0, 1])
S2 = tf([0, 1], [1, 1])
S = series(S1, S2)
print(S.minreal())
print(S2)
tf2ss(S2)
print(S1)
tf2ss(S1)
import sympy as sp
s = sp.Symbol('s')
t = sp.Symbol('t', positive=True)
sp.init_printing()
sp.laplace_transform(1, t, s)
sp.laplace_transform(t, t, s)
a = sp.Symbol('a', real=True)
sp.laplace_transform(sp.exp(-a*t), t, s)
w = sp.Symbol('w', real=True)
sp.laplace_transform(sp.sin(w*t), t, s)
sp.laplace_transform(sp.cos(w*t), t, s)
sp.laplace_transform(sp.exp(-a*t)*sp.sin(w*t), t, s)
sp.laplace_transform(sp.exp(-a*t)*sp.cos(w*t), t, s)
sp.inverse_laplace_transform(1/s, s, t)
sp.inverse_laplace_transform(1/s**2, s, t)
sp.inverse_laplace_transform(1/(s+a), s, t)
sp.inverse_laplace_transform(w/(s**2+w**2), s, t)
sp.inverse_laplace_transform(s/(s**2+w**2), s, t)
sp.inverse_laplace_transform(w/((s+a)**2+w**2), s, t)
sp.inverse_laplace_transform((s+a)/((s+a)**2+w**2), s, t)