matrix2.h 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. /**************************************************************************
  2. **
  3. ** Copyright (C) 1993 David E. Steward & Zbigniew Leyk, all rights reserved.
  4. **
  5. ** Meschach Library
  6. **
  7. ** This Meschach Library is provided "as is" without any express
  8. ** or implied warranty of any kind with respect to this software.
  9. ** In particular the authors shall not be liable for any direct,
  10. ** indirect, special, incidental or consequential damages arising
  11. ** in any way from use of the software.
  12. **
  13. ** Everyone is granted permission to copy, modify and redistribute this
  14. ** Meschach Library, provided:
  15. ** 1. All copies contain this copyright notice.
  16. ** 2. All modified copies shall carry a notice stating who
  17. ** made the last modification and the date of such modification.
  18. ** 3. No charge is made for this software or works derived from it.
  19. ** This clause shall not be construed as constraining other software
  20. ** distributed on the same medium as this software, nor is a
  21. ** distribution fee considered a charge.
  22. **
  23. ***************************************************************************/
  24. /*
  25. Header file for ``matrix2.a'' library file
  26. */
  27. #ifndef MATRIX2H
  28. #define MATRIX2H
  29. #include "matrix.h"
  30. /* Unless otherwise specified, factorisation routines overwrite the
  31. matrix that is being factorised */
  32. #ifndef ANSI_C
  33. extern MAT *BKPfactor(), *CHfactor(), *LUfactor(), *QRfactor(),
  34. *QRCPfactor(), *LDLfactor(), *Hfactor(), *MCHfactor(),
  35. *m_inverse();
  36. extern double LUcondest(), QRcondest();
  37. extern MAT *makeQ(), *makeR(), *makeHQ(), *makeH();
  38. extern MAT *LDLupdate(), *QRupdate();
  39. extern VEC *BKPsolve(), *CHsolve(), *LUsolve(), *_Qsolve(), *QRsolve(),
  40. *LDLsolve(), *Usolve(), *Lsolve(), *Dsolve(), *LTsolve(),
  41. *UTsolve(), *LUTsolve(), *QRCPsolve();
  42. extern BAND *bdLUfactor(), *bdLDLfactor();
  43. extern VEC *bdLUsolve(), *bdLDLsolve();
  44. extern VEC *hhvec();
  45. extern VEC *hhtrvec();
  46. extern MAT *hhtrrows();
  47. extern MAT *hhtrcols(), *_hhtrcols();
  48. extern void givens();
  49. extern VEC *rot_vec(); /* in situ */
  50. extern MAT *rot_rows(); /* in situ */
  51. extern MAT *rot_cols(); /* in situ */
  52. /* eigenvalue routines */
  53. extern VEC *trieig(), *symmeig();
  54. extern MAT *schur();
  55. extern void schur_evals();
  56. extern MAT *schur_vecs();
  57. /* singular value decomposition */
  58. extern VEC *bisvd(), *svd();
  59. /* matrix powers and exponent */
  60. MAT *_m_pow();
  61. MAT *m_pow();
  62. MAT *m_exp(), *_m_exp();
  63. MAT *m_poly();
  64. /* FFT */
  65. void fft();
  66. void ifft();
  67. #else
  68. /* forms Bunch-Kaufman-Parlett factorisation for
  69. symmetric indefinite matrices */
  70. extern MAT *BKPfactor(MAT *A,PERM *pivot,PERM *blocks),
  71. /* Cholesky factorisation of A
  72. (symmetric, positive definite) */
  73. *CHfactor(MAT *A),
  74. /* LU factorisation of A (with partial pivoting) */
  75. *LUfactor(MAT *A,PERM *pivot),
  76. /* QR factorisation of A; need dim(diag) >= # rows of A */
  77. *QRfactor(MAT *A,VEC *diag),
  78. /* QR factorisation of A with column pivoting */
  79. *QRCPfactor(MAT *A,VEC *diag,PERM *pivot),
  80. /* L.D.L^T factorisation of A */
  81. *LDLfactor(MAT *A),
  82. /* Hessenberg factorisation of A -- for schur() */
  83. *Hfactor(MAT *A,VEC *diag1,VEC *diag2),
  84. /* modified Cholesky factorisation of A;
  85. actually factors A+D, D diagonal with no
  86. diagonal entry in the factor < sqrt(tol) */
  87. *MCHfactor(MAT *A,double tol),
  88. *m_inverse(const MAT *A,MAT *out);
  89. /* returns condition estimate for A after LUfactor() */
  90. extern double LUcondest(const MAT *A, PERM *pivot),
  91. /* returns condition estimate for Q after QRfactor() */
  92. QRcondest(const MAT *A);
  93. /* Note: The make..() and ..update() routines assume that the factorisation
  94. has already been carried out */
  95. /* Qout is the "Q" (orthongonal) matrix from QR factorisation */
  96. extern MAT *makeQ(const MAT *QR,const VEC *diag,MAT *Qout),
  97. /* Rout is the "R" (upper triangular) matrix
  98. from QR factorisation */
  99. *makeR(const MAT *A,MAT *Rout),
  100. /* Qout is orthogonal matrix in Hessenberg factorisation */
  101. *makeHQ(MAT *A,VEC *diag1,VEC *diag2,MAT *Qout),
  102. /* Hout is the Hessenberg matrix in Hessenberg factorisation */
  103. *makeH(const MAT *A,MAT *Hout);
  104. /* updates L.D.L^T factorisation for A <- A + alpha.u.u^T */
  105. extern MAT *LDLupdate(MAT *A,VEC *u,double alpha),
  106. /* updates QR factorisation for QR <- Q.(R+u.v^T)
  107. Note: we need explicit Q & R matrices,
  108. from makeQ() and makeR() */
  109. *QRupdate(MAT *Q,MAT *R,VEC *u,VEC *v);
  110. /* Solve routines assume that the corresponding factorisation routine
  111. has already been applied to the matrix along with auxiliary
  112. objects (such as pivot permutations)
  113. These solve the system A.x = b,
  114. except for LUTsolve and QRTsolve which solve the transposed system
  115. A^T.x. = b.
  116. If x is NULL on entry, then it is created.
  117. */
  118. extern VEC *BKPsolve(const MAT *A,PERM *pivot,const PERM *blocks,
  119. const VEC *b,VEC *x),
  120. *CHsolve(const MAT *A,const VEC *b,VEC *x),
  121. *LDLsolve(const MAT *A,const VEC *b,VEC *x),
  122. *LUsolve(const MAT *A, PERM *pivot, const VEC *b,VEC *x),
  123. *_Qsolve(const MAT *A, const VEC *diag, const VEC *b,
  124. VEC *x, VEC *tmp),
  125. *QRsolve(const MAT *A, const VEC *diag, const VEC *b,VEC *x),
  126. *QRTsolve(const MAT *A,const VEC *,const VEC *b,VEC *x),
  127. /* Triangular equations solve routines;
  128. U for upper triangular, L for lower traingular, D for diagonal
  129. if diag_val == 0.0 use that values in the matrix */
  130. *Usolve(const MAT *A,const VEC *b,VEC *x,double diag_val),
  131. *Lsolve(const MAT *A,const VEC *b,VEC *x,double diag_val),
  132. *Dsolve(const MAT *A,const VEC *b,VEC *x),
  133. *LTsolve(const MAT *A,const VEC *b,VEC *x,double diag_val),
  134. *UTsolve(const MAT *A,const VEC *b,VEC *x,double diag_val),
  135. *LUTsolve(const MAT *A,PERM *pivot,const VEC *b, VEC *x),
  136. *QRCPsolve(const MAT *QR,const VEC *diag,PERM *pivot,
  137. const VEC *b,VEC *x);
  138. extern BAND *bdLUfactor(BAND *A,PERM *pivot),
  139. *bdLDLfactor(BAND *A);
  140. extern VEC *bdLUsolve(const BAND *A,PERM *pivot,const VEC *b,VEC *x),
  141. *bdLDLsolve(const BAND *A,const VEC *b,VEC *x);
  142. extern VEC *hhvec(const VEC *,unsigned int,Real *,VEC *,Real *);
  143. extern VEC *hhtrvec(const VEC *,double,unsigned int,const VEC *,VEC *);
  144. extern MAT *hhtrrows(MAT *,unsigned int,unsigned int,const VEC *,double);
  145. extern MAT *hhtrcols(MAT *,unsigned int,unsigned int,const VEC *,double);
  146. extern MAT *_hhtrcols(MAT *,unsigned int,unsigned int,const VEC *,double,VEC *);
  147. extern void givens(double,double,Real *,Real *);
  148. extern VEC *rot_vec(const VEC *,unsigned int,unsigned int,
  149. double,double,VEC *); /* in situ */
  150. extern MAT *rot_rows(const MAT *,unsigned int,unsigned int,
  151. double,double,MAT *); /* in situ */
  152. extern MAT *rot_cols(const MAT *,unsigned int,unsigned int,
  153. double,double,MAT *); /* in situ */
  154. /* eigenvalue routines */
  155. /* compute eigenvalues of tridiagonal matrix
  156. with diagonal entries a[i], super & sub diagonal entries
  157. b[i]; eigenvectors stored in Q (if not NULL) */
  158. extern VEC *trieig(VEC *a,VEC *b,MAT *Q),
  159. /* sets out to be vector of eigenvectors; eigenvectors
  160. stored in Q (if not NULL). A is unchanged */
  161. *symmeig(const MAT *A,MAT *Q,VEC *out);
  162. /* computes real Schur form = Q^T.A.Q */
  163. extern MAT *schur(MAT *A,MAT *Q);
  164. /* computes real and imaginary parts of the eigenvalues
  165. of A after schur() */
  166. extern void schur_evals(MAT *A,VEC *re_part,VEC *im_part);
  167. /* computes real and imaginary parts of the eigenvectors
  168. of A after schur() */
  169. extern MAT *schur_vecs(MAT *T,MAT *Q,MAT *X_re,MAT *X_im);
  170. /* singular value decomposition */
  171. /* computes singular values of bi-diagonal matrix with
  172. diagonal entries a[i] and superdiagonal entries b[i];
  173. singular vectors stored in U and V (if not NULL) */
  174. VEC *bisvd(VEC *a,VEC *b,MAT *U,MAT *V),
  175. /* sets "out" to be vector of singular values;
  176. singular vectors stored in U and V */
  177. *svd(MAT *A,MAT *U,MAT *V,VEC *out);
  178. /* matrix powers and exponent */
  179. MAT *_m_pow(const MAT *A, int p, MAT *tmp,MAT *out);
  180. MAT *m_pow(const MAT *A, int p, MAT *out);
  181. MAT *m_exp(MAT *,double,MAT *);
  182. MAT *_m_exp(MAT *A, double eps, MAT *out, int *q_out, int *j_out);
  183. MAT *m_poly(const MAT *,const VEC *,MAT *);
  184. /* FFT */
  185. void fft(VEC *,VEC *);
  186. void ifft(VEC *,VEC *);
  187. #endif
  188. #endif