|
5 | 5 | Implementation of the functions lyap, dlyap, care and dare |
6 | 6 | for solution of Lyapunov and Riccati equations. """ |
7 | 7 |
|
8 | | -# Python 3 compatability (needs to go here) |
| 8 | +# Python 3 compatibility (needs to go here) |
9 | 9 | from __future__ import print_function |
10 | 10 |
|
11 | 11 | """Copyright (c) 2011, All rights reserved. |
|
41 | 41 | Author: Bjorn Olofsson |
42 | 42 | """ |
43 | 43 |
|
44 | | -from numpy.linalg import inv |
45 | 44 | from scipy import shape, size, asarray, asmatrix, copy, zeros, eye, dot |
46 | | -from scipy.linalg import eigvals, solve_discrete_are |
| 45 | +from scipy.linalg import eigvals, solve_discrete_are, solve |
47 | 46 | from .exception import ControlSlycot, ControlArgument |
48 | 47 |
|
49 | 48 | __all__ = ['lyap', 'dlyap', 'dare', 'care'] |
@@ -557,9 +556,9 @@ def care(A,B,Q,R=None,S=None,E=None): |
557 | 556 |
|
558 | 557 | # Calculate the gain matrix G |
559 | 558 | if size(R_b) == 1: |
560 | | - G = dot(dot(1/(R_ba),asarray(B_ba).T) , X) |
| 559 | + G = dot(dot(1/(R_ba), asarray(B_ba).T), X) |
561 | 560 | else: |
562 | | - G = dot(dot(inv(R_ba),asarray(B_ba).T) , X) |
| 561 | + G = dot(solve(R_ba, asarray(B_ba).T), X) |
563 | 562 |
|
564 | 563 | # Return the solution X, the closed-loop eigenvalues L and |
565 | 564 | # the gain matrix G |
@@ -660,9 +659,9 @@ def care(A,B,Q,R=None,S=None,E=None): |
660 | 659 |
|
661 | 660 | # Calculate the gain matrix G |
662 | 661 | if size(R_b) == 1: |
663 | | - G = dot(1/(R_b),dot(asarray(B_b).T,dot(X,E_b))+asarray(S_b).T) |
| 662 | + G = dot(1/(R_b), dot(asarray(B_b).T, dot(X,E_b)) + asarray(S_b).T) |
664 | 663 | else: |
665 | | - G = dot(inv(R_b),dot(asarray(B_b).T,dot(X,E_b))+asarray(S_b).T) |
| 664 | + G = solve(R_b, dot(asarray(B_b).T, dot(X, E_b)) + asarray(S_b).T) |
666 | 665 |
|
667 | 666 | # Return the solution X, the closed-loop eigenvalues L and |
668 | 667 | # the gain matrix G |
@@ -699,7 +698,7 @@ def dare(A,B,Q,R,S=None,E=None): |
699 | 698 | Rmat = asmatrix(R) |
700 | 699 | Qmat = asmatrix(Q) |
701 | 700 | X = solve_discrete_are(A, B, Qmat, Rmat) |
702 | | - G = inv(B.T.dot(X).dot(B) + Rmat) * B.T.dot(X).dot(A) |
| 701 | + G = solve(B.T.dot(X).dot(B) + Rmat, B.T.dot(X).dot(A)) |
703 | 702 | L = eigvals(A - B.dot(G)) |
704 | 703 | return X, L, G |
705 | 704 |
|
@@ -825,11 +824,11 @@ def dare_old(A,B,Q,R,S=None,E=None): |
825 | 824 |
|
826 | 825 | # Calculate the gain matrix G |
827 | 826 | if size(R_b) == 1: |
828 | | - G = dot( 1/(dot(asarray(B_ba).T,dot(X,B_ba))+R_ba) , \ |
829 | | - dot(asarray(B_ba).T,dot(X,A_ba)) ) |
| 827 | + G = dot(1/(dot(asarray(B_ba).T, dot(X, B_ba)) + R_ba), \ |
| 828 | + dot(asarray(B_ba).T, dot(X, A_ba))) |
830 | 829 | else: |
831 | | - G = dot( inv(dot(asarray(B_ba).T,dot(X,B_ba))+R_ba) , \ |
832 | | - dot(asarray(B_ba).T,dot(X,A_ba)) ) |
| 830 | + G = solve(dot(asarray(B_ba).T, dot(X, B_ba)) + R_ba, \ |
| 831 | + dot(asarray(B_ba).T, dot(X, A_ba))) |
833 | 832 |
|
834 | 833 | # Return the solution X, the closed-loop eigenvalues L and |
835 | 834 | # the gain matrix G |
@@ -930,11 +929,11 @@ def dare_old(A,B,Q,R,S=None,E=None): |
930 | 929 |
|
931 | 930 | # Calculate the gain matrix G |
932 | 931 | if size(R_b) == 1: |
933 | | - G = dot( 1/(dot(asarray(B_b).T,dot(X,B_b))+R_b) , \ |
934 | | - dot(asarray(B_b).T,dot(X,A_b)) + asarray(S_b).T) |
| 932 | + G = dot(1/(dot(asarray(B_b).T, dot(X,B_b)) + R_b), \ |
| 933 | + dot(asarray(B_b).T, dot(X,A_b)) + asarray(S_b).T) |
935 | 934 | else: |
936 | | - G = dot( inv(dot(asarray(B_b).T,dot(X,B_b))+R_b) , \ |
937 | | - dot(asarray(B_b).T,dot(X,A_b)) + asarray(S_b).T) |
| 935 | + G = solve(dot(asarray(B_b).T, dot(X,B_b)) + R_b, \ |
| 936 | + dot(asarray(B_b).T, dot(X,A_b)) + asarray(S_b).T) |
938 | 937 |
|
939 | 938 | # Return the solution X, the closed-loop eigenvalues L and |
940 | 939 | # the gain matrix G |
|
0 commit comments