Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Check for symmetric matrices with machine precision#348

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
murrayrm merged 4 commits intopython-control:masterfrombnavigator:symmetric-eps
Dec 30, 2019
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 23 additions & 13 deletionscontrol/mateqn.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -41,7 +41,8 @@
Author: Bjorn Olofsson
"""

from numpy import shape, size, array, asarray, copy, zeros, eye, dot
from numpy import shape, size, asarray, copy, zeros, eye, dot, \
finfo, inexact, atleast_2d
from scipy.linalg import eigvals, solve_discrete_are, solve
from .exception import ControlSlycot, ControlArgument
from .statesp import _ssmatrix
Expand DownExpand Up@@ -122,7 +123,7 @@ def lyap(A, Q, C=None, E=None):
if size(Q) > 1 and shape(Q)[0] != shape(Q)[1]:
raise ControlArgument("Q must be a quadratic matrix.")

if not(asarray(Q) == asarray(Q).T).all():
if not_is_symmetric(Q):
raise ControlArgument("Q must be a symmetric matrix.")

# Solve the Lyapunov equation by calling Slycot function sb03md
Expand DownExpand Up@@ -188,7 +189,7 @@ def lyap(A, Q, C=None, E=None):
raise ControlArgument("E must be a square matrix with the same \
dimension as A.")

if not(asarray(Q) == asarray(Q).T).all():
if not_is_symmetric(Q):
raise ControlArgument("Q must be a symmetric matrix.")

# Make sure we have access to the write slicot routine
Expand DownExpand Up@@ -309,7 +310,7 @@ def dlyap(A,Q,C=None,E=None):
if size(Q) > 1 and shape(Q)[0] != shape(Q)[1]:
raise ControlArgument("Q must be a quadratic matrix.")

if not(asarray(Q) == asarray(Q).T).all():
if not_is_symmetric(Q):
raise ControlArgument("Q must be a symmetric matrix.")

# Solve the Lyapunov equation by calling the Slycot function sb03md
Expand DownExpand Up@@ -371,7 +372,7 @@ def dlyap(A,Q,C=None,E=None):
raise ControlArgument("E must be a square matrix with the same \
dimension as A.")

if not(asarray(Q) == asarray(Q).T).all():
if not_is_symmetric(Q):
raise ControlArgument("Q must be a symmetric matrix.")

# Solve the generalized Lyapunov equation by calling Slycot
Expand DownExpand Up@@ -500,10 +501,10 @@ def care(A, B, Q, R=None, S=None, E=None, stabilizing=True):
size(B) == 1 and n > 1:
raise ControlArgument("Incompatible dimensions of B matrix.")

if not(asarray(Q) == asarray(Q).T).all():
if not_is_symmetric(Q):
raise ControlArgument("Q must be a symmetric matrix.")

if not(asarray(R) == asarray(R).T).all():
if not_is_symmetric(R):
raise ControlArgument("R must be a symmetric matrix.")

# Create back-up of arrays needed for later computations
Expand DownExpand Up@@ -603,10 +604,10 @@ def care(A, B, Q, R=None, S=None, E=None, stabilizing=True):
size(S) == 1 and m > 1:
raise ControlArgument("Incompatible dimensions of S matrix.")

if not(asarray(Q) == asarray(Q).T).all():
if not_is_symmetric(Q):
raise ControlArgument("Q must be a symmetric matrix.")

if not(asarray(R) == asarray(R).T).all():
if not_is_symmetric(R):
raise ControlArgument("R must be a symmetric matrix.")

# Create back-up of arrays needed for later computations
Expand DownExpand Up@@ -775,10 +776,10 @@ def dare_old(A, B, Q, R, S=None, E=None, stabilizing=True):
size(B) == 1 and n > 1:
raise ControlArgument("Incompatible dimensions of B matrix.")

if not(asarray(Q) == asarray(Q).T).all():
if not_is_symmetric(Q):
raise ControlArgument("Q must be a symmetric matrix.")

if not(asarray(R) == asarray(R).T).all():
if not_is_symmetric(R):
raise ControlArgument("R must be a symmetric matrix.")

# Create back-up of arrays needed for later computations
Expand DownExpand Up@@ -882,10 +883,10 @@ def dare_old(A, B, Q, R, S=None, E=None, stabilizing=True):
size(S) == 1 and m > 1:
raise ControlArgument("Incompatible dimensions of S matrix.")

if not(asarray(Q) == asarray(Q).T).all():
if not_is_symmetric(Q):
raise ControlArgument("Q must be a symmetric matrix.")

if not(asarray(R) == asarray(R).T).all():
if not_is_symmetric(R):
raise ControlArgument("R must be a symmetric matrix.")

# Create back-up of arrays needed for later computations
Expand DownExpand Up@@ -960,3 +961,12 @@ def dare_old(A, B, Q, R, S=None, E=None, stabilizing=True):
# Invalid set of input parameters
else:
raise ControlArgument("Invalid set of input parameters.")


def _is_symmetric(M):
M = atleast_2d(M)
if isinstance(M[0, 0], inexact):
eps = finfo(M.dtype).eps
return ((M - M.T) < eps).all()
else:
return (M == M.T).all()
Loading

[8]ページ先頭

©2009-2025 Movatter.jp