- Notifications
You must be signed in to change notification settings - Fork441
fixed StateSpace for complex inputs#468
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
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -70,7 +70,7 @@ | ||
# Define module default parameter values | ||
_statesp_defaults = { | ||
'statesp.use_numpy_matrix':False, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Please don't change the default setting here. We have a road map in mind when this should happen and it should be independent of the support for complex types. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. That said, actually#438 takescomplex inputs into account already! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Ok, I will change this back There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more.
Oh, I see, should I close my PR? | ||
'statesp.default_dt': None, | ||
'statesp.remove_useless_states': True, | ||
} | ||
@@ -98,11 +98,11 @@ def _ssmatrix(data, axis=1): | ||
# Convert the data into an array or matrix, as configured | ||
# If data is passed as a string, use (deprecated?) matrix constructor | ||
if config.defaults['statesp.use_numpy_matrix']: | ||
arr = np.matrix(data, dtype=complex) | ||
elif isinstance(data, str): | ||
arr = np.array(np.matrix(data, dtype=complex)) | ||
else: | ||
arr = np.array(data, dtype=complex) | ||
ndim = arr.ndim | ||
shape = arr.shape | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
from matplotlib import pyplot as plt | ||
import numpy as np | ||
from scipy.linalg import eig | ||
from control import step_response, StateSpace | ||
# Example of diagonalization of StateSpace representation | ||
# In this example the diagonalized system has complex values on the matrices | ||
def diagonalize(A, B, C, D): | ||
eigenvectors_matrix = eig(A)[1] | ||
A = np.matmul(np.matmul(np.linalg.inv(eigenvectors_matrix), A), eigenvectors_matrix) | ||
B = np.matmul(np.linalg.inv(eigenvectors_matrix), B) | ||
C = np.matmul(C, eigenvectors_matrix) | ||
print(A) | ||
print(B) | ||
print(C) | ||
print(D) | ||
return A, B, C, D | ||
def main(): | ||
A = np.array([[0, 0, 1000], [0.1, 0, 0], [0, 0.5, 0.5]]) | ||
B = np.array([[0], [0], [1]]) | ||
C = np.array([[0, 0, 1]]) | ||
D = np.array([[0]]) | ||
Aw, Bw, Cw, Dw = diagonalize(A, B, C, D) | ||
system = StateSpace(A, B, C, D, 1) | ||
system_w = StateSpace(Aw, Bw, Cw, Dw, 1) | ||
length = 20 | ||
plt.figure(figsize=(14, 9), dpi=100) | ||
response_w = step_response(system_w, T=np.arange(length)) | ||
response = step_response(system, T=np.arange(length)) | ||
plt.plot(response[0], response[1], color="red", label="System") | ||
plt.plot(response_w[0], response_w[1], color="blue", label="System W") | ||
plt.xticks(np.arange(length)) | ||
plt.legend() | ||
plt.savefig("diagonalization.png") | ||
main() |