import numpy as np
import control as ct
from numpy.linalg import eig
from numpy import linalg as LA
A = np.asarray([
[0, 1, 0],
[0, 0, 1],
[-6, -11, -6]
])
B = np.asarray([
[0],
[0],
[6]
])
C = np.asarray([1, 0, 0])
D = np.asarray([0])
sys = ct.ss(A, B, C, D)
sys
ct.ss2tf(sys)
eigenvalues, eigenvectors = LA.eig(A)
inv_eigen = LA.inv(eigenvectors)
Am = (inv_eigen @ A) @ eigenvectors
Bm = inv_eigen @ B
Cm = C @ eigenvectors
sys2 = ct.ss(Am, Bm, Cm, D)
sys2
ct.ss2tf(sys2)
eigenvectors
array([[-0.57735027, 0.21821789, -0.10482848], [ 0.57735027, -0.43643578, 0.31448545], [-0.57735027, 0.87287156, -0.94345635]])
!pip install sympy
Requirement already satisfied: sympy in /usr/local/lib/python3.9/dist-packages (1.12) Requirement already satisfied: mpmath>=0.19 in /usr/local/lib/python3.9/dist-packages (from sympy) (1.3.0) WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
import sympy
sympy.init_printing()
s = sympy.Symbol('s') # A single symbol
A = np.asarray([
[0, 1],
[-2, -3]])
identity_matrix = np.identity(2)
laplce_target = sympy.Matrix(s * identity_matrix -A)
laplce_target_inv = laplce_target.inv()
laplce_target_inv
type(laplce_target_inv)
sympy.matrices.dense.MutableDenseMatrix
t, s = sympy.symbols('t, s')
a, b, c, d = sympy.symbols('a b c d')
partial = sympy.matrices.dense.MutableDenseMatrix(2,2, [a, b, c, d])
values = {a: laplce_target_inv[0].apart(s),
b: laplce_target_inv[1].apart(s),
c: laplce_target_inv[2].apart(s),
d: laplce_target_inv[3].apart(s)
}
partial = partial.subs(values)
partial
type(partial)
sympy.matrices.dense.MutableDenseMatrix
a, b, c, d = sympy.symbols('a b c d')
complete = sympy.matrices.dense.MutableDenseMatrix(2,2, [a, b, c, d])
values = {a: sympy.inverse_laplace_transform(partial[0], s, t),
b: sympy.inverse_laplace_transform(partial[1], s, t),
c: sympy.inverse_laplace_transform(partial[2], s, t),
d: sympy.inverse_laplace_transform(partial[3], s, t)
}
complete = complete.subs(values)
complete
3.3. What is that θ?
The unit step function is also known as the Heaviside step function. We will see this function often in inverse laplace transforms. It is typeset as by sympy.
sympy.Heaviside(t)
#예제
a = sympy.symbols('a', real=True, positive=True)
t, s = sympy.symbols('t, s')
f = sympy.exp(-a*t)
sympy.laplace_transform(f, t, s)
A
eigenvalues, eigenvectors = LA.eig(A)
inv_eigen = LA.inv(eigenvectors)
t, s = sympy.symbols('t, s')
print(eigenvalues)
print(eigenvectors)
diagonal_matrix = inv_eigen @ A @ eigenvectors
lamda_matrix = sympy.diag(sympy.exp(eigenvalues[0]*t),sympy.exp(eigenvalues[1]*t) )
# P^-1 @ A P가 아니라 P @ A @ P^-1인 형식
complete2 = eigenvectors @ lamda_matrix @ inv_eigen
[-1. -2.] [[ 0.70710678 -0.4472136 ] [-0.70710678 0.89442719]]
lamda_matrix
complete2
A = np.asarray([
[0, 1],
[-2, -3]
])
B = np.asarray([
[0],
[1]
])
s = sympy.symbols('s', real=True, positive=True)
identity_matrix = np.identity(2)
Pi_matrix = sympy.Matrix(s * identity_matrix - A)
Pi_matrix = Pi_matrix.inv()
initial_tmp = Pi_matrix
response_tmp = Pi_matrix @ B
a, b, c, d = sympy.symbols('a b c d')
initial = sympy.matrices.dense.MutableDenseMatrix(2,2, [a, b, c, d])
values = {a: Pi_matrix[0].apart(s),
b: Pi_matrix[1].apart(s),
c: Pi_matrix[2].apart(s),
d: Pi_matrix[3].apart(s)
}
initial = initial.subs(values)
response = sympy.matrices.dense.MutableDenseMatrix(2,1, [a, b])
values = {a: response_tmp[0].apart(s),
b: response_tmp[1].apart(s),
}
response = response.subs(values)
initial
response
a, b, c, d = sympy.symbols('a b c d')
#t, s = sympy.symbols('t, s')
initial_time = sympy.matrices.dense.MutableDenseMatrix(2,2, [a, b, c, d])
values = {
a: sympy.inverse_laplace_transform(initial[0], s, t),
b: sympy.inverse_laplace_transform(initial[1], s, t),
c: sympy.inverse_laplace_transform(initial[2], s, t),
d: sympy.inverse_laplace_transform(initial[3], s, t)
}
initial_time = initial_time.subs(values)
response_time = sympy.matrices.dense.MutableDenseMatrix(2,1, [a, b])
values = {
a: sympy.inverse_laplace_transform(response[0], s, t),
b: sympy.inverse_laplace_transform(response[1], s, t)
}
response_time = response_time.subs(values)
initial_time
response_time
response_time에서 t를 t-tau 로 변경하고, 적분