Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Addressing #84 and #85 #91

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 30, 2016
Merged
Show file tree
Hide file tree
Changes from all 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
21 changes: 12 additions & 9 deletions control/statesp.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
dot, empty, exp, eye, matrix, ones, pi, poly, poly1d, roots, shape, sin, \
zeros, squeeze
from numpy.random import rand, randn
from numpy.linalg import inv, det, solve
from numpy.linalg import solve, eigvals, matrix_rank
from numpy.linalg.linalg import LinAlgError
from scipy.signal import lti, cont2discrete
# from exceptions import Exception
Expand Down Expand Up @@ -405,7 +405,7 @@ def freqresp(self, omega):
def pole(self):
"""Compute the poles of a state space system."""

return roots(poly(self.A))
return eigvals(self.A)

def zero(self):
"""Compute the zeros of a state space system."""
Expand Down Expand Up @@ -452,21 +452,24 @@ def feedback(self, other=1, sign=-1):
D2 = other.D

F = eye(self.inputs) - sign * D2 * D1
if abs(det(F)) < 1.e-6:
if matrix_rank(F) != self.inputs:
raise ValueError("I - sign * D2 * D1 is singular.")

E = inv(F)
T1 = eye(self.outputs) + sign * D1 * E * D2
T2 = eye(self.inputs) + sign * E * D2 * D1
# Precompute F\D2 and F\C2 (E = inv(F))
E_D2 = solve(F, D2)
E_C2 = solve(F, C2)

T1 = eye(self.outputs) + sign * D1 * E_D2
T2 = eye(self.inputs) + sign * E_D2 * D1

A = concatenate(
(concatenate(
(A1 + sign * B1 * E * D2 * C1, sign * B1 * E * C2), axis=1),
(A1 + sign * B1 * E_D2 * C1, sign * B1 * E_C2), axis=1),
concatenate(
(B2 * T1 * C1, A2 + sign * B2 * D1 * E * C2), axis=1)),
(B2 * T1 * C1, A2 + sign * B2 * D1 * E_C2), axis=1)),
axis=0)
B = concatenate((B1 * T2, B2 * D1 * T2), axis=0)
C = concatenate((T1 * C1, sign * D1 * E * C2), axis=1)
C = concatenate((T1 * C1, sign * D1 * E_C2), axis=1)
D = D1 * T2

return StateSpace(A, B, C, D, dt)
Expand Down
7 changes: 4 additions & 3 deletions control/tests/statesp_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,13 @@ def setUp(self):
def testPole(self):
"""Evaluate the poles of a MIMO system."""

p = self.sys1.pole()

np.testing.assert_array_almost_equal(p, [3.34747678408874,
p = np.sort(self.sys1.pole())
true_p = np.sort([3.34747678408874,
-3.17373839204437 + 1.47492908003839j,
-3.17373839204437 - 1.47492908003839j])

np.testing.assert_array_almost_equal(p, true_p)

def testZero(self):
"""Evaluate the zeros of a SISO system."""

Expand Down