Room 14-0551 77 Massachusetts Avenue Cambridge, MA 021 39 sMTiebravies braries W eIT M Document Services Ph: 617.253.5668 Fax: 617.253.1690 Email: docs@mit.edu http://libraries.mit.edu/docs DISCLAIMER OF QUALITY Due to the condition of the original material, there are unavoidable flaws in this reproduction. We have made every effort possible to provide you with the best copy available. If you are dissatisfied with this product and find it unusable, please contact Document Services as soon as possible. Thank you. Pages are missing from the original document. ( o'.'(') LIDS- P 859 Research Supported By: ERDA-E contract (49-18)-2087 A Schur Method for Solving Algebraic Riccati Equations* Laub, A.J. A SCHUR METHOD FOR SOLVING ALGEBRAIC RICCATI EQUATIONS* by Alan J. Laub** ABSTRACT In this paper a new algorithm for solving algebraic Riccati equations (both continuous-time and discrete-time versions) is presented. The method studied is a variant of the classical eigenvector approach and uses instead an appropriate set of Schur vectors thereby gaining substantial numerical advantages. number of numerical issues. Considerable discussion is devoted to a The method is apparently quite numerically stable and performs reliably on systems with dense matrices up to order 100 or so, storage being the main limiting factor. *This research was supported by the U.S. Energy Research and Development Agency under contract ERDA-E(49-18)-2087. **Laboratory for Information and Decision Systems, Rm. 35-331, Massachusetts Institute of Technology, Cambridge, MA 02139; ph.: (617)-253-2125. -2- 1. Introduction In this paper a new algorithm for solving algebraic Riccati equations (both continuous-time and discrete-time versions) is presented. These equations play fundamental roles in the analysis, synthesis, and design of linear-quadratic-Gaussian control and estimation systems as well as in many other branches of applied mathematics. It is not the purpose of this paper to survey the extensive literature available for these equations but, rather, we refer the reader to, for example, [5] for references. [1], [2], [31, [4], and Nor is it our intention to investigate any but the unique (under suitable hypotheses) symmetric, nonnegative definite solution of an algebraic Riccati equation even though the algorithm to be presented does also have the potential to produce other solutions. For further reference to the "geometry" of the Riccati equation we refer to [31, 16], and [7]. The method studied here is a variant of the classical eigenvector approach to Riccati equations, the essentials of which date back to at least von Escherich in 1898 18]. The approach has also found its way into the control literature in papers by, for example, MacFarlane Potter 110], and Vaughn 111]. [9], Its use in that literature is often associated with the name of Potter. However, the use of eigenvectors is often highly unsatisfactory from a numerical point of view and the present method uses the so-called and much more numerically attractive Schur vectors to get a basis for a certain subspace of interest in the problem. Other authors such as Fath [121 and Willems [31, to name two, have also noted that any basis of the subspace would suffice but the specific -3- use of Schur vectors was inhibited by a not-entirely-straightforward problem of ordering triangular canonical forms - a problem which. is discussed briefly in the sequel. The paper by Fath is very much in the spirit of the work presented here and is one of the very few in the literature which seriously addresses numerical issues. One of the best summaries of the eigenvector approach to solving algebraic Riccati equations is the work of Martensson [13]. This work extends [10] to the case of "multiple closed-loop eigenvalues." It will be shown in the sequel how the present approach recovers all the theoretical results of [10] and [131 while providing significant numeri- cal advantages. Most numerical comparisons of Riccati algorithms tend to favor the standard eigenvector approach - its numerical difficulties notwithstandingover other approaches such as Newton's method integrating a Riccati differential equation. [7], [15], and [16]. [14] or methods based on Typical of such comparisons are It will be demonstrated in this paper that if you previ- ously liked the eigenvector approach, you must prefer, almost by definition, the Schur vector approach. This statement, while somewhat simplistic, is based on the fact that a Schur vector approach provides a substantially more efficient, useful, and reliable technique for numerically solving algebraic Riccati equations. The method is intended primarily for the solution of dense, moderate- sized equations (say, order < 100) rather than large, sparse equations. While the algorithm in its present state offers much scope for improvement, it still represents a substantial improvement over current direct methods for solving algebraic Riccati equations. -4- Briefly, the rest of the paper is organized as follows. is concluded with some notation and linear algebra review. This section In Sections 2 and 3 the continuous-time and discrete-time Riccati equations, respectively, are treated. In Section 4 numerical issues such as algorithm implementation, balancing, scaling, operation counts, timing, storage, stability, and conditioning are considered. In Section 5 we emphasize the advantages of the Schur vector approach and make some further general remarks. Six examples are given in Section 6 and some concluding remarks are made in Section 7. 1.1 Notation Throughout the paper A e efficients in a field IR IF. or the complex numbers IF will denote an mxn matrix with co- The field will usually be the real numbers C. The notations AT and AH will denote transpose and conjugate transpose, respectively, while A (A ) = (A ) . The notation A -T will denote will denote the Moore-Penrose pseudo- inverse of the matrix A. For A e will be denoted by C(A). When a matrix A e nxn its spectrum (set of n eigenvalues) IR2nx2n is partitioned into four nxn blocks as A= 112 A128 21 A22/ A we shall frequently refer to the individual blocks A..i discussion. without further -5- 1.2 Linear Algebra Review Definition 1: A e Definition 2: A e Let J = IR = A- 1 is orthogonal if A nxn H -l x is unitary if A = A IR2 nx2 n where I denotes the ni- order identity matrix. e 0 I Note that J T = -l = -J. Definition 3: A e IR is Hamiltonian if J Definition 4: A e IR is symplectic if J-1 A J = A - 1 Hamiltonian A TJ = -A. and symplectic matrices are obviously closely related. For a discussion of this relationship and a review of "symplectic algebra" see [17], algebra. [18]. We will use the following two theorems from symplectic Their proofs (see [18]) are trivial (and hence will be omitted). Theorem 1: 1. Let A e IR be Hamiltonian. implies -X e C(A) with the same multiplicity. 2. symplectic. Then X e CG(A) implies X Then X e CT(A) Let A e IR2 n x 2n, be e aC(A) with the same multiplicity. There is a relationship between the right and left eigenvectors of these symplectically associated eigenvalues. Theorem 2: U e Let A e IR R 2 n x 2 n be symplectic. See [18] be Hamiltonian for details. (or symplectic). Then U-1 AU is Hamiltonian Let (or symplectic). Finally, we need two theorems from classical similarity theory which form the theoretical cornerstone of modern numerical linear algebra. See [19], for example, for a textbook treatment. -6- Theorem 3 (Schur canonical form): Xl,...,X . Let A e Rxn have eigenvalues Then there exists a unitary similarity transformation U such that U AU is upper triangular with diagonal elements Al,... k n in that order. In fact, it is possible to work only over IR by reducing to quasi- upper-triangular form with 2x2 blocks on the (block) diagonal corresponding to complex conjugate eigenvalues and lxl blocks corresponding to the real eigenvalues. We refer to this canonical form as the real Schur form (RSF) or the Murnaghan-Wintner Theorem 4 (RSF): Let A e canonical form. [.20] nR nxn . Then there exists an orthogonal T similarity transformation U such that U AU is quasi-upper-triangular. Moreover, U can be chosen so that the 2x2 and lxl diagonal blocks appear in any desired order. T If in Theorem 4 we partition U AU into 11 S12 kR O<k<n, we shall refer to the first k vectors of U as corresponding to C(S ll) C G(A). where Sll e kxk the Schur vectors The Schur vectors corresponding to the eigenvalues of Sll span the eigenspace corresponding to those eigenvalues even when some of the eigenvalues are multiple (see [21]). use this property heavily in the sequel. We shall -7- 2. The Continuous-Time Algebraic Riccati Equation In this section we shall present a method for using a certain set of Schur vectors to solve (for X) the continuous-time algebraic Riccati equation F X + XF - XGX + H = O . All matrices are in ]R n (1) and G = GT > 0, H = H > 0. It is assumed that (F,B) is a stabilizable pair [1] where B is a full-rank factorization (FRF) of G(i.e., BB and (C,F) is a detectable pair and rank(C) = rank(H)). [11 T = G and rank(B) = rank(G)) where C is a FRF of H (i.e., Under these assumptions, a unique nonnegative definite solution 1J1. C C = H (1) is known to have There are, of course, other solutions to (1) but for the algorithm presented here the emphasis will be on computing the nonnegative definite one. Now consider the Hamiltonian Z < ( F -GA e -H matrix 2nx2n R2 nx 2 n (2) -F/ Our assumptions guarantee that Z has no pure imaginary eigenvalues. Thus by Theorem 4 we can find an orthogonal transformation U e R 2 nx 2 n which puts Z in RSF: S1:2 12 =ll U ZU = S = \° where S.. e 1j R nx (3) S22/ It is possible to arrange, moreover, that the real parts of the spectrum of Sll are negative while the real parts of the spectrum of S22 are positive. nxn blocks: U is conformably partitioned into four -8- U 11 U12 U21 U2 2 We then have the following theorem. Theorem 5: 1. Ull is invertible and X=U1U 2. Proof: With respect to the notation and assumptions above: (Sll) -1 1 solves T (1) with X=X >0. = c(F-GX) = the "closed-loop" spectrum. A direct proof of this theorem may be found in [22] omitted here. but will be An alternate proof is suggested in Remark 1 below. Remark 1: As an alternative to the direct proofs provided in [22] one could simply appeal to the proofs given for the eigenvector approach and note that the Schur vectors are related to the eigenvectors by a nonsingular transformation. Specifically, with Z, U, and S as above, let V IR 2 2n put Z in real Jordan form 1 (5) (ZV -A= (gnx2n denotes the set of 2n x 2n matrices of rank 2n, i.e., invertible) 2n where -A is the real Jordan form of the eigenvalues of Z with negative real parts. -A. Furthermore, let T epxn transform n S 11 to the real Jordan form Then Z 21 (21-A) (6) and Z (Ull) =(Ul 21W v11e tU21 We thus have 2 21:3;t1 11··~ -9- 1~T (-A) .(7) 2J Since eigenvectors are unique up to nonzero scalar multiple, comparing (6) and (7) we must have (1 T= (V1)DT where D is V -1 Vl1 21 11 solves -1 21 11 diagonal and invertible, (1), U -1 Ull must also solve 21 11 -1 21 Thus -1 -1 11 11 =Vll -1 and since (1) since -1 21 11' Further discussion of Theorem 5 and computational considerations are deferred until Section 4. -10- 3. The Discrete-Time Algebraic Riccati Equation In this section we shall present an analogous method using certain Schur vectors to solve the discrete-time algebraic Riccati equation TT T -1 T - X - FXG(G 2 + GlXG) GXF + H = 0. FTF Here F,-KHX £RE Also, m<n. nxn RR ' G1 £ nxm G2 IR mxm , and H=H (8)* T T >0, G2=G >0. The details of the method for this equation are sufficiently different from the continuous-time case that we shall explicitly present most of them. It is assumed that (F,G1 ) is a stabilizable pair and that (C,F) is a detectable pair where C is a FRF of H (i.e., C C=H and rank (C)= rank (H)). We also assume that F is invertible - a common assumption on the openloop dynamics of a discrete-time system [23]. when F is The details for the case singular or ill-conditioned with respect to inversion can be found in [24]. Under the above assumptions (8) is known to have a unique nonnegative definite solution [25] and the method proposed below will be directed towards finding that solution. -1 T Setting G= G G G we consider this time the symplectic matrix 12 1 (F+GF TH -F H (9) -GFT F Our assumptions guarantee that Z has no eigenvalues on the unit circle. Theorem 4 we can find an orthogonal transformation U E IR 2nx2n which puts Z in RSF: *Note that an alternate equivalent form of T FT(X T-1 - G) T-= +GG 1 2 G1 F F-X+H=0 By (8) when X is invertible is: UTZU = S 0 where Sij £ R nxn (10) 12 11 S22 . It is possible to arrange, moreover, that the spectrum of Sll lies inside the unit circle while the spectrum of S22 lies outside the unit circle. Again U is partitioned conformably. We then have the following theorem. Theorem 6: With respect to the notation and assumptions above: 1. -1 Ull is invertible and X=U21Ull solves 2. C(Sll)= O(F - G (G2 +G XG ) T = Q(F - GF -T = a(F - G(X -1 T (8) with X=X >0. -1 T G1XF) (X-H)) + G) -1 F) when X is invertible = the "closed-loop" spectrum. Proof: As for Theorem 5 we shall omit a direct proof of this theorem and refer the interested reader instead to [22] or [24]. Again an alternate proof is possible as in Remark 1. We now turn to some general numerical considerations regarding the Schur vector approach. -12- 4. Numerical Considerations There are two steps to the Schur vector approach. The first is re- duction of a 2nx 2n matrix to an ordered real Schur form; the second is th the solution of an n - order linear matrix equation. We shall discuss these in the context of the continuous-time case noting differences for the discrete-time case where appropriate. 4.1 Algorithm Implementation It is well-known (see [21], for example) that the double Francis QR algorithm applied to a real general matrix does not guarantee any special order for the eigenvalues on the diagonal of the Schur form. However, it is also known how the real Schur form can be arbitrarily reordered via orthogonal similarities; see [21] for details. further orthogonal similarities required to ensure that Thus any C(Sll) in (3) lies in the left-half complex plane can be combined with the U initially used to get a RSF to get a final orthogonal matrix which effects the desired ordered RSF. Stewart has recently published FORTRAN subroutines for calculating and ordering the RSF of a real upper Hessenberg matrix 126]. The lxl or 2x 2 blocks are ordered so that the eigenvalues appear in descending order of magnitude along the diagonal. Stewart's software (HQR3) may thus be used directly if one is willing to first apply to the Z of (2) an appropriate bilinear transformation which maps the left-half-plane to the exterior of the unit circle. Since the transformed Z is an analytic function of Z, the U that reduces it to an ordered RSF - with half the eigenvalues outside the unit circle - is the desired U from which the solution of (1) may be constructed. Alternatively, Stewart's software can be modified to directly reorder a RSF by algebraic sign. In the discrete-time case, HQR3 can be used directly by working with -1 Z = /F-1 -1 FG-1 T HFG (11) The U which puts G(Sll) outside the unit circle is thus the same U which puts the upper left nxn block of the RSF of Z inside the unit circle. In summary then, to use HQR3 we would recommend using the following sequence of subroutines (or their equivalents): BALANC to balance a real general matrix ORTHES to reduce the balanced matrix to upper Hessenberg form using orthogonal transformations ORTRAN to accumulate the transformations from the Hessenberg reduction HQR3 to determine an ordered RSF from the Hessenberg matrix BALBAK to backtransform the orthogonal matrix to a nonsingular matrix corresponding to the original matrix. The subroutines BALANC, ORTHES, ORTRAN, BALBAK are all available in EISPACK [27]. th The second step to be implemented is the solution of an n - order linear matrix equation XU 11 U 21 -1 to find X = U21Ull. For this step we would recommend a good linear equation solver such as DECOMP and SOLVE available in 128] or the appropriate routines available in LINPACK 1291. A routine such as DECOMP computes the LU-factorization of Ull and SOLVE performs the forward and backward substitutions. A good estimate of the condition number of Ull with respect to inversion is available with good linear equation software and this estimate should be inspected. A badly con- ditioned Ull usually results from a "badly conditioned Riccati equation". This matter will be discussed further in Section 4.4. While we have no analytical proof at this time, we have observed empirically that a condition number estimate on the order of 10t for Ull usually results in a loss of about t digits of accuracy in X. One final note on implementation. Since X is symmetric it is usually more convenient, with standard linear equation software, to solve the equation T T UllX = U2 11 21 to find X =U 4.2 -TT -1 Ul =U U21 11 21 21 11' Balancing and Scaling Note that the use of balancing in the above implementation results in a nonsingular (but not necessarily orthogonal) matrix which reduces Z to RSF. More specifically, suppose P is a permutation matrix and D is a diagonalmatrix such that PD balances Z, i.e., D PZPD = Zb where Zb is the balanced matrix; see [303 for details. an orthogonal matrix U which reduces Zb to ordered RSF: UTZbU = S We then find -15- Then PDU (produced by BALBAK) is clearly a nonsingular matrix which reduces Z to ordered RSF. The first n columns of PDU span the eigenspace corresponding to eigenvalues of Z with negative real parts and that is the only property we require of the transformation. For simplicity in the sequel, we shall speak of the transformation reducing Z to RSF as simply an orthogonal matrix U with the understanding that the more computationally attractive transformation is of the form PDU. An alternative approach to direct balancing of Z is to attempt some sort of scaling in the problem which generates the Riccati equation. To illustrate, consider the linear optimal control problem of finding a feedback controller u(t) = Kx(t) which minimizes the performance index J(u) = fT Ix (t)Hx(t) + u T (t)Ru(t)Jdt with plant constraint dynamics given by x t) = Fx(t) + Bu(t) We assume H = H ; > 0, R = RT x(.) > 0 and where C C = H and rank(C) = rank(H). = x 0 (F,B) controllable, (F,C) observable Then the optimal solution is well- known to be u(t) = -R lBTXx where X solves the Riccati equation T F X + XF- XBR -l T B X + H 0 Now suppose we change coordinates via a nonsingular transformation x(t). Tw(t). minimize Then in terms of the new state w our problem is to -16- Of [w(t)(TTHT)w(t) + uT(t)Ru(t)ldt subject to O(t) = (T FT)w(t) + (T B)u(t) . The Hamiltonian matrix Z for this transformed system is now given by /-1 -l T ( w T HT HT -1 1 T -T -T-1BR BT-T TTFTT-T -T F T and the associated solution X of the transformed Riccati equation is w related to the original X by X = T X T . One interpretation of T then is as a scaling transformation, a diagonal matrix, for example, in an attempt to "balance" the elements of Z . Applying such a procedure, even w in an ad hoc way, is frequently very useful from a computational point of view. Another way to look at the above procedure is that Zw T) , i.e., is symplectically similar to Z via the transformation T Z = -T It is well-known that Z Z T· is again Hamiltonian (or symplectic in the dis- crete-time case) since the similarity transformation is symplectic. One can then pose the problem of transforming Z by other ities, say orthogonal, symplectic similar_ so as to achieve various desirable numerical properties or canonical forms. presently being investigated. This topic for further research is -17- 4.3 Operation Counts, Timing, and Storage th We shall give approximate operation counts for the solution of n-order algebraic Riccati equations of the form (1) or (8). Each operation is assumed to be roughly equivalent to forming a + (b x c) where a,b,c It is almost impossible to give an accurate are floating point numbers. operation count for the algorithm described above since so many factors are variable such as the ordering of the RSF. We shall indicate only a ballpark 0(n3 ) figure. Let us assume then that we already have at hand the 2n x 2n matrix Z of the form (2) or (9). Note, however, that unlike forming Z in (2), Z in (9) requires approximately 4 n 3 additional operations to construct, given only F, G, and H. This will turn out to be fairly negli- gible compared to the counts for the overall process. Furthermore, we The shall give only order of n3 counts for these rough estimates. three main steps are: Operations (i) (ii) (iii) reduction of Z to upper Hessenberg from -(2n) 3 reduction of upper Hessenberg form to RSF > 4k(2n)3 solution of XUll = 4 3 n U21 The number k represents the average number of QR steps required per eigenvalue and is usually over-estimated by 1.5. > 4k(2n)3 We write since, in general, the reduction may need more operations if ordering is required. Using k = 1.5 we see that the total number 3 of operations required is at least 63 n . Should the ordering of the RSF require, say, 25% more operations than the unordered RSF, we have -18- a ballpark estimate of about 75 n3 for the entire process. Timing estimates for steps (i) and (ii) may be obtained from [27] for a variety of computing environments. The additional time for balancing and for step (iii) would then add no more than about 5% to those times while the additional time for ordering the RSF is variable, but typically adds no more than about 15%. For example, adding 20% to the published figures 127] for an IBM 370/165 (a typical medium speed machine) under OS/360 at the University of Toronto using FORTRAN H Extended with Opt. = 2 and double precision arithmetic, we can construct the following table: Riccati Equation Order n = 10 20 30 40 CPU Time (Sec.) 0.2 1.3 4.0 9.0 In fact, these times are in fairly close agreement with actual observed times for randomly chosen test examples of these orders. Note the approximately cubic behavior of time versus order. Extrapolating these figures for a 64th order equation (see Example 5 in Section 6) one might expect a CPU-time in the neighborhood of 38 sec. In fact, for that particular example the time was approximately 34 sec. It must be re-emphasized here that timing estimates derived as above are very approximate and depend on numerous factors in the actual computing environment as well as the particular input data. However, such estimates can provide very useful and quite reliable information if interpreted as providing essentially order of magnitude figures. -19- With respect to storage considerations the algorithm requires 8n + cn (c = a small constant) storage locations. This fairly large figure limits applicability of the algorithm to Riccati equations on the order of about 100 or less in many common computing environments. Of course, CPU time becomes a significant factor for n>100, also. 4.4 Stability and Conditioning This section will be largely speculative in nature as very few hard results are presently available. A number of areas of continuing research will be described. With respect to stability, the implementation discussed in Section 4.1 consists of two effectively stable steps. The crucial step is the QR step and the present algorithm is probably essentially as stable as QR. The overall two step process is apparently quite stable numerically but we have no proof of that statement., Concerning the conditioning of (1) (or (8)) almost no analytical results are known. The study of (1) is obviously more complex than the study of even the Lyapunov equation F X + XF + H = 0 where H = HT > 0. (12). And yet very little numerical analysis is known for In case F is normal, a condition number with respect to in- version of the Lyapunov operator FX = F X + XF is easily shown to be given by max Xi(F) + Xi (F)| i,j min Lj (12) i (F) + X (F)I -20- But in the general case, a condition number in terms of F rather than F 0 I + I 0 FT ( 0 denotes Kronecker product) has not been determined. Some empirical observations on the accuracy of solutions of certain instances of (12) suggest that one factor influencing conditioning of (12) is the proximity of the spectrum of F to the imaginary axis. more specific, suppose F has an eigenvalue at a + jb withla cally a < 0 is very small). To be >> 1 (typi- t l = 0 (10 ) we lose approximately t digits If of accuracy and we might expect a condition number for the solution of 0 (1 0 t) (12) to also be in this situation. There are some close connections between (12) and (1) (and the respective discrete-time versions) and we shall indicate some preliminary observations here. A perturbation analysis or the notion of a condition number for (1) is intimately related to the condition of an associated Lyapunov equation, namely one whose "F-matrix" approximates the closedloop matrix F-GX where X solves where Y = Y (1). To illustrate, suppose X = Y + E may be interpreted as an approximation of X. 0 = FT (Y+E) + Then (Y+E)F - (Y+E)G(Y+E) + H T T (F-GY) E + E(F-GY) + (F Y + YF - YGY + H) ^AT =F E + EF + H where we have neglected the second-order term EGE. Thus conditioning of (1) should be closely related to nearness of the closed-loop spectrum (c(F-GX)) to the imaginary axis. made elsewhere; Observations similar to these have been see, for example, Bucy [31] where the problem is posed as one of structural stability. A condition number might, in some sense, be thought of as a quantitative measure of the degree of structural stability. -21- Another factor involved in the conditioning of assumptions of stabilizability of (F,B) and detectability of (C,F). For example, near-unstabilizability of or in a control energy sense definitely causes (1) relates to the (i.e., (F,B) in either a parametric sense near-singular controllability Gramian) (1) to become badly conditioned. Our experience has been that the ill-conditioning manifests itself in the algorithm by a badly conditioned Ull. Work related to the conditioning of (1) and (8) is under continuing investigation and will be the subject of another paper. Such analysis is, of course, independent of the particular algorithm used to solve (1) or (8), but is useful to understand how ill-conditioning can be expected to manifest itself in a given algorithm. -22- 5. Advantages of the Schur Vector Approach and Further General Remarks 5.1 Advantages and Disadvantages of the Schur Vector Approach The advantages of this algorithm over others using eigenvectors as Potter's approach [10] and its extensions) are obvious. (such Firstly, the reduction to RSF is an intermediate step in computing eigenvectors anyway (using the double Francis QR algorithm) so the Schur approach must, by definition, be faster. Secondly, and more importantly, this algorithm will not suffer as severely from the numerical hazards inherent in computing eigenvectors associated with multiple or near-multiple eigenvalues. The computation of eigenvectors is fraught with difficulties (see, e.g. [21] for a cogent discussion) and the eigenvectors themselves are simply not needed. All that is needed is a basis for the eigenspace spanned by the eigenvalues of Z with negative real parts time case). ror) (with an analogous statement for the discrete- As good a basis as is possible (in the presence of rounding er- for this subspace can be found from the Schur vectors comprising the matrixi 11 , independently of individual eigenvalue multiplicities. reader is strongly urged to consult [32] and [21] The (especially pp. 609-610) for further numerical details. The fact that any basis for the stable eigenspace can be used to construct the Riccati equation solution has been noted by many people; see or [3] among others. [12] The main stumbling block with using the Schur vectors was the ordering problem with the RSF but once that is handled satisfactorily the algorithm is easy. -23- The Schur vector approach derives its desirable numerical properties from the underlying QR-type process. To summarize: if you like the eigenvector approach for solving the algebraic Riccati equation you must like the Schur vector approach better. Like the eigenvector approach, the Schur vector approach has the advantage of producing the closed-loop eigenvalues (or whatever is appropriate to the particular application from which the Riccati equation arises) essentially for free. And finally, an important advantage of the Schur vector approach, in addition to its general reliability for engineering applications, is its speed in comparison with other methods. We have already mentioned the advantage, by definition, over previous eigenvector approaches but there is also generally an even more significant speed advantage over iterative methods. This advantage is particularly apparent in poorly conditioned problems and in cases in which the iterative method has a bad starting value. Of course, it is impossible to make the comparison between a direct versus iterative method any more precise for general problems but we have found it not at all uncommon for an iterative method, such as straightforward Newton [14], to take ten to thirty times as long - if, indeed, there was convergence at all. As mentioned above, a possible disadvantage of the method is the storage requirement of at least two 2nx2n arrays. Another disadvantage is -1 the fact that for the computed X=U21Ull there is no guarantee of symmetry. In practice, we have found the deviation from symmetry to be only slight for most problems, becoming more pronounced only when the Riccati equation was known to be "ill-conditioned." This phenomenon might be used advantageously if the deviation from perfect symmetry could be used to reliably monitor conditioning. -24- 5.2 Miscellaneous General Remarks Remark 2: An n th- order algebraic Riccati equation has a finite number of solutions if the characteristic and minimal polynomials of F - GX are equal where X is the unique nonnegative definite solution. In that case there are still as many as( nsolutions corresponding to as many as( of the 2n eigenvalues of Z. choices of n Any of these solutions may also be generated by the Schur approach, as for the eigenvector approach, by an appropriate reordering of the RSF. For most control and filtering applications we are interested in the unique nonnegative definite solution and we have thus concentrated the exposition on that particular case. Remark 3: One of the most complete sources for an eigenvector-oriented proof of Theorem 5 for the general case of multiple eigenvalues is Martensson [13]. But even a casual glance at that proof exposes the awkwardness of fussing with eigenvectors and principal vectors. The proof using Schur vectors is extremely clean and easy by comparison and neatly avoids any difficulties with multiple eigenvalues. This observation is but one instance of the more general observation that Schur vectors can probably always replace principal vectors (or generalized eigenvectors) corresponding to multiple eigenvalues throughout linear control/systems theory. Principal vectors are not generally reliably computable in the presence of roundoff error anyway (see [21]) and a basis for an eigenspace - but not the particular one corresponding to the principal vectors - is all that is normally needed. Use of Schur vectors will not only frequently provide cleaner proofs but is also numerically much more attractive. Remark 4: The same Schur vector approach employed in this paper can also be used instead of the eigenvector approach for the nonsymmetric matrix quadratic -25- equation (13) XEX + FX + XG + H = 0 where E I mxn , F £ IR nxn ,GE R mxm ,H C I nxm , andXE R nxm . In this case, we work with the (m+n) x (m+n) matrix Z -GEF and various solutions of (13) are determined by generating appropriate combinations of m eigenvalues of Z along the diagonal of the RSF of Z. corresponding m Schur vectors give the solution X = U Ul IR ~mxm , U21 C IR nxm . [33], -1 U1 as before where 21 11 The analogous remarks apply for the corresponding nonsymmetric "discrete-time equation." both cases. The Proofs are essentially the same in Further details on the eigenvector approach can be found in [34]. Remark 5: Special cases of the matrix quadratic equations such as (1), (8), or (13) include the Lyapunov equation part FTXF - X + H = O) (12) (or its discrete-time counter- and the Sylvester equation FX + XG + H = 0 (14) (or its discrete-time counterpart FXG - X + H = 0). Thus setting an appropriate block of the Z matrix equal to 0 provides a method of solving such "linear equations" and, in fact, this method has even been proposed in the literature [35]. However, the approach probably has little to recommend it from a numerical point of view as compared to applying the Bartels-Stewart algorithm [39] and we mention it only in passing. -26- 6. Examples In this section we give a few examples both to illustrate various points discussed previously and to provide some numerical results for comparison with other approaches. All computations were done at M.I.T. on an IBM 370/168 using FORTRAN H Extended (Opt. = 2) and double precision arithmetic. Example 1: The Schur vector approach is obviously not well-suited to hand computation - which partly explains its desirable numerical properties. However, to pacify a certain segment of the population a "hand example" is provided in complete detail. T Consider the equation -1T A X + XA - XBR B X + Q = 0 (15) which arises in a linear-quadratic optimal control context with 1, A=( B= A, Then 0 1 0 0 0 0 0 -1 0 0 0 -2 -1 0 -1 0 and the matrix 1 _ _V5 2 10 1 __5 2 10 21 305 2 10 _1 2 - _3V/ 10 3/5 1 10 2 3_5 1 10 2 1 10 2 10 1 2 R= 1, Q= -27- is an orthogonal matrix which reduces Z to RSF -1 0 1 0 -1 -1 1 O 0 1 0 0 0 0 1 S = U ZU = Then the unique positive definite solution of (15) is given by the solution of the linear matrix equation XUll = U21 or 11 2 2 1lO 0 10 10 Thus X = ( ) 2 10 and it can quickly be checked that the spectrum of the "closed-loop matrix" is {-1, -1} as was (A- BR-1BTX) = \-1 -2 evident from Sll. Example 2: For checking-purposes consider the solution of (15) with the following uncontrollable but stabilizable, and unobservable but detectable data: A= 6 3) B( ) R=l, ( ) -28- /9c The solution of (15) is X = - loop spectrum is }. 6c where c = 1 + W and the closed4c 6c These values were all obtained correctly to at least 14 significant figures as were the values for the corresponding discrete-time problem T T T -lT A XA - X - ATXB(R+ B XB) B XA + Q = 0 (16) the solution of which is 9d 6d\ X= \6d 4d 1+ where d - 2 Example 3: 1 and the closed-loop spectrum is {- 2' 2 /0~.9512 0~ , 4.877 4.877 1.1895 3.569/ I B= 0 0.9048 3-- .005 , R= The solution of 0 Q 3 X } For further comparison purposes consider the discrete-time system of Example 6.15 in [36] where A 3 - -2' 0 0.02) (16) is given by 0.010459082320970 0.003224644477419 0.003224644477419 0.050397741135643/ = and the feedback gain F = 0.071251660724426 F3569839235296 .013569839235296 (R+ B XB) BTXA is given by -0.070287376494153 0.045479287667006/ 0.045479287667006/ -29- Note the typographical error in the (1,2)-element of F in [36]. The closed-loop eigenvalues are given by 0.508333461684191 and 0.688069670988913 These are definitely different from [36] but have the same sum. Our numbers do appear to be the correct ones. Example 4: We now consider somewhat higher order Riccati equations arising from position and velocity control for a string of high-speed vehicles. The matrices are taken from a paper by Athans, Levine, and Levis [37]. For a string of N vehicles it is necessary to solve the Riccati equation ATX + XNA N - X NBNR1B+ R N Q NN NNN NNN NNN 0 where all matrices are of order n = 2N-1 and are given by A11 A12 A22 A23 N N-2,N-2 A N-2,N-l ,N-1 0 where A,k Akk ' Akkl= = + 0 --1 -1 -30- and B 1 = NBN N BT diag{l,0,,0,1 N,= QN .. 0,.,1} diag{0,10,0,10,...,10,0} . For the case of 5 vehicles we repeated the calculations presented in [373. The correct values for X rounded to six significant figures are: 1.36302 2.61722 -0.705427 0.936860 -0.293666 0.477354 -0.197375 0.211212 -0.166552 7.59255 -1.68036 1.47522 -0.459506 0.665147 -0.266142 0.280654 -0.211212 1.77478 2.15771 -0.609136 0.670717 -0.262843 0.266142 -0.197375 8.25770 -1.94650 1.75587 -0.670717 0.665147 -0.477354 1.80560 1.94650 -0.609136 0.459506 -0.293666 8.25770 -2.15771 1.47522 -0.936860 1.77478 1.68036 -0.705427 7.59255 -2.61722 [SYMMETRIC] \ 1.36302 While 4 or 5 decimal places are published in [37], it can be seen that, surprisingly, only the first and sometimes the second were correct. Sub- stitution of our full 16 decimal place solution into the Riccati equation -14 gives a residual of norm on the order of 10 (-consistent with a condition estimate of U11 of 26.3) while the residual for the solution in [37] has a large norm on the order of 10 . The closed-loop eigenvalues for the above problem (again rounded to six significant figures) are: -1.00000 -1.10779 -1.45215 -1.67581 -1.80486 + + + + 0.852759 1.26836 1.51932 1.66057 j j j j We also computed the Riccati solution and closed-loop eigenvalues for the cases of 10 and 20 vehicles. This involved the solutions of 19th and 39th order Riccati equations, respectively, and rather than -31- reproduce all the numbers here we give only the first five and last five elements of the first row (or column) of X and the fastest and slowest closed-loop modes. Again all values are rounded to just six significant figures; the complete numerical solutions are available from the author. First row (column) of Riccati Solution N=10 N=20 n=19 n=39 1.40826 1.42021 2.66762 2.68008 -0.658219 -0.646127 1.04031 1.06539 -0.242133 -0.229761 -0.0515334 -0.0123718 0.103453 0.0250824 -0.0472086 -0.0120915 0.0504036 0.0124632 -0.0452352 -0.0119545 Fastest and Slowest Closed-Loop Modes N=10 n=19 N=20 n=39 -1.83667 -1.84459 + 1.69509 j -0.862954 + 1.70368 j -0.662288 + 0.494661 j The closed-loop eigenvalues for the case of, say, 10 vehicles interlace andinclude, as a subset, those of 5 vehicles. Similarly, those for 20 vehicles interlace and include, as a subset, those of 10 (and hence 5) vehicles. It appears evident that both the elements of the Riccati solution and the closed-loop eigenvalues are converging to values in some finite region. Example 5: This example involves circulant matrices. solve (15) with We wish to -32- -2 1 and BR B 1 0. 1 0 . . .1 I, Q I *2 The matrices A, BR the Riccati solution X e JR X0 Xn-l Xn X1 X Xn-l X1 X0 X= X 2 2 is B, Q are all circulant so known to be circulant of the form . . . x X2 In fact, there is a simple transformation which "diagonalizes" the Riccati equation and allows the solution of (15) to be recovered via the solution of n scalar quadratic equations and an inverse discrete Fourier transform. The details of this procedure and related analysis of circulant systems can be found in the work of Wall r[38]. For this example, we have n = 64 and the xe are given by k=OX 4 2+2cos 5-4cos where w64 is a 64-th root of unity. 0 + 4 26k ik The solution was computed by the Schur vector approach and checked by means of the circulant analysisf -33- of Wall. Our figures. computed Riccati solution had at least 13 significant For reference purposes we list Xll = 0.37884325313566 x12 = 0,18581947375535 X44 = 0.37884325313567 x = 0.18581947375536 The closed-loop eigenvalues are all real and are arranged as follows: -4.1231056256177 -4.1137632861146 -4.1137632861146 31 eigenvalues of multiplicity 2 -0.99999999999991 th This 64- order example required approximately 50 sec. of CPU time on the 370/168 at M.I.T. and approximately 34 sec. on the 370/165 at the University of Toronto - both using FORTRAN H Extended (Opt. =2), double precision. Example 6: This example is one which would be expected to cause problems on physical grounds and which appears to give rise to an "ill-conditioned Riccati equation". Consider the solution of (15) with -34- 0 1 o Oi 0 0 A=01 , B O/ O0 Q = diag{q,0,...,0}, R=r Here we have a system of n integrators connected in series. It is desired' th to apply a feedback controller to the n--system (which is to be integrated n times) so as to achieve overall asymptotic stability. x1 th Only deviations of integral of the constant system) from 0 are penalized. (the n- The reachability Gramian t Wt = f ;A e T sAT BB e ds while positive definite for all t>0, becomes more nearly singular as n increases. The system ismhard to control" in the sense of requiring a large amount of control energy (as measured by I Wt lI). The closed-loop eigenvalues are easily seen to be the roots of x2n + (_l)n q = 0 r with negative real parts. pattern. In These eigenvalues lie in a classic Butterworth It can also be easily verified that r = product of the closed-loop eigenvalues -35- We attempted the solution of (15) with the above matrices and q= r= 1. While the closed-loop eigenvalues were determined quite accurately as expected (approximately 14 decimal places using IBM double precision), the Riccati solution was increasingly less accurate as n increased due to the increasingly ill-conditioned nature of Ull. For example, for n = 21 there was already a loss of 10 digits of accuracy (consistent with a condition estimate of 0(10 10) for Ull) in xl (=1). Other computed elements of X were as large as 0(109) in magnitude. Repeating the calculations with q = 10 , r = 1 there was a loss of approximately 12 digits of accuracy in xln (=100) for n= 21. other elements of X were as large as 0(10 11) in magnitude. In this case Again, the closed- loop eigenvalues were determined very accurately. Our attempts to get Newton's method to converge on the above problem were unsuccessful. Obviously, there is more that can be said analytically about this problem. Our interest here has been only to highlight some of the numerical difficulties. -36- 7. Concluding Remarks We have discussed in considerable detail a new algorithm for solving algebraic Riccati equations. A number of numerical issues have been addressed and various examples given. The method is apparently quite numerically stable and performs reliably on systems with dense matrices of up to order 100 or so, storage being the main limiting factor. For some reason, numerical analysts have never really studied algebraic Riccati equations. The algorithm presented here can undoubtedly be refined considerably from a numerical point of view but it nonetheless represents an immense improvement over algorithms heretofore proposed. Some topics of continuing research in this area will include: (i) conditioning of Riccati equations, (ii) use of software to sort blocks of the RSF diagonal into just the two appropriate groups rather than within the two groups as well, (iii) making numerically viable the use of symplectic transformations such as in 1171 to reduce the Hamiltonian or symplectic matrix Z to a convenient canonical form. Each of these topics is of research interest in its own right in addition to the application to Riccati equations. -37- 8. References [1] Wonhamn,, W.M., On a Matrix Riccati Equation of Stochastic Control, SIAM J. Contr., 6(1968), 681-697. [2] Reid, W.T., Riccati Differential Equations, Academic Press, New York, 1972. [31 Willems, J.C., Least Squares Stationary Optimal Control and the Algebraic Riccati Equation, IEEE Trans. Aut. Contr., AC-16(1971), 621-634. [4] Silverman, L.M., Discrete Riccati Equations: Alternative Algorithms, Asymptotic Properties, and System Theory Interpretations, in Advances in Control Systems, Vol. 12, (Leondes, Ed.), Academic Press, New York, 1976, pp. 313-386. [51 Lainiotis, D.G., Partitioned Riccati Solutions and Integration-Free Doubling Algorithms, IEEE Trans. Auto. Contr., AC-21 (1976), 677-689. [61 Rodriguez-Canabal, J., The Geometry of the Riccati Equation, Stochastics, 1(1973), 129-149. 7]1 Pachter, M., and T.E. Bullock, Ordering and Stability Properties of the Riccati Equation, Na. Res. Inst. for Math. Sci. Report, WISK 264, Pretoria, June 1977. 181 Von Escherich, G., Die Zweite Variation der Einfachen Integrale, Wiener Sitzungsberichte, 8(1898), 1191-1250. [91 MacFarlane, A.G.J., An Eigenvector Solution of the Optimal Linear Regulator Problem, J. Electron. Contr., 14(1963), 643-654. [101 Potter, J.E., Matrix Quadratic Solutions, SIAM J. Appl. Math., 14(1966), 496-501. 1111 Vaughn, D.R., A Nonrecursive Algebraic Solution for the Discrete Riccati Equation, IEEE Trans. Auto. Contr., AC-15(1970), 597-599. 112] Fath, A.F., Computational Aspects of the Linear Optimal Regulator Problem, IEEE Trans. Auto. Contr., AC-14(1969), 547-550. [131 MArtensson, K., New Approaches to the Numerical Solution of Gptimal Control Problems, Lund Institute of Technol., Divis. of Auto. Contr., Report No. 7206, Lund, Sweden, Mar. 1972. 1141 Kleinman, D.L., On An Iterative Technique for Riccati Equation Computations, IEEE Trans. Auto. Contr., AC-13(1968), 114-115. -38- [15] Farrar, F.A., and R.C. DiPietro, Comparative Evaluation of Numerical Methods for Solving the Algebraic Matrix Riccati Equation, United Technologies Research Center Report No. R76-140268-1, East Hartford, CT, Dec. 1976. [16] Hewer, G.A., and G. Nazaroff, A Survey of Numerical Methods for the Solution of Algebraic Riccati Equations, Naval Weapons Center Report, China Lake, CA. [17] Laub, A.J., and K.R. Meyer, Canonical Forms for Hamiltonian and Symplectic Matrices, Celestial Mechanics, 9(1974), 213-238. [18] Laub, A.J., Canonical Forms for a-Symplectic Matrices, M.S. Thesis, School of Mathematics, Univ. of Minnesota, Dec. 1972. [19] Stewart, G.W., Introduction to Matrix Computations, Academic Press, New York, 1973. [20] Murnaghan, F.D., and A. Wintner, A Canonical Form for Real Matrices Under Orthogonal Transformations, Proc. Na. Adad. Sci., 17(1931), 417-420. [21] Golub, G.H., and J.H. Wilkinson, Ill-Conditioned Eigensystems and the Computation of the Jordan Canonical Form, SIAM Rev., 18(1976) 578-619. [22] Laub, A.J., A Schur Method for Solving Algebraic Riccati Equations, LIDS Report LIDS-R-859, Laboratory for Information and Decision Systems, Massachusetts Institute of Technology, Cambridge, MA 02139. [23] Dorato, P., and A. Levis, Optimal Linear Regulators: The DiscreteTime Case, IEEE Trans. Auto. Contr., AC-16(1971), 613-620. [24] Pappas, T., A.J. Laub, and N.R. Sandell, On the Numerical Solution of the Discrete-Time Algebraic Riccati Equation, LIDS Report, LIDS-P-908, Laboratory for Information and Decision Systems, Massachusetts Institute of Technology, Cambridge, MA 02139. [25] Anderson, B.D.O., and J.B. Moore, Optimal Filtering, Prentice-Hall, Englewood Cliffs, NJ, 1979. [26] Fortran Subroutines for Calculating Stewart, G.W., HQR3 and EXCHNG: and Ordering the Eigenvalues of a Real Upper Hessenberg Matrix, ACM Trans. Math. Software, 2(1976), 275-280. [27] Smith, B.T., et. al., Matrix Eigensystems Routines -- EISPACK Guide, Second Edition, Lect. Notes in Comp. Sci., Vol. 6, Springer-Verlag, New York, 1976. [28] Forsythe, G.E., M.A. Malcolm, and C.B. Moler, Computer Methods for Mathematical Computations, Prentice-Hall, Englewood Cliffs, NJ, 1977. -39- [29] Dongarra, J.J., J.R. Bunch, C.B. Moler, and G.W. Stewart, LINPACK User's Guide, SIAM, Philadelphia, 1979. [30] Parlett, B.N., and C. Reinsch, Balancing a Matrix for Calculation of Eigenvalues and Eigenvectors, Numer. Math., 13(1969), 296-304. [31] Bucy, R.S., Structural Stability for the Riccati Equation, SIAM J. Contr., 13(1975), 749-753. [321 Wilkinson, J.H., The Algebraic Eigenvalue Problem, Oxford University Press, London, 1965. [33] Coppel, W.A., Matrix Quadratic Equations, Bull. Austral. Math. Soc., 10(1974), 377-401. [34] Meyer, H.-B., The Matrix Equation AZ+B-ZCZ-ZD=0, SIAM J. Appl. Math, 30(1976), 136-142. [35] Bar-Ness, Y., and G. Langholz, The Solution of the Matrix Equation XC-BX=D as an Eigenvalue Problem, Int. J. Sys. Sci., 8(1977), 385392. [36] Kwakernaak, H., and R. Sivan, Linear Optimal Control Systems, Wiley, New York, 1972. [37] Athans, M., W.S. Levine, and A. Levis, A System for the Optimal and Suboptimal Position and Velocity Control for a String of High-Speed Vehicles, Proc. 5th International Analogue Computation Meetings, Lausanne, Switzerland, Sept. 1967. [38] Wall, J.E., Control and Estimation for Large-Scale Systems Having Spatial Symmetry, Ph.D. Thesis, M.I.T., Aug. 1978; Electronic Systems Lab. Rept. ESL-TH-842. [39] Bartels, R.H., and G.W. Stewart, Solution of the Matrix Equation AX + XB = C, Comm. ACM, 15(1972), 820-826. -47- APPENDIX 1 We outline here how to set up the "symplectic approach" when the matrix F in FTXF - X - F XG I is singular. (G 2 +Gl XG) - G1 X F + H = O All other assumptions and notation of Section 3 will be the same. Letting xk denote the state at time tk and Xk the corresponding adjoint vector, recall the Hamiltonian difference equations arising from the discrete maximum principle: (I G (xF 0 ( Xk+l Note that if F were invertible we could work with the symplectic matrix F H which is just (9). I -F -TH Here, instead, we shall be concerned with a "symplectic generalized eigenvalue problem" Lz = XMz with F L = -H F- 0 I G) I) O F -48- and symplectic in the sense that if X 4 0 is a generalized eigenvalue then X is a generalized eigenvalue. In fact, L and M are characterized by the property that LJLT = MJMT where J =(C In our specific situation LJL ) = MJM = FT 0 There is even more "reciprocal symmetry" in the problem. With F singular there must be least one generalized eigenvalue at 0 and to each such generalized eigenvalue there corresponds its reciprocal at a. The generalized eigenvalues can then be arranged in two groups of n as before: 1 n with O<Ixil<l. 1 - __ We then find a basis for the generalized eigenspace cor- responding to 0,...,O,X ,...Xk and proceed essentially as before. details are omitted here as they are the subject of a forthcoming paper with T. Pappas. The -49APPENDIX 2 In this appendix we provide FORTRAN source listings for one possible implementation of the Schur vector approach described in the paper. Sub- routines for solving both the continuous-time algebraic Riccati equation (1) tRICCND] and the discrete-time algebraic Riccati equation (8) [RICDSDJ are given. The subroutine names are derived from the following nomenclature convention for a family of subroutines to solve Riccati and various other matrix equations: subroutine name: where XXXYYZ (RIC XXX = Riccati equation LYP Lyapunov equation SYL Sylvester equation ICN continuous-time version YY = DS discrete-time version single (short) precision version Z= D double (long) precision version Subroutine RICCND calls or further requires the following additional subroutines: BALANC, BALBAK, DDCOMP, DSOLVE, EXCHNG, HQR3, MLINEQ, ORTHES, ORTRAN, QRSTEP, SPLIT Subroutine RICDSD requires each of the 11 subroutines above as well as the two additional subroutines MULWOA, MULWOB. -50- All the additional subroutines required have also been listed here with the exception of BALANC, BALBAK, ORTHES, and ORTRAN which are available in EISPACK [27]. These subroutines are being used in the environment described in Section 6 as part of a package called LQGPACK. This package is a preliminary version of a set of subroutines being developed at M.I.T.'s Laboratory for Information and Decision Systems to solve linear-quadraticGaussian control and estimation problems. The package has also been run in a single precision version on a CDC 6600. However, at this time we make no claims of portability of the code to other machines. The code listed here is solely for illustrative purposes. Finally, we add two additional technical notes: NOTE 1: A fairly reliable estimate of the condition number of U11 with respect to inversion is returned by RICCND or RICDSD in WORK (1). NOTE 2: The subroutine HQR3 contains a small error which can occasionally cause RICCND or RICDSD to give erroneous or misleading information. The trouble arises when ORTHES produces an upper Hessenberg form with a zero on the first subdiagonal. HQR3 then correctly orders the resulting RSF both above and below that zero element but not necessarily globally. In practice this almost never happens and it has only ever been observed for certain low-order examples with all coefficient matrices diagonal. This error in HQR3 can and will be corrected. In the interim, error can either be ignored (a safe strategy for virtually all "real problems") or temporarily patched by the following scheme. the -51Let ai+l i be a zero element of the upper Hessenberg matrix A (the output of ORTHES). replaced by e Then before HQR3 is called, ai+l i should be (-Iai,if + jai+l,i+ll)where e is the machine precision (EPS) defined by e = min {6: f(l+I6 I) f 1} (f (-) denotes floating point operation). The source listings now follow. RICCND 1 -52- SUBROUTINE RICCND + C C *****A RAE TER S: INTEGER NZ, NF,NG,NH,N,NN,ITYPE(NN),IPVL (NN) ,IPVS (N) DOUBLE PRECISION Z(NZ,NN),W(NZ,NN),F(NF,N),G(NG,N),H(NH,N), EF (NN),EI(NN),WCRK(N),SCALE(NN) + C C j*****.':LOCAL VARIABLES: INTEGER I,J,LOW,IGH,NLOW,NUP DOUBLE PRECISION EPS, EPSP1,ZNOR.i,,T,ALPHA,COND C C C C C C C C C C C C C C C C C C C C C C C C C C C C C c C C C C C C C c C C C C C (NZ,NF, NG, NH, N,NN,Z,W,F,G,H,ER,EI,ORK, SCALE,ITYPE,IPVL,IPVS) *****FUNCTICNS: DOUBLE PRECISION DABS,DSQRT *****SUBROUTINES CALLED: BALA.NC,BALBAK,HQR3, MLINEQ,ORTHES,ORTRAN -- ::::::::::..:R1C009:0::: ' :::: *****PURPOSE: THIS SUBROUTINE SOLVES THE CONTINUOUS-TIME ALGEBRAIC MATRIX RICCATI EQUATION T F *X + X*F - X*G*X + H = 0 RIC00010 RIC00020 RICO0030 RIC00040 RICO0050 RICOOO60 RIC00070 RICOOO380 RIC00090 RICOOo00 RICOOl110 RIC00120 RIC00130 RIC00140 RICO 1 5O RIC00160 RICOO1 70 RIC0so80 0: : RIC00200 RIC00210 RIC0o0220 RIC00230 RI CO 2 40 RIC00250 RIC00260 RIC00270 APPROACH. HAMILTONIAN-EIGENVECTOR THE BY LAUB'S VARIANT OF RIC00280 R C00290 *****PAR$AMETER DESCRIPTION: RIC00 300 ON INPUT: RIC00310 RIC00320 ROW DIMENSIONS OF THE ARRAYS CONTAINING NZ,NF,NG,NH RIC00330 AS RESPECTIVELY, H, AND Z (AND W),F,G, RIC00340 DECLARED IN THE CALLING PROGRAM DIMENSION RIC00350 STATEMENT; RIC00360 RIC00370 F,G,H; MATRICES OF THE ORDER N RIC00380 RIC00390 = 2*N = ORDER OF THE INTERNALLY GENERATED NN RIC00400 W; Z AND MATRICES RIC00410 RIC00420 MATRIX; (REAL) X N AN N F RIC00430 RIC00440 DEFINITE NONNEGATIVE SYMMETRIC, X N N G,H RIC00450 (REAL) MATRICES. RIC00460 R-IC00470 ON OUTPUT: RIC00480 AN N X N ARRAY CONTAINING THE UNIQUE POSITIVE :RIC00490 H RICOO500 (OR NONNEGATIVE) DEFINITE SOLUTION OF THE RIC00510 RICCATI EQUATION; RIC00520 REAL SCRATCH VECTORS OF LENGTH 2*N; ON OUTPUT RIC00530 ER,EI RIC00540 (ER(I),EI(I)), I=1,N CONTAIN THE REAL AND RIC00550 IMAGINARY PARTS, RESPECTIVELY, OF THE N -53- C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C CLOSED LOOP EIGENVALUES SPECTRUM OF F - G*X); 5 C C C 10 20 RICCND 2 (I.E., THE RIC00560 RIC00570 RIC00580 Z'i 2*N X 2*N REAL SCRATCH ARRAYS USED FOR RIC00590 COMPUTATIONS INVOLVING THE HAMILTONIAN RICOO600 MATRIX ASSOCIATED WITH THE RICCATI EQUATION; RIC00610 RIC00620 WORK,SCALE REAL SCRATCH VECTORS OF LENGTHS N, 2*N, RIC00630 RESPECTIVELY; ON OUTPUT, WORK(1) CONTAINS A RIC00640 CONDITION NUMBER ESTIMATE FOR THE FINAL NTH RIC00650 ORDER LINEAR MATRIX EQUATION SOLVED; RIC00660 RIC00670 ITY PE,IPVL, IP VS INTEGER SCRATCH VECTORS OF LENGTHS 2*N, 2*N, RIC00680 N, RESPECTIVELY. RIC00690 RIC00700 ***NOTE: ALL SCRATCH ARRAYS MUST BE DECLARED AND INCLUDED RIC00710 IN THE CALL.*** RIC00720 RIC007 30 *****ALGORITHM NOTES: RIC00740 IT IS ASSUMED THAT G AND H ARE NONNEGATIVE DEFINITE AND THAT (F,B) RIC00750 T RIC00760 RIC00770 =G IS STABILIZABLE AND (C,F) IS DETECTABLE WHERE B*B T RIC00780 RIC00790 AND C*C = H (C OF FULL (B OF FULL RANK = RANK (G)) RANK = RANK (H)) IN WHICH CASE THE SOLUTION (RETURNED IN THE RIC00800 RIC00810 ARRAY H) IS UNIQUE AND NONNEGATIVE DEFINITE. RIC00820 *****HISTORY: RIC00830 WRITTEN BY ALAN J. LAUB (ELEC. SYS. LAB.., M.I.T., RM. 35-331, RIC00840 CAMBi:IDGE, MA 02139, PH.: (617) - 253-2125), SEPTEMBER 1977. RIC00850 MOST RIlCENT VERSION: SEP. 15, 1978. RIC00860 RI C00870 .::: : 1::::::880:::: RIC00890 EPS IS AN INTERNALLY GENERATA.D MACHINE DEPENDENT PARAMETER RIC00900 SPECIFYING THE RELATIVE PRECISION OF FLOATING POINT ARITHMETIC. RIC00910 FOR EXAMPLE, EPS = 16.ODO**(-13) FOR DOUBLE PRECISION ARITHMETIC RIC00920 ON IBM S360/5370. RIC00930 RIC00940 EPS= .OD0 RIC00950 EPS=0.5D0*EPS RIC00960 EPSP =EPS+1.O D RIC00970 IF (EPSPl.GT.1.0DO) GO TO 5 RIC00980 EPS=2.ODO*EPS RIC00990 I1C01000 SET UP HAMILTONIAN MATRIX RIC01010 RIC01 020 RIC01030 DO 20 J=1,N DO 10 I=1,N RIC01040 RIC0 1050 Z (I ,J) =F (I,J) Z (N+I,J)=-d (I,J) Rt C01 060 RICO 1 70 Z (I ,N+J) -G (I,J) RIC01080 Z (N+I,N+J)=-F(J,I) CONTINUE RIC01090 CONTINUE RIC01100 -54- C C C BALANCE Z CALL BALANC C C C 30 40 C C C C C C C 50 60 C C C C COAPUTE (NZ,NN,Z,LOW,IGH,SCALE) 1-NORM OF Z ZNORM=. ODO DO 40 J=1,NN T=0.ODO DO 30 I= 1,NN T-=T+DABS (Z (I ,J) ) CONTINUE IF (T.GT.ZNGRM) ZNORM=T CONTINUE ALPHA=DSQRT (ZNORM) + 1. 0DO -1 COMPUTE W; = (ALPHA*I + Z) * (ALPHA*I - Z), AN ANALYTIC FUNCTION OF Z MAPPING THE LEFT HALF PLANE TO THE EXTERIOR OF THE UNIT DISK. THIS PERMITS DIRECT APPLICATION OF HQR3. THIS STEP MAY BE REMOVED IF HQR3 IS MODIFIED APPROPRIATELY. DO 60 J=1,NN DO 50 T=1,NN W(I, J) =-Z (I, J) CONTINUE W (3,3) =ALPHA+W (J,J) Z (J,J)=ALPHA+Z (J,J) CONTINUE CALL MLINEQ (NZ, NZ,NN,NN,Z,W,COND,IPVL, ER) REDUCE W TO REAL SCHUR FORM WITH EIGENVALUES OUTSIDE THE UNIT DISK IN THE UPPER LEFT N X N UPPER QUASI-TRIANGULAR BLOCK N LO W_ 1 NUP=NN CALL ORTHES (NZ, NN,NLOW,NUP,W,ER) CALL ORTRAN (NZ,NN,NLOW, NUP,W,ER,Z) DO 15 I=2,NN IF(W(,I-1).EQ. 0.0D ) W (I,I-1)= .OD-14 15 CONTINUE CALL HQE3 (W,Z,NN,NLOW,NUP,EPS,ER,EI,ITYPE, NZ,NZ) C C C C 70 80 RICCND 3 COMPUTE SOLUTION OF THE RICCATI EQUATION FROM THE ORTHOGONAL MATRIX NOW IN THE ARHAY Z. STORE THE RESULT IN THE ARRAY H. CALL BALBAK (NZ,NN,LOW,IGH, SCALE, NN,Z) DO 80 J=1,N DO 70 I1=,N F (I J) =Z (J,I) H (I ,J) =Z (N+J,I) CONTINUE CONTINUE CALL MLINEQ (NF,NH,N,N,F,H,COND,IPVS,WORK) RIc01110 RIC 1 1 20 RIC01 30 RIC0 1 140 RICO 150 RIC01160 RIC01170 RIC01180 RICO 1190 RIC01200 RIC01210 RIC01220 RIC01230 RIC01240 RIC01250 RIC01260 RIC01270 RIC01280 RIC01290 RIC01300 RIC01310 RIC 01320 RIC01330 RIC01340 RIC01350 RICO 360 RIC01370 RIC01 380 RIC0 1390 RIC01400 RIC01 410 R IC01 42 O RIC03 1430 RIC01440 RIC01450 RI CO 14 60 RIC01 470 RIC01480 RIC01490 RIC01500 C01 51 0 RIC01520 RIC01530 RIC01540 RICO1550 RIC01560 RIC01570 RIC01580 RIC01590 RIC01600 RIC01610 RIC01620 RIC01630 RIC0 1640 RIC01650 -55- RICCND 4 WORK (1) =COND C C 44400 TTRANSFORM BACK TO GET THE CLOSED LOOP SPECTRUM C DO 110 I=1,N IF (ITYPE(I).GE.0) GO TO 90 WRITE (6,t44400) I FORMAT (lX, I4, X,41HHTH EIGENVALUE NOT SUCCESSFULLY CALCULATED) RETUJRN 90 100 110 RIC0174O IF (ITYPE (T).GT.0) GO TO 100 ER (I) =ALPHA* ( . OD-ER (I ))/(1. ODO+ER (I)) EI (I) =0.OD0 GO TO 110 IF (ITYPE(I).EQ.2) GO TO 110 T=ALPHA/ ((1. ODO+ER (I)) **2+El (I) **2) ER (I)= (1. ODO-ER (I) **2-EI (i) **2) *T EI (I) =-2. ODO*EI (I) *T ER (I+1) =ER(I) El (I + 1)=-EI (I) CONTINU E RETURN RIC 1750 RIC01760 RIC01770 RIC01780 RIC01790 RIC01800 RIC018 s RIC01820 RIC01830 RICO 1840 RIC01 850 RICO 1860 LAST LINE OF RICCND RIC01880 RIC01890 RIC01900 g C C RIC0 1660 RIC01 670 RIC01680 RIC01690 RICO1700 RIC01710 RIC01720 RIC01730 RIC0t870 END RICDSD 1 -56- SU;i3ROUTINE RICDSD + C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C c C C C C C C C C C C C C (N ,NFNGNH,N, NN,Z,,F,G,H,EElEI,WORK, SCALE, ITYPE, IPVT) *****P ARAETERS: INTEGER NZ,NF,NG,NH N,NNITYPE (NN),IPVT(N) DOUBLE PRECISION Z(.NZ,NN),W(NZ,NN),F(NF, N),G(NG,N),H(NH,N) , ER (NN) ,EI(NN) ,WORK (N) ,SCALE (NN) + VARIABLES: *****LOCAL INTEGER I,J,K,LOW,IGH,NLOW,NUP DOUBLE PRECISION EPS,EPSP1,CCNDCON NDP1 **$***SUBlROUTINES CALLED: BALANC, BALBAK,DDCOMP,DSOLVE, IQR3,MLINEQ,MULWOA,,MULWOB, ORTHES,ORTRAN :::::-:::: ..... : ::::':::::. .:::: RICOOO1( RIC0002( RIC0003( RIC 0004( RIC0005( RIC0006( RIC0007( RICOO08( RICO09( RICOa O( RIC0011( RIC0012( RICO 13( RICOO 14( R IC00 15( RIC00!6( :': ::::'::''::* RICO017( RICo018( RIC00 19( *****PURPOSE: RICOO20( THIS DOUBLE PRECISION SUBROUTINE SOLVES THE DISCRETE-TIME RIC002V1 ALGEBRAIC MATRIX RICCATI EQUATION RIC0022( RIC0023( T -1 T T T RIC0024( )*G1 *X*F + H X = F *X*F - F *X*GI*((G2 + G1 *X*G1) RIC0025( RIC0026( BY LAUB S VARIANT OF THE HAMILTONIAN-EIGENVECTOR APPROACH. Gl AND RIC0027i MATRICES AND THE THE MATRIX F IS ASSUMIED TO BE NONSINGULAR G2 ARE ASSUMED TO BE COMBINED INTO THE SQUARE ARRAY G AS FOLLOWS: RIC0028( R IC0029( -1 T RICOO 30{ *G1 G = G1*G2 RIC0031 RIC00321 *****PARAMETER DESCRIPTION: RIC0033( ON INPUT: RIC00341 RICOO35( CONTAINING THE ARRAYS OF DIMENSIONS ROW NZ,NF,NG,NH RIC00364 Z (AND W),F,G, AND H, RESPECTIVELY, AS RIC0037( DECLARED IN THE CALLING PROGRAM DIMENSION RIC0038 STATEMENT; RICO 391 RIC0040( F,G,H; MATRICES THE OF ORDER N RIC004! RICi042{ - 2*N = ORDER OF THE INTERNALLY GENERATED NN RIC0043! MATRICES Z AND W; RICO04 4 RIC0045( A NONSINGULAR N X N (REAL) MATRIX; F RIC001 46~ RIC0047t N X N SYMMETRIC, NONNEGATIVE DEFINITE G,H RICO0048i (REAL) MATRICES. RIC0049 R'IC 005O ON OUTPUT: RIC0051{ AN N X N ARRAY CONTAINING TH.E UNIQUE POSITIVE RIC052! H RIC00534 (OR NONNEGATIVE) DEFINITE SOLUTION OF THE RIC0054i RICCATI EQUATION; RIC0055( -57- C C C C C C EREI RICDSD 2 REAL SCRATCH VECTORS OF LENGTH 2*N; ON OUTPUT RIC00561 (ER (I) ,EI (1)), I= 1,N CONTAIN THE REAL AND RICCO57i IMAGINARY PARTS, RESPECTIVELY, OF THE N RIC005W8 CLOSED LOOP EIGENVALUES (I.E., THE RIC00591 SPECTRUM OF T -1 T RICO060( F - G* ((G2 + Gl *X*Gt) )*G1 *X*FRIC0061i C C -T = C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C F - G*F *(X - RIC0062( RIC00631 H)); Z,W 2*N X 2*N REAL SCRATCH ARRAYS USED FOR COMPUTATIONS INVOLVING THE SYMPLECTIC MATRIX ASSOCIATED WITH THE RICCATI EQUATION; WORK,SCALE REAL SCRATCH VECTORS OF LENGTHS N, 2*N, RESPECTIVELY; ON OUTPUT, WORK(1) CONTAINS A CONDITION NUMBER ESTIMATE FOR THE FINAL NTH ORDER LINEAR MATRIX EQUATION SOLVED; ITYPE,IPVT INTEGER SCRATCH VECTORS OF LENGTHS 2*N, RESPECTIVELY. ***NOTE: N, ALL SCRATCH ARRAYS MUST BE DECLARED AND INCLUDED IN THE CALL.*** *****ALGORITHM NOTES: IT IS ASSUMED THAT: (1) F IS NONSINGULAR (2) G AND I ARE NONNEGATIVE DEFINITE (3) (F,GI) IS STABILIZABLE AND (C,F) IS DETECTABLE WHERE T C *C = H (C OF FULL bANK = RANK(H)) . RICOO86i UNDER THESE ASSUMPTIONS THE SOLUTION (RETURNED IN THE ARRAY H) IS RICO087( UNIQUE AND NONNEGATIVE DEFINITE. RIC00881 RIC0089( *****HISTORY: RfIC0090( WRITTEN BY ALAN J. LAUB (ELEC. SYS. LAB., M.I.T., RM. 35-331, RIC0091( CAMBRIDGE, MA 02139, PH.: (617) - 253-2125), SEPTEMBER 1977. RICOO92< MOST RECENT VERSION: SEP. 15, 1978. RIC0093i R IC0094f C :-:::'::: C C C C C C EPS IS AN INTERNALLY GENERATED MACHINE DEPENDENT PARAMETER SPECIFYING THE RELATIVE PRECISION OF FLOATING POINT ARITHMETIC. FOR EXAMIPLE, EPS 1= 6.ODO**(-13) FOR DOUBLE PRECISION ARITHMETIC ON IBM S360/5370. 5 C C C RIC0064I RIC0065{ RIC0066t RIC00671 RIC0068S RIC0069( BIC0703 IRICOO71( RIC0072i RIC00731 RIC007L4 RIC0075S RIC0076t RICO0077i RIC0078{ RIC0079i RIC080( RIC0081: RICO082( RIC0083( RIC0084{ RIC0085{ :: ..... :.:**: EPS= 1. DO -EiPS=0.5D0*EPS EPSP1=EPS+ 1 0D0 IF (EPSPl.GT. 1.ODO) EPS=2.ODO*EPS .: ::::.>::::::::: GO TO 5 SET UP SYMPLECTIC MATRIX Z DO 20 J=1,N RIC0096 RIC0097( RIC0098! RICOO99t RICO100I RICO10 1t RIC010 2{ RICO0103 RIC104( RICO01051 RIC0106i RIC0 107 RICO1083 RICO10 9g RICO11O1 -58- DO 10 I=1,N z (N+I , N+J) =- (J,I) 10 CONTINUE 20 CONTI NUE CALL DDCOMP (NF, N,F,COND,IPVT, WO K) CONDP I=COND+ 1. ODO IF (C0NDt1. GT.COND) GO TO 30 WRITE (6,44400) 44400 FORMAT (42H1F MATRIX IS SINGULAR TO WORKING RETURN 30 DO 60 J=1,N DO 40 I=1,N WORK {I) =0. ODO 40 CONTINUE WORK (J)=1.ODO CALL DSOLVE (NF, N,F, WORK,IPVT) DO 50 I=1,N z (I,J) =WORK (I) 50 CONTINUE 60 CONTINU E DO 80 J=1,N DO 70 I=1,N F (I ,J) =Z (I ,J) 70 CO NTINUE 80 CONTINUE CALL MULWOA (NHNF,N,H,F,WORK) DO 120 J-1,N DO 90 I=1,N Z (I,N+J)=0. ODO RICDSD 3 PRECISION) z (N+I,J)=H (I,J) 90 100 110 120 130 140 C C C CONTINUE DO 110 K=1,N DO 100 I=1,N +F (I,K)*G (K,J) Z (I,N+J)=Z (t,N+J) CONTINUE CONTINUE CONTINUE CALL .BLULWOB (NH,NG, N, H, G, WORK) DO 140 J=l,N DO 130 I=1,N Z (N+I, N+J) =Z (N+I, N+J) +G (I,J) CONTINUE CONTINUE BALANCE Z CALL C C C C BALBAANC (NZ,NN,Z,LOW,IGH,SCALE) REDUCE Z TO REAL SCHUR FORM WITH EIGENVALUES OUTSIDE THE UNIT DISK IN THE UPPER LEFT N X N UPPER QUASI-TRIANGULAR BLOCK NLOW=l NUP=NN CALL ORTHES CALL ORTRAN (NZ,NN,NLOW,NUP,Z,ER) (NZ,NN, NLOW,NUP,Z,ER,W) RICOl111t RICO1 12i RICOI1 3 RIC01141 RIC0 1 5 RICO 1 t16 RICO 17i RICO 1 18( RICO1019 RIC1 20( RIC0121! RIC0322i RICO123i RIC01294 RIC01251 RIC01261 RICO 127( RIC01281 RICO 129( RI C01 3 01 RIC0131( RIC01321 RIC01331 PIC0134( RIC0135{ RIC0 36( RICO137( RIC0138( RICO 139 RI CO140( RICO0141 RICO 142 RIC0143i RIC0 1O44 RIC01451 RIC01461 RICO 147( RIC0!48{1 RIC0149( RICO1501 RICO 15 1 RIC01 521{ RIC0153( RIC01541 RIC0155O RICO156 RICO 1571 RICO 158{ RIC01591 RIC0160( RICOI6 1 RIC01621 RIC0163i RIC01641 RICO 165( -59- CALL HQR3 C C C C 150 160 C C C RICDSD 4 (Z,,NN,NLOW,NUP,EPS,ER,EI, ITYPE, NZ,NZ) COMPUTE SOLUTION OF THE RICCATI EQUATION FROM THE ORTHOGONAL MATRIX NOW IN THE ARRAY W. STORE THE RESULT IN THE ARRAY H. CALL BALBAK (NZ,NN,LOW,IGH,SCALE,NN,W) DO 160 J=1,N DO 150 I=1,N F (I, J) W (J, I) H (I ,J)=W (N+J,I) CONTINUE CONTINUE CALL MLINEQ (NF,NH,N,N,FH,COND,IPVT,WORK) WORK (1) =COND TRANSFORM TO GET THE CLOSED LOOP SPECTRUM 190 I1t,N IF (ITYPE(I) .GE.0) GG TO 170 WRITE (6,44410) I 44410 FORMAT (lX,I4,IX,41HTH EIGENVALUE RETURN 170 IF (ITYPE(I).GT. ) GO TO 180 ER (I) = 1. O0D0/ER (I) EI ({) =0. ODO GO TO 190 180 IF ({ITYPE(I). EQe.2) GO TO 190 T=ER (1) **2+EI (I) **2 ER (I)= ER (I)/T EI (I) =EI (I) /T ER (I+ 1) - ER (I) EI (I+1) =-EI) I 190 CONTINUE RETU RN C C LAST LINE OF RICDSD C END DO NOT SUCCESSFULLY CALCULATED) RIC0166 RI C0 1671 RICO168i RIC01691 RIC0170O RIC0171i RIC0172i RIC0173i RICO 1741 R C01 75. RIC0O 176 RIC0177i RIC0178{ RC0179 RICO 180( RIC0181I RICOt821 RIC0183I RIC0184( RIC 085( RIC0186 RIC0187( RIC01881 RICO 189( RICO 901 RIC01911 RIC0192( RIC0193L RIC 194( RIC0195i RICO 196( RIC01 97 RIC 198( RIC0 99{ RIC0200( RIC020 1( RIC0202{ RICO0203( -60- DDCOMP 1 C DDC000 10 DDC00020 DDC00030 DDC0040 DDC00050 DDC00060 DDC00070 DDC00080 DDC00090 DDC00 100 DDC00 110 DDC00120 DDC00130 C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C DDC00 150 DDCOO160 *****PURPOSE: N DDC00170 N X THE REAL OF THIS SUBROUTINE CCMPUTES AN LU-DECOMPOSITION DDC00180 MATRIX A BY GAUSSIAN ELIMINATION WITH PARTIAL PIVOTING. DDC00190 A IS ESTIMATED. A CONDITION NUMBER OF DDC00200 DDC O0210 DESCRIPTION: *****PARAMETER DDC00220 ON INPUT: DDC00230 DDC00240 ROW DIMENSION OF THE ARRAY CONTAIN-ING A AS NA DDC00250 DiECLARED IN THE CALLING PROGRAM DIMENSION DDC00260 STATEMENT; DDC00270 DDC00280 ORDER OF THE MATRIX; N DDC00290 DDC00300 N X N MATRIX TO BE TRIANGULARIZED. A DDC00310 DDCO 3 20 ON OUTPUT: DDC00330 DDCO00340 N X N ARRAY CONTAINING AN UPPER TRIANGULAR A DDC00350 MATRIX U AND A PERMUTED VERSION OF A LOWER DDC00360 TRIANGULAR MATRIX I-L SO THAT DDC00370 (PERMUTATION MATRIX)*A = L*U. DDC00380 DDC00390 AN ESTIMATE OF THE CONDITION OF A FOR THE COND DDC00400 LINEAR SYSTEM DDC-00410 A*X = B. DDC00420 CHANGES IN A AND B MAY CAUSE CHANGES COND IF COND + 1.ODO = COND,DDC00430 TIMES AS LARGE IN X. DDC00440 COND IS A IS SINGULAR TO WORKING PRECISION. DDCOO450 SET TO 1.OD+32 IF "EXACT" SINGULARITY IS DDC00460 DETECTED. DDC00470 DDC00480 PIVOT VECTOR CF LENGTH N. IPVT D3DC0490 IPVT(K) = THE INDEX OF THE K-TH PIVOT ROW. DDC00500 IPVT (N) = (-l)**(NUMBER OF INTERCHANGES). DDCOO510 DDCOO520 REAL SCRATCH VECTOR OF LENGTH N. WORK DDC005S30 ITS OUTPUT ITS INPUT CONTENTS ARE IGNORED. DDC00540 CONTENTS ARE USUALLY UNIMPORTANT. DDC00550 SUBROUTINE DDCOMP C C C C (NA,N,A,CONL, IPVT,WORK) *****PA RA ETERS: INTEGER NA, N,IPVT(N) DOUBLE PRECISION A(NA,N) COND,WORK(N) *****LOCAL VARIABLES: INTEGER NM1,.I,J,K, P1,KB,KM1,M DOUBLE PRECISION EK,T, ANORM,YNORM,ZNORM C **'***FUNCTIONS: DOUBLE PRECISION DABS -61- C C C C C C C C C C C C C C C C C C C C C C C C C C C C C::::::::: C C C C 5 10 C C C C C C DDCOMP 2 *****APPLICATIONS AND USAGE RESTEICTIONS: DDC00560 DDCOMP CAN BE USED IN CONJUNCTION WITH DSOLVE TO COMPUTE SOLUTIONSDDC00570 TO SYSTEMS OF LINEAR EQUATIONS. IF NEAEi-SINGULARITY IS DDC00580 DETECTED SOLUTIONS ARE MORE RELIABLY COMPUTED VIA SINGULAR DDC0590 VALUE DECOMPOSITION OF A. DDC00600 DDCOMP CAN ALSO BE USED TO COMPUTE THE DETERMINANT OF A. DDC00610 ON OUTPUT SIMPLY COMPUTE: DDCOO620 DET (A) = I PVT (N) *A (1, 1) A (2 ,2) . . .A (N,N) DDC06 30 DDC00640 *****ALGORITHM NOTES: DDC00650 DDCOMP IS A DOUBLE PRECISION ADAPTATION OF THE SUBROUTINE DECOMP DDC00660 (SEE REFEERENCE (1) FOR DETAILS). THIS ALGORITHM IMPLEMENTS DDC00670 GAUSSIAN ELIMINATION IN A MODERATELY UNCONVENTIONAL MANNER DDC00680 TO PROVIDE POTENTIAL EFFICIENCY ADVANTAGES UNDER CERTAIN DDC00690 OPZERATING SYSTEMS (SEE REFERENCE (2) FOR DETAILS). DDCO0700 DDC007 10 *****jEFERENCES: DDC00720 (1) FORSYTHE,G.E., MALCOLM,M.A., AND MOLER,C.B., COMPUTER DDC00730 METHODS FOR MATHEMATICAL COMPUTATIONS, PRENTICE-HALL, 1977. DDC00740 (2) MOLER,C.B., MATRIX COMPUTATIONS VITH FORTRAN AND PAGING, DDC00750 COMM. ACM, 15(1972), 268-270. DDC00760 DDC00770 *****HISTORY: DDC00780 ADAPTATION AND DOCUMENTATION WRITTEN BY ALAN J. LAUB DDC00790 (ELEC. SYS. LAB., M.I.T., RM. 35-331, CAMBRIDGE, MA 02139, DDC00800 PH.: (617)-253-2125), AUGUST 1977. DDC0810 MOST RECENT VERSION: SEP. 21, 1977. DDC00820 DDC00 830 :::::::::::::::::::::':: :::'::.::.:.::::::::DDC0840 DDC00850 IPVT (N) = 1 DDC00860 IF (N.EQ 1) GO TO 80 DDC 00870 N 1t=N- 1 DDC00880 DDC0O890 COHPUTE 1-NORM OF A DDCO900 DDC0910 ANORM=. ODO DDCO0920 DO 10 J=1,N DDC00930 T=. ODO DDC00940 DO 5 I=1,N DDC00950 T=T +DABS (a (i,J)) DDC00960 CONTINUE DDC00970 IF (T. GT.ANORM) ANOR1=T DDC00980 CONTINUE DDC00990 DDC01000 GAUSSIAN ELIMINATION WITH PARTIAL PIVOTING DDC01010 DDC0 1020 DO 35 K=1,NM DDC01 030 KP1=K+ 1 DDC010 40 DDC0105 FIND PIVOT DDC01060 'DDC01070 M=K DDC01 080 DO 15 I=KP1,N DDC01090 IF (DABS(A(I,K)).GT. DABS (A(M,K) )) M=I DDC01100 -62- 15 C C C CONTINUE IPVT (K) =M IF (M. NE.NK) IPVT (N) =-IPVT (N) T= A (M,K) A (M,K) =A (K, K) A (K, K) =T SKIP STEP IF PIVOT IS ZERO IF C C C (T.EQ.0.0D0) GO TO 35 COMPUTE MULTIPLIERS DO 20 20 C C C 25 30 35 C C C C C C C C C C C C 40 45 50 I=KP1,N A (I ,K) =-A (I, K)/T CONTIN UE INTERCHANGE AND ELIMINATE BY COLUMNS DO 30 J=KP1,N T=A (M,J) A (M,J)=A (K,J) A (K,J)=T IF (T.EQ.0.ODO) GO TO 30 DO 25 I=KPl,N A (I J) A (I,J) +A (I, K) *T CONTIN UE CON T.fN UE CONTINUE COND = (1-NORM OF A)*(AN ESTIMATE OF 1-NORM OF A-INVERSE). ESTIMATE OBTAINED BY ONE STEP OF INVERSE ITERATION FOR THE SMALL SINGULAR VECTOE. THIS INVOLVES SOLVING TWO SYSTEMS T WHERE L AND A*Z = Y OF EQUATIONS: A *Y = E IS A VECTOR OF +1 OR -1 CHOSEN TO CAUSE GROWTH IN Y. ESTIMATE = (1-NORM OF Z)/(1-NCRM OF Y). T SOLVE A *Y = E DO 50 K=1,N T=0.0DO IF (K.EQ. ) GO TO 45 KM 1=K-1 DO 40 I=1,KM1 T=T +A (I, K) *WORK (I) CONTINUE EK=. 0DO IF (T..LT. .ODO) EK=- .0ODO IF {A K,K)..EQ.0.ODO) GO TO 90 WORK (K) =- (EK+T) /A (K,K) CON TIN U DO 60 KB=1,NM1 K=N- K B DDCOMP 3 DDC01110 DDC01120 DDCO1 130 DDCO 1140 DDC01 150 DDCO 1 t60 DDC i 170 DDC01180 DDC01190 DDC01200 DDC01210 D DC 01220 )DDC01230 DDC01240 DDC01250 DDC01260 DDC01270 DDC01280 DDC01290 DDC01300 DDC013 10 DDC0 1320 DDC 1330 DDC01 340 DDC01350 DDC01.360 DDC0 1370 DDCO 138 0 DDC01390 DDC01400 DDC01410 DDCO1420 DDC01430 DDC01440 DDC01450 DDCO1460 DDC01470 DDC0 480 DDC01490 DDC01500 DDC01510 DDC01520 DDC01530 DDC 0540 DDC01 550 DDC01560 DDC0 5 70 DDC01580 DDC01590 DDC01600 DDC01610 DDC 1620 DDC01630 DDC01640 DDC01650 -63- 55 60 C 65 C C C T=O0.00 KP?1K+1 DO 55 I=KP1,N T=T +A (I, K) *WORK (K) CONTINUE WORK (K)=T M=IPVT (K) GO TO 60 (M.EQ.K) IF T=WORK (M) WORK (M)= WORK (K) WORK(K)=T CONTINUE YNORM=O.ODO DO 65 rI = ,N YNOR M=YNOBR+DABS (WORK (I) CONTINUE SOLVE A*Z CALL DSOLVE Y (NA,N,A,WORK,IPVT) C 70 C C C ZNOR=0. ODO DO 70 I=1,N ZNORM=ZNOih+DABS (WORK (I)) CONTINUE ESTIMATE CONDITION COND=A NORM*ZNORM/YNOR1 IF (COND.LT.t.ODO) COND=1.ODO RETURN C C C 80 C C C 90 C C C 1-BY-1 CASE COND=1.ODO IF (A (1, 1).NE. 0.0 DO) "EXACT" SINGULARITY CoND=1.0D+32 RETURN LAST END LINE OF DDCOMP RETURN DDCOMP 4 DDC01 660 DDC01670 DDC0680 DDC01690 DDC01700 DDC017 10 DDC 01720 DDC017 30 DDC01740 DDCO17 50 DDC01760 DDC01770 DDC0 780 DDC01790 DDC01800 DDC0 180 DDC0 1820 DDC01830 DDC 01840 DDC01850 DDC01860 DDC01870 DDC01880 DDC01890 DDC01900 DDC01910 DDC01920 DDC01930 DDC01940 DDC019 50 DDC01960 ODC01970 DDC01980 DDC01990 DDC02000 DDC02010 DDC02020 DDC02030 DDC020L40 DDC02050 DDC02060 DDC02070 DDC02080 DDC02090 DDCO2100 DDC02110 -64- SUBROUTINE DSOLVE c C C C (NA,N,A,B,IPVT) ***** PAAME TER S: INTEGER NA, N,IPVT(N) DOUBLE PRECISION A(NA,N) ,B(N) :@'X***'**LOCAL VARIABLES: iNTEGER KB,KM1,NM1,KP1,I,K,M DOUBLE PRECISION T C C C C C C CC C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C DSOLVE 1 DS0001( DSC0002{ DS00003( DSO000O4( DSO0005C DS00006( DS00007( DSO0008( DSO0009( DS0 t0( DS00012( DSO00 13( DSO0014( DSC0015( D3SO0016( DS000 17( *c****PARAlifETER DESCRIPTION: DS(00 18( ON INPUT: DSC001 9( DSO0020( NA ROW DIMENSION OF THE ARRAY CONTAINING A DSO0021( AS DECLARED IN THE CALLING PROGRAM DIMENSION DSO0022( STATEMENT; DSO0023( DS00024( N ORDER OF THE MATRIX A; DS00025( DS 0026 A TRIANGULARIZED MATRIX OBTAINED FROM DDCOMP; DSO00027 DS00028( B RIGH'T¢' HAND SIDE VECTOR OF LENGTH N; DS00029( DS00030(O IPVT PIVOT VECTOR OF LENGTH N OBTAINED FROM DDCOMP.DSO0031( DS00032( ON OUTPUT: DS00033( DS00034( B SOLUTION VECTOR, X, OF LENGTH N. DSO0035( DS00036C *****APPLICATIONS AND USAGE RESTRICTIONS: DS00037( DSOLVE SHOULD NOT BE USED IN CASE DDCOMP HAS DETECTED NEARDS00038( SINGULARITY. SINGULAR VALUE ANALYSIS IS THEN MORE RELIABLE. DS00039( DSO0040( **8***ALGORITHM NOTES: DS00041( DSOLVE IS A DOUBLE PRECISION ADAPTATION OF THE SUBROUTINE SOLVE DS00042( (SEE REFERENCE (1) IN THE DDCOMP DOCUMENTATION FOR DETAILS). DSO0043( DS00-44( *****HISTORY: DSO0045( ADAPTATION AND DCCUMENTATION WRITTEN BY ALAN J. LAUB DSO0046( (ELEC. SYS. LAB., M.1.T., RM. 35-331, CAMBRIDGE, MA 02139, DS00047( PH.: (617)-253-2125), AUGUST 1977. DSO0048 MOST RECENT VERSION: SEP. 21, 1977. DSO0049( DSO00050( *****PURPOS E THIS SUBROUTINE SOLVES THE LINEAR SYSTEM A*X = B BY FORWARD ELIMINATION AND BACK SUBSTITUTION USING THE TRIANGULAR FACTORS OF A PROVIDED BY DDCOMP C =:=::.:.::,:::::::4::::::::::::::::::::::::::::::::::::::::::::::::::::::::::5 C C C FOR-WARD IF ELIMINATION (N.EQ.1) GO TO 50 DS00052( DS00053( DSO0054( DS00055( -65- 10 20 C C C 30 40 50 C C C NM 1=N- 1 DO 20 K=1,NM1 KP1=K+1 M-=IPVT (K) T=B (M) B(M) = B (K) B (K) =T DO 10 I=KP1,N 13 (I)=B (I)+A (I,K) *T CONTINUE CONTINUE BACK SUBSTITUTION DO 40 KB=1,NM1 KM1=N-KB K=KM1+1 B (K) =B(K)/A (K,K) T=-B (K) DO 30 I=1,Kfll B (I) -B (1) +A (I, CONTINUE CONTINUE B (1) =B (1) /A (1,1) RETURN LAST END LINE OF DSOLVE K) *T DSOLVE 2 DS00056( DS0057( DSOO0058( DS00059( DSO00601 DS00061( DSO006-2 DS00063( DSOOO64( DS00065( DSO0066( DSO0067{ DS00068( DS©00698 DS00701 DSO007t1 DSO0072( DS00073( DS00074( DKS0t75( DS00076( DS00077( DS00078( Ds1007ts Ds0080( DS00O10( DS00082( DS00083( DSO0084( -66- S'JBEOUTINE EXCHNG C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C EXCHNG 1 (A,V,N,L, B1,B2,EPS,FAIL,NA,NV) EXCO0010 EXC000 20 EXCO0030 E XC00040 EXC0050 EXC00060 EXCc0070 EC000oso EXCOO0090 EXC00100 EXC00 10 EXC0o120 EXC0130 EXCO0 140 EXC0050 EXC0 160 EXC00170 a***** AARAET ER S INTEGER B1,B2,L,NA,NV DOUBLE PRECISION A(NA,N),EPS,V(NV,N) LOGICAL FAIL *****LOCAL VARIABLES: INTEGEA I,IT,J,L1,M DOUBLE PRECISION PQRS,W,X,Y,Z *****FUNCTIONS: DOUBLE PRECISION DABS,DSQRT,DMAX1 *****SUBROUTINES CALLED: QESTEP e EXC00190 E XC0200 EXCO0210 EXC00220 EXCO0230 EXC00240 EXCO0250 EXC00260 *****PARAMETER DESCRIPTION: EXC00270 ON INPUT: EXCO00280 NA,NV ROW DIMENSIONS OF THE ARRAYS CONTAINING A EXC00290 AND V, RESPECTIVELY, AS DECLARED IN THE EXCO0300 CALLING PROGRAM DIMENSION STATEMENT; EXC00310 EXCOt.32C A N X N MATRIX WHOSE BLOCKS ARE TO BE EXC0330 INTERCHANGED; EXC00340 EXC0O350 N ORDER OF THE MATRIX A; EXC00360 EXC00370 L POSITION OF THE BLOCKS; EXC00380 EXC00390 B1 AN INTEGER CONTAINING THE SIZE OF THE FIRST EXC00400 BLOCK; EXCO0410 EXCO042C B2 AN INTEGER CONTAINING THE SIZE OF THE SECOND EXC00430 BLOCK; EXCOO44C EXC0045C EPS A CONVERGENCE CRITERION (CF. HQR3). EXC00460 EXC0047C ON OUTPUT: EXCO0480 EXCO0049C FAIL A LOGICAL VARIABLE WHICH IS .FALSE. ON A EXC00500 NORMAL RETURN. IF THIRTY ITERATIONS WERE EXC0051C PERFORMED WITHOUT CONVERGENCE, FAIL IS SET TO EXCO0520 .TRUE. AND THE ELEMENT A(I.+B2,L+B2-1) CANNOT EXCO053C Bt ASSUMED ZERO. EXCOS04C EXC055C *****PUR POSE: GIVEN THE UPPER HESSENBERG MATRIX A WITH CONSECUTIVE Bl X B1 AND B2 X B2 DIAGONAL BLOCKS (B1, B2.LE.2) STARTING AT A(L,L), THIS SUBROUTINE PRODUCES A UNITARY SIMILARITY TRANSFORMATION THAT EXCHAN;GES THE BLOCKS ALONG WITH THEIR EIGENVALUES. THE TRANSFORMATION IS ACCUMULATED IN V. -67- C C C C C C C 10 20 30 40 50 60 EXCHNG 2 **** HISTOR Y: DOCUŽMENTED BY J.A.K. CARRIG (ELEC. SYS. LAB., M.I.T., RM. 35-307, CAMBRIDGE, MA 02139, PH.: (617) - 253-2165, SEPTEMBER 1978. MOST RECENT VERSION: SEPT. 21, 1978. : FAIL= . FALSE. IF (Bl.'Q.2) GO TO 70 IF (B2.EQ.2) GO TO 40 L t=L+ 1 Q=A (L+ ,L+1 ) -A (L,L) P=A (L, L 1) E=DMAX1 (P,Q) (R.EQ.0.0 .F DO) RETURN P=P/R Q=Q/R R=DSQhT (P**2+Q ** 2) P =P/R Q=Q/E DO 10 J=L,N S=P*A(L,J) +Q*A(L+1,J) A (L+1,J)=P*A (L+ 1,J)-Q*A(L,J) A (L,J)=S CONTINUE DO 20 =1I,Ll S-=P*A (, L)+Q*A (I,L+1) A (I,L+1)=P*A (I,L+l)-Q*A(I,.L) A (I,L)=S CONTINUE DO 30 I=1,N S=P*V(, L) +Q*V (I,L+1) v (I ,L+) =P*V (I,.L+1) -Q*V (I,L) V (I,L) =S CO NTINJ E A (L+ 1,L) =0. ODO RETURN CONTINUE X=A (L,L) P=1. ODO Q=l1.ODO -= .ODO CALL QRSTEP (A,V,P,Q,R,L,L+2,N, NA,NV) IT =0 IT=IT+1 IF (IT.LE.30) GO TO 60 FAIL=. TRUE. RETURN CONTINUE P=A (L,L)-X Q=A (L-+1 ,L) R=O.ODO CALL QRSTEP (A,V,P,Q,R,L,L+2,N,NA,NV) IF (DAt3S(A(L+2,L+1)) .GT.EPS*(DABS(A(L+1,L+1))+DABS(A{L+2,L+2)))) + GO TO 50 EXC 0056C EXC00570 EXCOO58C EXC059C EXCO060C XCOO::::: EXCO062C EXCOO63 EXC00640 EXC0065C EXCO0660 EXC0067C EXCO 680 EXCO0690 EXC00700 EXCO0710 EXCO0720 EXCO0730 EXCOO74O EXCO0750 EXCO0760 EXCO0770 EXCO0780 EXCO0790 EXCOO800 EXCO0810 EXC0820 EXCOO03C EXCO840 EXC0085C EXC00860 EXC00870 EXCO0880 EXC00890 EXC 0900 EXCO09 10 EXCO0920 EXCO0930 EXCOQ940 EXCO0950 EXCO0960 EXCO0970 EXC00980 EXC00990 EXCO 1000 EXC 01010 EXCO 10 20 EXCO1030 EXCO1040 EXCO1050 EXCO1060 EXCO1070 EXC01080 EXC01090 EXCO1t00 -68- 70 80 90 C C C EXCHNG 3 A (Lf 2,L+1) =0.ODO RETURN CO NTINUE M= L+2 IF (B2.EQ.2) Mi=M+1 X=A (L+I,L+1) Y=A (L,L) W=A (L+1,L) *A (L,L+l) P= 1. ODO Q=1.ODO R=1.ODO CALL QRSTEP (A,V,P,Q,R,L,IIN,NA,NV) I1=0 IT=IT+1 IF (IT.LE.30) GO TO 90 FAIL=. TRUE. RETURN CONTINUE Z=A (L,L) R=X-Z S=Y-Z P= (Rf'*S-W) /A (L+ 1L) +A (L,L+l) Q=A (L+ 1,L+1)-Z-R-S R=A (L+2,t L+) S=DABS (P) +DABS (Q) +DABS (R) P=P/S Q=Q/S R=P/S CALL QRSTEP (A,V,P,Q,R,L,M,N,NA,NV) If (DABS (A (M-1,M-2)) .GT.EPS* (DABS (A (M-1,M-1)) +DABS(A (M-2,M-2)) ) ) + GO TO 80 A (Pi- 1,M-2) =0.0D0 RETUR N LAST LINE OF EXCHNG END EXCO 1 t10 EXC0 1120 EXCO 1130 E XC0 1140 O EXCO 150 EXCO1160 EXCO1170 EXC01180 EXCO1290 EXCO1200 EXCO1210 EXCO 220 EXC01230 EXC01240 EXC01250 EXCO 1260 EXCO 1270 EXC01280 EXC01290 EXC01300 EXC01310 EXC0 1320 EXC01330 EXCO1340 EXC 1 3 50 EXC01360 EXC01370 EXCO1380 EXCO1390O EXC1400 EXC01410 EXC01420 EXC01430 EXC01440 EXC01450 EXCO1460 EXCO0470 -69- SUBROUTINE HQR3 C C C C C C (A,V,N,NLOW, NUP,EPS,EREI,ITYPE,NA,NV) *****PARAMETERS: INTEGER N,NA,NLOW,NUP, NV,ITYPE (N) DOUBLE PRECISION A(NA,N),EI(N),E (N),EPS,V(NV,N) *****LOCAL VARIABLES: LOGICAL FAIL INTEGER I,IT,L,&U, NL, U DOUBLE PRECISION Et,E2,P,Q,R,S,T,W,X,Y,Z *****FUNCTIONS: DOUBLEZ PRECISION DABS HQR3 1 HQR0001( HQR0002( HQR0003( HQR0004( HQROOO05( HQR0006( HQR0007C HQR0008( HQR0009( HQROO1 0( HQRO0 1 1( HQR 0012( HQRO0013( HQR00'14( HQR0015( HQR0016( HQR00 17( C C C C ***$**SUBROUTINES CALLED: EXCHNG, QRSTEP, SPLIT C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C HQR001 9 HQRO 20( *****PURPOSE: HQeOO21( A TO QUASIMATRIX HESSENBERG THIS SUBROUTINE REDUCES THE UPPER HQR0022( THE TRIANGULAR FORM BY UNITARY SIMILARITY TRANSFORMATIONS. liQROO23( 2 2 X X 1 AND THE 1 EIGENVALUES OF A, WHICH ARE CCNTAINED IN HQR0024( IN DESCENDING ARE ORDERED DIAGONAL BLOCKS OF THE REDUCED MATRIX, HQR0025( ARE TRANSFORMATIONS THE ORDER OF MiAGNITUDE ALONG THE DIAGONAL. HQR 0026{ ACCUMULATED .iN THE ARRAY V. HQ R027( HQR0028( DESCRIPTION: *****PARAMETER HQR0029( ON iNPUT: HQR0030( A AND CONTAINING ARRAYS OF THE DIMENSIONS ROW NA,NV HQR0031( THE CALLING IN AS DECLARED V, RESPECTIVELY, H1QR0032{ STATEMENT; DIMENSION PROGRAM HQR0033( HQR0034( N X N ARRAY CONTAINING THE UPPER HESSENBERG A HQR0035( BE REDUCED; MATRIX TO HQR0036( HQR0037( ORDER OF THE MATRICES A AND V; N HQR 0038( fHQR0039( A(NLOW,NLOW-1) AND A(NUP,1+NUP) ARE ASSUMED NLOW,NUP HQR0040( TO BE ZERO, AND ONLY ROWS NLOW THROUGH NUP AND COLUMNS NLOW THROUGH NUP ARE TRANSFORMED, HQR004I1 HQE0042( RESULTING IN THE CALCULATION OF EIGENVALUES HQR00431 NLOW THROUGH NUP; HQRO04(4 A CONVERGENCE CRITERION USED TO DETERMINE WHENHQR0045 EPS HQR00461 A SUBDIAGONAL ELEMENT OF A IS NEGLIGIBLE. HQR0047 SPECIFICALLY, A (I+1,i) IS BEGAjRDED AS HQR0048i NEGLIGIBLE IF DABS(A (I+1),I)) .LE.EPS* (DABS (A (I+1,I+1))). THIS MEANS THAT THE FINAL HQ.R00i49 MATRIX RETURNED BY THE PROGRAM WILL BE EXACTLYHQE00503 HQRO05 1( SIMILAR TO A + E WHERE E IS OF ORDER FOR ANY REASONABLY BALANCED NORM HQR00521 EPS*NOEM (A), HQR0053( SUCH AS THE ROW-SUM NORM; H QR0054, HQR0055( AN INTEGER VECTOR OF LENGTH N WHOSE I LYPE -70- C C C C C C C C C C C C C C C C C C C C C C C C C C C C I-TH ENTRY IS 0 IF THE I-TH EIGENVALUE IS REAL, 1 IF THE I-TH EIGENVALUE IS COMPLEX WITH POSITIVE IMAGINARY PART, 2 IF THE I-TI EIGENVALUE IS COMPLEX WITH NEGATIVE IMAGINARY PART, -1 IF THE I-TH EIGENVALUE WAS NOT CALCULATED SUCCESSFULLY. HQR 0056 HQR0057i HQR0058t HQR00591 HQR0060( HQR00611 HQR0062( HQR0063( HQR0064L ON OUTPUT: HQR00651 HQR00661 A N X N ARRAY CCNTAINING THE REDUCED, QUASIHQR0067i TRIANGULAR MATRIX; HQR0068i HQR0069( V N X N ARRAY CCNTAINING THE REDUCING HQR0070I TRANSFORMATIONS TO BE MULTIPLIED; HQR0071( HQR0072{ ER, EI REAL SCRATCH VECTORS OF LENGTH N WHICH ON HQE0073( RETURN CONTAIN THE REAL AND IMAGINARY PARTS, HQE0074( RESPECTIVELY, OF THE EIGENVALUES. HQR0075{ HQR0076i *****HISTORY: HQR0O77( DOCUbENTED BY J.A.K. CARRIG, (ELEC. SYS. LAB., M.I.T., RN. 35-307,HQR0078( CAfBRIDGE, MA 02139, PH.: (617)- 253-2165), SEPT 1978. HQR0079t MOST RECENT VERSION: SEPT 21, 1978. HQR0080( HQR0081( : ... :::::: ::::::::::::::::::::::::::: :::Q082( HQR0083( DO 10 I=NLOW,NUP HQR0084( ITYP 10 20 30 40 50 60 HQR3 2 (I) =- 1 CONTINUE T=0.ODO NU=NU P IF (NU.LT.NLOW) GO TO 240 IT=O CONTINUE L=NU CONTINUE IF (L.EQ.NLOW) GO TO 50 IF (DABS (A (L,L-1 ) . LT. EPS* (DABS (A (L- 1,L-) ) +DABS (A (L,L) + GO TO 50 L=L- 1 GO TO 40 CONTINUE X=A (NU, NU) IF (L. EQ. NU) GO TO 160 Y=A (NU- 1 ,NU-1) W=A(NU, NU-1 ) *A (NU-1.NU) IF (L.EQ.NU-1) GO TO 100 IF (IT. EQ.30) GO TO 240 IF (IT.NE.10 .AND. IT.NE.20) GO TC 70 T=T+X DO 60 I=NLOW,NU A (I I) =A (I,I) -X CONTINUE HQR085( HQERO86( HQR0087( HQR0088( H QR0089( HQR0090i HQR009 1( HQR0092t HQR0-093( IIQR0094 )) HQR0095( HQR0096( HQR 0097( HQR0098( HQR0099{ HQR0100( HQR01 01( HQRO 10 2( HQRO1 03( HQROo104( HQR01O5( HQRO106( HQRO 107( HQRO108( HQRO 1 0 9 HQR0110( -71- 70 80 90 100 110 S=DABS (A (NU,NU-1)) +DABS(A (NU-1, NU-2)) X=0. 75DOS Y=X W=-O. 4375DO*S**2 CONTINUE HQ.R01111t HQR01 12( HQRO1 13( HQR01 14 HQR01 15( IT=IT+I HQR01161 NL=NU-2 CONTINUE Z=A (NL, NL) R=X-Z S=Y-Z P=(R*S-W)/ A(NL+1,NL) +A(NL,NL+1) S Q=A (NL+1 NL+ 1 ) -Z -R=A, { NL+ 2, NL+1) 1 S-DABS (P)+DABS (Q)+DABS (R) P=P/S Q=Q/S R=R/S IF (NL.EQ.L) GO TO 90 IF (DABS (A(NL,NL-1)) *(DABS(Q) +DABS(R)).LE.EPS*DABS(P)* + (DABS (A (NL-1,NL-1))+DABS () +DABS (A (NL+1 ,NL+1)))) GO TO 90 LNLL-1 GO TO 80 CONTINUE1 CALL QRSTEP (A,V,P,Q,R,NL,NUN,NA,NV) GO TO 30 IF (NU.NE.NLOW+1) A(NU- 1,NU-2)=0.ODO A (NU,NU) =A (NU, NU) +T A(NU-1, NU- ) -A (NU-1,NU-1) +T ITYPE (NU)= ITYPE (NU-1) = MU=NU CONTINUE NL=MU-1 CALL SPLIT (A,V,N,NL, EL,E2,NA,NV) IF (A(MU,MU-1).EQ. 0.ODO) GO TC 170 IF (14U.EQ.NUP) GO TO 230 IF (MU.EQ.NUP-1) GO TO 130 IF (A(MU+2, MU+1) .EQ.0.0D0) GO TO 130 .GE.A(1U+1,AiU+1)* UIF (A(U-1,MU-1)*A(MU,MU)-A(MiU-1,MU)*A(MU,MU-1) + A(aU+2,MU+2)-A(LIU+1,MU+2)*A(MU+2,MU+1)) GO TO 230 CALL EXCHNG (A,V,N,NL,2,2,EPS,FAIL,NA,NV) IF (.NOT.FAIL) GO TO 120 ITYPE (NL) =- i 120 130 HQR3 3 ITYPE (NL+1) =-1 ITYPE (NL+ 2) =- 1 ITYPE (NL+3) =-1 GO TO 240 CONTINUE MU=MU+2 GO TO 150 CONTINUE IF (A (MU-1,MU- 1) *A (MU,MU) -A (U- 1,MU) *A (MU, TU-1) .GEo + A( U+1,MU+1)**2) GO TO 230 CALL EXCHNG (A,V,N,NL,2,1,EPS,FAIL,NA,NV) HQR0117( HQ.l01 18{ HQEi0119{ HQ 0120( HQRO 121( HQR0122( HQR0123 HQ0 24( HQE0125( HQR0 126( HQR0127t HQ0R 128( HQR0 129( HQRE0130 HQReO131( HQRe0132f HQR0133( HQR01 34( HQr0135( HQR0136( HQ.1O 1 37( HQRO 1 38( aQRE01391 HQR0140( HQ R 0141( HQR0142( HQF 014 3( HQR0144( HQR0145( HQR0146( HQR0147( HIQRO1481 HQR0149i HQR0150( HQR0151( HQBO0152{ HQ.RO 153( HfQR0154( HQR0 1 55( QR0 156( HQOR01571 HQR0158( HQR01 59( HQR 160( HQE0161( HQR0162( HQR0163( HQR01644( HQR0165( -72- 140 150 160 170 180 190 200 210 220 230 240 250 260 270 280 HQR3 4 IF (.NOT.FAIL) GO TO 140 ITYPE (NL) =- 1 ITYPE (NL+1) -ITYPE (NL+2) -1 GO TO 240 CONTINUE MU=MU+ 1 CONTINUE GO TO 110 NL=O A (NU, NU) =A (NU,NU) +T IF (NU. NE.NLOW) A (NU,NU-1)=0. ODO ITYPE (NU)=0 tU=NU CONTINUE CONTINUE IF (MU. EQ NUP) GO TO 220 IF (MU.EQi.NUP-1) GO TO 200 IF (A (U+2,MU+1).EQ.0.ODO) GO TO 200 IF (A (NU,MU) **2.GE.A(MU+1,MU+1)*A (pU+2,MU+2)-A(MU+1,MU+2)* + A(MU+2,MU+1)) GO TO 230 CALL EXCHNG (A,V,N,MU,1,2,EPS,FAIL,NA,NV) IF (.NOT.FAIL) GO TO 190 ITYPE (MU) =- I ITYPE (MU+1) -1 ITYPE (MU+2) =GO TO 240 CONTINUE MU=MU+2 GO TO 210 CONTINUE DABS (A (MU+1,MU+1)) GO TO 220 IF (DABS (A (MU,MU)) .GE. CALL EXCHNG (A,V,N,MU,1,1,EPS,FAIL,NA,NV) MU=U+ 1 CONTINUE GO TO 180 CONTINUE MU=NL NL=0 IF (MU.NB.0) GO TO 170 CONTINUE NU=L-1 GO TO 20 IF (NU.LT. NLOW) GO TO 260 DO 250 I=1, NU A (I,I)=A {I, I)+T CO TINUE CONTINUE N U=NUP CONTINUE IF (ITYPE (NU).NE.-1) GO TO 280 NU=NU- 1 GO TO 310 CONTINUE IF (NU.EQ.N.LOW) GO TO 290 QR 01 66( HQ0 167( HQa0168( HQR0169( HQR0170( HQR0171{ HQRO 17 2( HQIE0173( HQR0174( HQR0175( HQR0176( HQR0 177( fHQR0178 HQR0 179( HQR0180( HQR0181( HQE1t82( HQE0183( HQE0184( HQP0185( HQiR0186( HQ;R0187{ HQR 188( HQ1O 891 HQR0 190( HQi 019 1 HQE0192( HQR0193( HQR0194( HQR 0195( H'QE0196( fHQE0197( HQRE0198( HQR0199( HQ.RO200( fIQR0201( HQR0202( HQ0 20 3( HQR0204( HQRO 205( HQR0206( HQR 020 7( HQE0208( HQR0209( HQR0210( HQR0211( HQEO212( HQ 0213 ( HQ0214( HQ 2 1 5( HQE3021 6 HQR0217( HQP,0218( HQBR0219( HQE0220( -73- 290 300 310 IF (A(NU, NU-1).EQ.0.ODO) GO TO 290 CALL SPLIT (A,V,N, NU-1,El,E2,NA,NV) IF (A (NU,NU-1).LQ.0.O)D0) GO TC 290 EL (NU)=Et EI (NU- 1) =E2 ER (NU-1) =ER (NU) EI (NU)=-- I (NU-1) ITYPE (NUI -) =1 ITYPE (NU)=2 NU=NU-2 GO TO 300 CONTINUE ER(NU)=A (NU,NU) El (NU)=0 ODO NU=NU-1 CONTINUE CONTINUE IF (NU.GE.N.LOW) GO TO 270 RETURN .I C C LAST LINS OF HQR3 C END HJR3 5 HQP02211 HQii0222( HQa 022.3 HQE0224( HQR0225{ HQEf0226( HiQR 0227( HQR0228{ HQR0229( HQR02301 HQR0231( HQR0232{ HQR0233( HQR0234( HQR0235( HQR0236( HQR0237( HQa0238( HQR0239{ HHQR0240( HQR 0241t fIHQ0242( HQR0243( HQR0244( -74- SUBROUTINE C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C MLINEQ MLINEQ 1 (NA,NB,N,M,A,B,COND,IPVT, WOEK) *****PARAMETERS: INTEGER NA, NB, N,M, IPVT N) DOUBLE PRECISION A(NA,N),B(NB,M),COND,WORK(N) *****LOCAL VARIABLES: INTEGER I,J,KIN, FOUT DOUBLE PRECISION CONDP1 *****SUBLOUTINES CALLED: DDCOMP,DSOLVE ML0001( MLI0002( MLt10003( MLI 000 4( MLIS005( ML10006( MLIO 007( MLI0008( ML10009( MLI001 0( MLI0011( MLI0012( MLI0013( MLI0015( MLI0016 ( MLIO017( MLI 0018 MLI0019( MLI0020( MLIO0021( MLTO0022( MLI0023( MLI0024( MLI0025( MLI0026( MLI0027( * ***PARAdiETER DESCRIPTION: NMLI0028( ON INPUT: MLI0029C ML10030( NA,NB ROW DIMENSIONS OF THE ARRAYS CONTAINING A AND M.LI0031( B, RESPECTIVELY, AS DECLARED IN THE CALLING MLI0032( PROGRAM DIMENSION STATEMENT; MLI0033( MLI0034t N ORDER OF THE MATRIX A AND NUMBER OF ROWS OF MLI0035( THE MATRIX B; MLI0036( MILO0037( A NUMBER OF COLUMNS OF THE MATRIX B; ML10038( ML10039( A N X N COEFFICIENT MATRIX; MLI0040( MLI0041 C B N X M RIGHT HAND SIDE MATRIX. MLI0042( MLI0043C ON OUTPUT: MLI0044( MLI0045( B SOLUTION MATRIX X = (A-INVERSE)*B; MLI0046( MLI0047( COND AN ESTIMATE OF THE CONDITION OF A; MLI0048C ML10049( IPYT PIVOT VECTOR CF LENGTH N (SEE DDCOMP MLTI050C DOCUMENTATION); MLI0051( MLI0052C WORK A REAL SCRATCH VECTOR OF LENGTH N. MLI0053C ML100 54( *****A.PPLICATIONS AND USAGE RESTRICTIONS: MLI0055C *****PURPOSE : THIS SUBROUTINE SOLVES THE MATRIX LINEAR EQUATION A*X = B WHERE A IS AN N X N (INVERTIBLE) MATRIX AND B IS AN N X M MATRIX. SUBROUTINE DDCOMP IS CALLED ONCE FOR THEI LU-DECOMPOSITION OF A AND SUBROUTINE DSOLVE IS CALLED M TIMES FOR FORWARD ELIMINATION AND BACK SUBSTITUTION TO PRODUCE THE M COLUMNS OF THE SOLUTION MATRIX X = (A-INVERSE) *B. AN ESTIMATE OF THE CONDITION OF A IS RETURNED. SHOULD A BE SINGULAR TO WORKING ACCURACY, A MESSAGE TO THAT EFFECT IS PRODUCED. -75- C C C C C C C C C C C C C C C C C C C C C C C C MLINEQ 2 (1)THE VALUE OF COND SHOULD ALWAYS BE CHECKED BY THE CALLING PROGRAM. SHOULD A BE NLAR-SINGULAR (OR SINGULAR TO WORKING ACCURACY) THE DATA SHOULD BE INVESTIGATED FOR POSSIBLE EREORS. IF THERE ARE NONE AND THE PROBLEM IS APPARENTLY WELL-POSED AND/OR MEANINGFUL, SINGULAR VALUE ANALYSIS IS THEN A MORE RELIABLE SOLUTION TECHNIQUE (CF. EISPACK SUBROUTINES SVD AND MINFIT). (2)MLINEQ CAN BE USED TO COMPUTE THE INVERSE OF A: SIMPLY SOLVE A*X = I WHERE I iS THE N X N IDENTITY MATRIX. (3)IF THE SOLUTION TO X*A = B (X = B*(A-INVERSE)) IS DESIRED, SIMPLY TRANSPOSE THE SOLUTION CF T T A* X = B *****ALGORITHM NOTES: THE CONTENTS OF A ARE MODIFIED BY THIS SUBROUTINE. SHOULD THE ORIGINAL COEFFICIENTS OF A BE NEEDED SUBSEQUENTLY, THE CONTENTS OF A SHOULD BE SAVED PRIOR TO THE CALL TO MLINEQ. ***** HISTORY: WRITTEN BY ALAN J. LAUB (ELEC. SYS. LAB., M.I.T., RM. 35-331, CAMBRIDGE, MA 02139, PH.: (617)-253-2125), AUGUST 1977. MOST RECENT VERSION: SEP. 21, 1977. Ž1LI0056( ML10057( MLI0058( MLI059( MLIOO60( MLI0061( ML10062( ML10063( MLI0064( MLI0065( ML10066( MLI0067( ML 0068( MLI0069( ML10070C MLI0071( MLI0072( MLII0073( MLI007 4( MLI0075( MLI0076( MLI0077C MLI0078( MLI0079( C MtiLI008 1( COMMON/INOU/KIN, KOUT CALL DDCOMP (NA,N,A,COND,IPVT,WORK) CONDP 1=COND+1. ODO IF (CONDPl.GT.COND) GO TO 100 WRITE (KOUT,44400) 44 4 00 FORMAT (40HIMATRIX IS SINGULAR TO WORKING PRECISION) RETURN 100 DO 400 J=1,M DO 200 I=1,N WORK (I)=B (I,J) 200 CONTINUE C C COMPUTI (JU-TH COLUMN OF X) = (A-INVERSE)*(J-TH COLUMN OF B) C CALL DSOLVE (NA,N,A,WORK,IPVT) DO 300 I=1,N B (I, J) =WORK (I) 300 CCNTINUE 400 CONTINUE RETURN C C LAST LINE OF MLINEQ C END MLI0082( ML1008:3( MLI0084( MLI:0085( MLI0086C ML10087( MLI0088C M1LI0089( MLI0090C MLI0091( MLI0092( MLI 0093( MLI009;4( MLI0095( MLI 0096( MLI0097( MLI0098( MLI0099£ MLIO100( MLIO 101 MLI0102 £ MLI0103( MLI0104( ML10105( -76- MUL00010 ¶MUL00020 MUL00030 *****PARAMETERS: MUL00040 INTEGER NA, NB, N MUL00050 DOUBLE PRECISION A(NA,N),B (NB,N) ,WO8RK(N) MULOO00060 MUL00070 *****LOCAL VARIABLES: MUL0080 INTEGER I,J,K MUL00090O MUL001 00 *****SUBROUTINES CALLED: MULOo 110 NONE MUL00120 :ULOI0 ................ aMUL00140 MUL 00150 *****PURPOS : MUL00160 PRODUCT MATRIX WITH THE A THE ARRAY THIS SUBROUTINE OVERWRITES MUL00170 AND B ARE N X N ARRAYS AND MUST BE DISTINCT. BOTH A A A*B. MUL00180 MUL00190 *****PARAMETER DESCRIPTION: MUL00200 ON INPUT: MUL00210 AND MUL00220 A CONTAINING ARRAYS THE OF ROW DIMENSIONS NA,NB MUL00230 CALLING THE IN AS DECLARED RESPECTIVELY, B, MUL00240 STATEMENT; DIMENSION PROGRAM iUL00250 MUL00260 B; AND A MATRICES OF THE ORDER N MUL00270 280 MUL00 MATRIX; X N AN N A MU.L00290 MUL00300 AN N X N MATRIX. B MUL00310 MUL00320 ON OUTPUT: MUL00330 MUL00340 AN N X N ARRAY CONTAINING A*B; A MUL00350 MUL00360O A REAL SCRATCH VECTOR OF LENGTH N. WORK MUL00370 MUL00380 *****HISTORY: MUL00390 LAUB (ELEC. SYS. LAB., M.I.T., RM. 35-331, WRITTEN BY ALAN J. MULO0400 1977. SEPTEMBER (617)-253-2125), PH.: MA 02139, , CAMBRIDGE MUL00410 MOST RECENT VERSION: SEP. 21, 1977. MUL00420 ======== = ::= = =============== :::::::: =:::::::::::::::::: MUL00440 MUL00450 DO 40 I=1,N MUL00460 DO 20 J=1,N MUL0470 3 =0. ODO WOR K (J) MUL00480 DO 10 K=1,N MUL00490 WORK (J) =WORK (J) +A (I ,K) *B (K,J) MUL00500 CONTINUE MUL 0510 CONTINUE MUL00520 DO 30 J=t,N MUL00530 A (I,J)=WORK (J) MUL00540 CONTINUE MUL00550 CONTINUE SUBROUTINE C C; C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C -c C 10 20 30 40 MULWOA 1- MULW OA (NA, NB,N,A,B,WB'CK) 30 -77- RETURN C C C LAST LINE OF MULWOA END MULWOA 2 UL00560 iUL00570 .MULO0580 iM1UL00590 MULO0600 a -78- SUBROUJTINE MULWOB C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C (NA,NB,N,A,B,WORK) *****PARAMETERS: INTEGER NA,NB,N DOUBLE PRECISION A (NA,N) ,B(NB,N)WORK (N) *****LOCAL VARIABLES: INTEGER I,J,K *****SUBROUTINES CALLED: NONE 20 30 MUL000 10 MUL0002O MU LOO3 30 MUL00040 MUL00050 MUL00060 MUL00070 MUL000 80 MUL00090 MUL00100 MUL001O C MULO0120 MUL00140 M'JLO 150 MUL00160 MUtL0017C MUL00130 *****P ARAMETER DESCRIPTION: MUL00190 ON INPUT: MUL0020C MUL00210 NA,NB ROW DIMENSIONS OF THE ARRAYS CONTAINING A AND MUL0022C B, RESPECTIVELY, AS DECLARED IN THE CALLING MUL0230 PROGRAM DIMENSION STATEMENT; NULOO24C MUL0025C N ORDER OF THE MATRICES A AND B; MUL0026C MU L0027C A AN N X N MATRIX; MUL0028C ¶U1002 9( B AN N X N MATRIX. MULO030C MUL0031 ( ON OUTPUT: MUL0032C MULO033C B AN N X N ARRAY CONTAINING A*B; MULO0.34C MUIL0035C WORK A REAL SCRATCH VECTOR OF LENGTH N. MULOO36( MULJ0037C *****HISTORY: MUL0038( WRITTEN BY ALAN J. LAUB (ELEC. SYS. LAB., M.I.T., RM. 35-331, MUL0039C CAMBRIDGE, MA 02139, PH.: (617)-253-2125), SEPTEMBER 1977 MULt0040( MOST RECENT VERSION: SEP. 21, 1977. M3UL0041C *,***PURPOSE: THIS SUBROUTINE OVERWRITES THE ARRAY 3 WITH THE MATRIX PRODUCT A*B. BOTH A AND B ARE N X N ARRAYS AND MUST BE DISTINCT. C 10 MULWOB 1 DO 50 J1,N DO 10 I=1,N WOR K (I)= O. ODO CONTINUE DO 30 K=1,N DO 20 1=1,N WORK (I) WORK (I) +A(I, K)*B(K,J) CONTINUE CONTIN UE DO 40 I=1,N B (I ,J) =WZORK (I) MUL0044( MUL0045( MULO '46( MUUL0047( MULO048( MUL0049( MUL0050(C MUL0051( MUL0052C MULOO53( MUL0054( tMUL0055( -79- 40 50 C C CONTINUE CONTINUE RETURN MULWOB 2 MUL0056C MUL00570 LAST LINE OF MULWOB MUL 058C tI[UL0059C MiUL0600 CND MUL00620 -80- SUB3OUTINE QESTE:P C c C C C C (A,V,P,Q,R, N, *****PARAMETERS: INTEGER NNANL,NU,NV DOUBLE PRECISION A(NA, N) NU, NNANV) P,Q,R,V(NV,N) *****LOCAL VARIABLES: LOGICAL LAST INTEGER i,J,K,NL2,NL3,NUM1 DOUBLE PRECISION S,X,Y,Z *****FUNCTIONS: DOUBLE PRECISION DABS,DSQRT QRSTEP 1 QRS000 1C QRS0OO2( QRS0003( QRSO004( QRS0005C QRS00064 QRS0007( QRSOO08( QRSOOO9( QRS0010{ QRS0011(i QRS0 12( QRS0013i QR SOO 14 QRS0015t QRS0 16( QRS0017{ C *****SUBROUTINES CALLED: C C NONE C C :::::....::.............QRS00l1 QBS 0 1 91 C QRS0020! C *****PURPOSE: Q S02 1 C THilS SUBROUTINE PERFORMS ONE IMPLICIT QR STEP ON THE UPPER QRS0022! C HESSENBERG MATRIX A. THE SHIFT IS DETERMINED BY THE NUMBERS P,Q, AND R, AND THE STEP IS APPLIED TC ROWS AND COLUMNS NL THROUTH NU. QRS00231 C QRS0O024 THE TRANSFORMATIONS ARE ACCUMULATED IN THE ARRAY V. C C QRS 0025 QRS00261 C *****PARAMETER DESCRIPTION: QRS0027 ON INPUT: C QRSOO28 ROW DIMENSIONS OF THE ARRAYS CONTAlNING A NA,NV C QRS0029 AND V, RESPECTIVELY, AS DECLARED IN THE C C CALLING PROGRAM DIMENSION STATEMENT; QRS0030: QRS003 1 C N X N UPPER HESSENBERG MATRIX ON WHICH THE QR QRS0032 C A QRS0033 i STEP IS TO BE PERFORMED; C QRS0034 C QRS0035 PARAMETERS WHICH DETERMINE THE SHIFT; P,QR C C QRS0036 QRS0037 THE LOWER LIMIT OF THE STEP; NL C QRSO 38 C QRS0039 THE UPPER LIMIT OF THE STEP; C NU QRSQ0040 C QRSOO41 ORDER OF THE MATRIX A. N C QRS0042 C Q S50043 ON OUTPUT: C QRS0044 C QRS0045 N X N REAL SCRATCH ARRAY CONTAINING THE V C QRS0046 ACCUMULATED TRANSFORMATIONS. C C QRS0047 QBS 0048 C *****HISTORY: DOCUMENTED BY J.A.K. CARRIG (ELEC. SYS. LAB., M.I.T., RM. 35-307, QRS0049 C QRS050 C CAMBRIDGE, MA 02139, PH.: (617) - 253-2165), SEPTEMBER 1978. QRS0051 MOST RECENT VERSION: SEPT 21, 1978. C QRS 0052 C : ::QRS0053 -5 3:-: )3: :: :1: . :::::-:-· : C...QRS3::' C QRS0054 NL2=NL+2 QRS0055 -81- 10 20 30 40 50 60 70 80 90 DO 10 I=NL2,NU A (1,I-2) =0. D CONTINUE IF (NL2,.EQ. NU) GO TO 30 NL3=NL+3 DO 20 I=NL3,NU A (I,t-3) =0. DO CONTINUE CONTINUE NU&1=NU-1 DO 130 K=NL,NUM1 LAST=K. EQ. NUM1 IF (K.EQ.NL) GO TO 40 P=A (K,K-1) Q-A (K+ 1,K-1) R=0.ODO IF (.NOT.LAST) fR=A(K+2,K-1) X=DABS (P) +DABS (Q) +DABS (R) IF (X.EQ.0. ODO) GO TO 130 P=P/X Q=Q/X R=R/X CONTINUE S=DSQRT (P**2+Q**2+R**2) IF (P.LT.O.ODO) S=-S IF (K.EQ.NL) GO TO 50 A (KK-1)=-S*X GO TO 60 CONTINUE IF (NL.NE.1) A -A(K,K--1 CONTINUE P=P+S QRSTEP 2 QRS00561 QRS00571 QRS0058( QRS0059i QRS0060j QRS061 QRS0062 ~ QR SO 0631 QRSOO64 QRS0065( QR50066: QR S0067t QRS00681 QRS00691 QRS007 0j QRS00711 QRS007 2 QRS0073 QRS0074( QRS0075i QRS0076i QR50077i QRS0078i QRS0079i QRS008Oi QRS00811 QRSO082i QRS0083( QRS00841 QRS00851 QRS0086i QeRSO 87 X=?/S QRSO088i Y=Q/S QRS00891 Z=R/S QRS0090( Q=Q/p R=a/P DO 80 J=K,N P=A (K,J) +Q*A (K +1 ,J) IF (LAST) GO TO 70 P=P+R*A (K+2,J) A (K+2,J)=A (K+2,J) -P*Z CONTINUE A (K+ 1 ,J) =A (K+1 ,J) -PY A (K,J)=A (K,J)-P*X CONTINUE J=MIN0 (K+3, NU) DO 100 I=1,J P=X*A (I,K) +Y*A (I,K+1) IF (LAST) GO TO 90 P=P +Z*A (I, K+2) A (I ,K+2) =A (I,K+2) -P*E CONTINUE A (I,K+ 1) =A (I,K+1)-P*Q QRSOO91QiRS0092 QRS0093t QRS00944 QRS0095( QiS 0O961 QRS0097( QRS00981 QRS0099 QRS0100i QRS0101I QR SO 1021 QRS0103, QRS0104L QRS0105i QR S 106( QSI01 073 QRS0108, QRS01 09 A (I ,K)=A (I,K) -P QRsO 1t0 -82- 100 110 120 130 C C C CONTI NUE DO 120 I=1,N P=-XY II, K) +Y*V (I, K+1) IF (LAST) GO TO 110 P=P+Z*V (I, K+2) V (IK+2) =V (I,K+2)-P*R CONTINUE V (I,K+ 1) =V (I,K+1) -P*Q v (I, K) V (I,K) -P CONTINUE CONTINUE RETURN LAST LINE OF QRSTEP END QRSTEP 3 Q R SO 1 1 1 QERS012 QRSO01 13 QRS01 14i QRSO 15t QRS0116t QRSO 17i QS01 18i QRS01 19P QRS0120i QRS0121, QRS0 122 QRS0123 QRS50124 QRSO125t QRS01261 -83- SUBROUTINE C C C C C C SPLIT (A,V,N,L,E1,E2,NA,NV) *****PARAMETERS: INTEGER L,N,NA,NV DOUBLE PRECISION A (NA,N),V(NV,N),E1,E2 ***'**LOCAL VARIABLES: INTEGER I,J,Lt DOUBLE PRECISION PQRTUWXY,Z ****FUNCTIONS: DOUBLE PRECISION DAiBS,DSQRT SPLIT 1 SPLOO 10 SPL00020 S PLOOO30 SPL00040 SPL00050 SPL00060 SPL00070 SPL00080 SPL00090 SPLO100l SPL001 10 SPLOO120 SPL00130 SPL00O1-40 SPL00150 SPL00 160 :: S::::: -:: :SP0170 C C C C :C.. ****SUBRO:UTINES CALLED: NONE C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C SPL00 180 SPLOO190 *****PURPOSE: GIVEN TiiE UPPLR-HESSENBERG MATRIX A WITH A 2 X 2 BLOCK STARTING ATSPLOO200 SPL00210 A (L,L), THIS PROGRAM DETERMINES IF THE CORRESPONDING EIGENVALUES SPL00220 ARLE EAL OR COMPLEX. IF THEY ARE REAL, A ROTATION IS DETERMINED SPL00230 THE THAT REDUCES THE BLOCK TO UPPER-TRIANGULAR FORM WITH SP.L00240 THE ELIGENVALUE OF LARGEST ABSOLUTE VALUE APPEARING FIRST. SPL00250 ROTATION IS ACCUMULATED IN THE ARRAY V. SPL00260 SPLOO 270 *****PARAMETER DESCRIPTION: SPLOO28C ON INPUT: SPL00290 ROW DIMENSIONS OF THE ARRAYS CONTAINING NA,NV SPLOO300 IN THE DECLARED AS V, RESPECTIVELY, A AND SPLOO310 CALLING PROGRAM DIMENSION STATEMENT; SPL0032C THE UPPER HESSENBERG MATRIX WHOSE 2 X 2 BLOCK SPL00330 A SPL00340 IS TO BE SPLIT; SPLOO35C SPL00360 A; MATRIX OF THE ORDER N SP L0037C SPLOO380 BLOCK. 2 X 2 THE OF POSITION L SPLOO39C SPLOO40C ON OUTPUT: SPL00O41C SPL0042C AN N X N ARRAY CONTAINING THE ACCUMULATED V SPL00430 SPLITTING TRANSFORMATION; SPL400L4C REAL SCALARS. IF THE EIGENVALUES ARE COMPLEX, SPLO045C Et,L2 SPL00O46 El AND E2 CONTAIN THEIR COM21MON REAL PART AND SPL00347C POSITIVE IMAGINARY PART (RESPECTIVELY). SPL0048( IF THE EIGENVALUES ARE REAL, El CONTAINS THE ONE LARGEST IN ABSOLUTE VALUE AND E2 CONTAINS SPL0049C SPL00O50C THE OTHER ONE. SPLO051C SPLOO52C *****HISTORY: SPL0053( 35-307, DOCUMENTED BY J.A.K. CARRIG (ELEC. SYS. LAB., M.I.T., E. SPL005C SEPT 1978. MA 02139, PH.: (617) - 253-2165), CAMBRIDGE, SPL0055( MlOST RECENT VERSION: SEPT 21, 1978. : -84- C C SPLIT 2 .:::::::' :::::::::.::':::::::::::: C 10 X=A (L+1 ,L+l) Y=A (LL, L) W=A (L,L+1)*.A(L+ 1, L) P= (Y-X)/2. 0D Q=P**2+W IF (Q.GL..O.0D0) GO TO EI=P+X E2=DSQRT (-Q) RETURN CONTINUE Z=DSQT (Q) IF 20 30 40 50 60 70 80 90 (P.LT.0.0ODO) SPLOO 560 SLOs7 SPL0058C SPLOO590 SPL0060C SPL006 10 SPL0062C SPL00630 SPL0640 SPL0650 SPLO066C SPL00670 SPL00630 10 SPL0069C SPL0O700 GO TO 20 Z=P+Z SPL071C GO TO 30 CONTINUE SPL00720 SPLOO73C Z=P-Z CONTINUE IF (Z.EQ.0.010) GO TO 40 R=-W/Z SPL0074C SPLO075C SPL076C SPL0077C GO TO 50 SPLOO78C CONTIN UE R=O.ODO CONTINUE IF (DABS (X+Z).GE.DABS(X+R)) Z=R Y=Y-X-Z X=-Z T=A (L,L+) U=A (L+ 1,L) IF (DABS (Y)+DABS(U) .L E.DABS(T)+DABS(X)) Q=U SPL0079C SPL080C SPL008 10 SPL0082C SPLOO83C SPLO084C SPL0085C SPL0OO86 SPL0087( SPL00880 GO TO 60 P=Y SPL0089( GO TO 70 CONTINUE Q=X P=T CONTINU.E R=DSQRT (P**2+Q**2) SPLOO90C SPL0091 C SPL0092C SPL0093( SPLOO94C SPL0O95C IF SPL0096( (R.GT.0.ODO) GO TO 80 E=A (L,L) E2=A (L+1 ,L+ 1) A (L+1,L) =0. ODO RETURN CONTINUE P=P/R Q=Q/R DO 90 J=L,N Z=A (L,J) A (L,J) =PZ +Q*A (L+ 1, J) A (L+l ,J) =P*A (L-+ t CONTINUE Ll=L+1 DO 100 I=1,Lt ,J)-Q*Z SPL0097C SPL0098( SPL0099C SPL0100( SPLO101C SPL0102( SPLO103( SPLO104C SPLO105( SPLO 106C SPLO1 07( SPL0108( SPLO109( SPL0110( -85- 100 110 C C C ZA=A (I,L) A (I ,L)=P*Z+Q*A (,L+) A (I, L+ 1)= P*A (I,L+ 1) -Q*Z CONTINUE DO 110 i=1,N Z=V (I,L) V (I,L)=P*Z+Q*V (I,L+1) V {I,L+ 1) =P*V (I,L+1) -Q*Z CONTINUE A (L+ 1,L)=0.ODO Et=A (LL) E2=A (L+t,L+ 1) RETURN LAST LINE OF SPLIT END SPLIT 3 SPLO 1 1 10 SPL1 120 SPLO 1 130 SPLO1140 SPLO1150 SP01 160 SPLO1 170 SPLO1180 SPLO1190 SPLO0200 SPL01210 SPLO 1220 SPL0123C SPL01240 SPLO1250 SPLO 1260 SPL01270