home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 22 gnu / 22-gnu.zip / mesch12a.zip / matrix2.h < prev    next >
C/C++ Source or Header  |  1994-01-13  |  9KB  |  230 lines

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