Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
e = ValueError("The N-th order system of linear algebraic \
equations is singular to working precision.")
e.info = ve.info
raise e
# Calculate the gain matrix G
if size(R_b) == 1:
G = dot(1/(dot(asarray(B_ba).T, dot(X, B_ba)) + R_ba), \
dot(asarray(B_ba).T, dot(X, A_ba)))
else:
G = solve(dot(asarray(B_ba).T, dot(X, B_ba)) + R_ba, \
dot(asarray(B_ba).T, dot(X, A_ba)))
# Return the solution X, the closed-loop eigenvalues L and
# the gain matrix G
return (_ssmatrix(X) , w[:n], _ssmatrix(G))
# Solve the generalized algebraic Riccati equation
elif S is not None and E is not None:
# Check input data for consistency
if size(A) > 1 and shape(A)[0] != shape(A)[1]:
raise ControlArgument("A must be a quadratic matrix.")
if (size(Q) > 1 and shape(Q)[0] != shape(Q)[1]) or \
(size(Q) > 1 and shape(Q)[0] != n) or \
size(Q) == 1 and n > 1:
raise ControlArgument("Q must be a quadratic matrix of the same \
dimension as A.")
if (size(B) > 1 and shape(B)[0] != n) or \
size(B) == 1 and n > 1:
raise ControlArgument("Incompatible dimensions of B matrix.")
i.e., the eigenvalues of A - B G.
(X,L,G) = dare(A,B,Q,R,S,E) solves the generalized discrete-time algebraic
Riccati equation
:math:`A^T X A - E^T X E - (A^T X B + S) (B^T X B + R)^{-1} (B^T X A + S^T) + Q = 0`
where A, Q and E are square matrices of the same dimension. Further, Q and
R are symmetric matrices. The function returns the solution X, the gain
matrix :math:`G = (B^T X B + R)^{-1} (B^T X A + S^T)` and the closed loop
eigenvalues L, i.e., the eigenvalues of A - B G , E.
"""
if S is not None or E is not None or not stabilizing:
return dare_old(A, B, Q, R, S, E, stabilizing)
else:
Rmat = _ssmatrix(R)
Qmat = _ssmatrix(Q)
X = solve_discrete_are(A, B, Qmat, Rmat)
G = solve(B.T.dot(X).dot(B) + Rmat, B.T.dot(X).dot(A))
L = eigvals(A - B.dot(G))
return _ssmatrix(X), L, _ssmatrix(G)
:math:`A^T X A - E^T X E - (A^T X B + S) (B^T X B + R)^{-1} (B^T X A + S^T) + Q = 0`
where A, Q and E are square matrices of the same dimension. Further, Q and
R are symmetric matrices. The function returns the solution X, the gain
matrix :math:`G = (B^T X B + R)^{-1} (B^T X A + S^T)` and the closed loop
eigenvalues L, i.e., the eigenvalues of A - B G , E.
"""
if S is not None or E is not None or not stabilizing:
return dare_old(A, B, Q, R, S, E, stabilizing)
else:
Rmat = _ssmatrix(R)
Qmat = _ssmatrix(Q)
X = solve_discrete_are(A, B, Qmat, Rmat)
G = solve(B.T.dot(X).dot(B) + Rmat, B.T.dot(X).dot(A))
L = eigvals(A - B.dot(G))
return _ssmatrix(X), L, _ssmatrix(G)
Examples
--------
>>> O = obsv(A, C)
"""
# Convert input parameters to matrices (if they aren't already)
amat = _ssmatrix(A)
cmat = _ssmatrix(C)
n = np.shape(amat)[0]
# Construct the observability matrix
obsv = np.vstack([cmat] + [np.dot(cmat, np.linalg.matrix_power(amat, i))
for i in range(1, n)])
return _ssmatrix(obsv)
Examples
--------
>>> C = ctrb(A, B)
"""
# Convert input parameters to matrices (if they aren't already)
amat = _ssmatrix(A)
bmat = _ssmatrix(B)
n = np.shape(amat)[0]
# Construct the controllability matrix
ctrb = np.hstack([bmat] + [np.dot(np.linalg.matrix_power(amat, i), bmat)
for i in range(1, n)])
return _ssmatrix(ctrb)
A, C: array_like or string
Dynamics and output matrix of the system
Returns
-------
O: matrix
Observability matrix
Examples
--------
>>> O = obsv(A, C)
"""
# Convert input parameters to matrices (if they aren't already)
amat = _ssmatrix(A)
cmat = _ssmatrix(C)
n = np.shape(amat)[0]
# Construct the observability matrix
obsv = np.vstack([cmat] + [np.dot(cmat, np.linalg.matrix_power(amat, i))
for i in range(1, n)])
return _ssmatrix(obsv)
# Calculate the closed-loop eigenvalues L
L = zeros((n,1))
L.dtype = 'complex64'
for i in range(n):
L[i] = (alfar[i] + alfai[i]*1j)/beta[i]
# Calculate the gain matrix G
if size(R_b) == 1:
G = dot(1/(R_b), dot(asarray(B_b).T, dot(X,E_b)) + asarray(S_b).T)
else:
G = solve(R_b, dot(asarray(B_b).T, dot(X, E_b)) + asarray(S_b).T)
# Return the solution X, the closed-loop eigenvalues L and
# the gain matrix G
return (_ssmatrix(X), L, _ssmatrix(G))
# Invalid set of input parameters
else:
raise ControlArgument("Invalid set of input parameters.")
# Convert the system inputs to NumPy arrays
A_mat = np.array(A)
B_mat = np.array(B)
if (A_mat.shape[0] != A_mat.shape[1]):
raise ControlDimension("A must be a square matrix")
if (A_mat.shape[0] != B_mat.shape[0]):
err_str = "The number of rows of A must equal the number of rows in B"
raise ControlDimension(err_str)
# Convert desired poles to numpy array
placed_eigs = np.array(p)
result = place_poles(A_mat, B_mat, placed_eigs, method='YT')
K = result.gain_matrix
return _ssmatrix(K)