NEURON
matrix2.h
Go to the documentation of this file.
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 #if defined(__cplusplus)
36 extern "C" {
37 #endif
38 
39 #include "matrix.h"
40 
41 /* Unless otherwise specified, factorisation routines overwrite the
42  matrix that is being factorised */
43 
44 #ifndef ANSI_C
45 
46 extern MAT *BKPfactor(), *CHfactor(), *LUfactor(), *QRfactor(),
47  *QRCPfactor(), *LDLfactor(), *Hfactor(), *MCHfactor(),
48  *m_inverse();
49 extern double LUcondest(), QRcondest();
50 extern MAT *makeQ(), *makeR(), *makeHQ(), *makeH();
51 extern MAT *LDLupdate(), *QRupdate();
52 
53 extern VEC *BKPsolve(), *CHsolve(), *LUsolve(), *_Qsolve(), *QRsolve(),
54  *LDLsolve(), *Usolve(), *Lsolve(), *Dsolve(), *LTsolve(),
55  *UTsolve(), *LUTsolve(), *QRCPsolve();
56 
57 extern BAND *bdLUfactor(), *bdLDLfactor();
58 extern VEC *bdLUsolve(), *bdLDLsolve();
59 
60 extern VEC *hhvec();
61 extern VEC *hhtrvec();
62 extern MAT *hhtrrows();
63 extern MAT *hhtrcols();
64 
65 extern void givens();
66 extern VEC *rot_vec(); /* in situ */
67 extern MAT *rot_rows(); /* in situ */
68 extern MAT *rot_cols(); /* in situ */
69 
70 
71 /* eigenvalue routines */
72 extern VEC *trieig(), *symmeig();
73 extern MAT *schur();
74 extern void schur_evals();
75 extern MAT *schur_vecs();
76 
77 /* singular value decomposition */
78 extern VEC *bisvd(), *svd();
79 
80 /* matrix powers and exponent */
81 MAT *_m_pow();
82 MAT *m_pow();
83 MAT *m_exp(), *_m_exp();
84 MAT *m_poly();
85 
86 /* FFT */
87 void fft();
88 void ifft();
89 
90 
91 #else
92 
93  /* forms Bunch-Kaufman-Parlett factorisation for
94  symmetric indefinite matrices */
95 extern MAT *BKPfactor(MAT *A,PERM *pivot,PERM *blocks),
96  /* Cholesky factorisation of A
97  (symmetric, positive definite) */
98  *CHfactor(MAT *A),
99  /* LU factorisation of A (with partial pivoting) */
100  *LUfactor(MAT *A,PERM *pivot),
101  /* QR factorisation of A; need dim(diag) >= # rows of A */
102  *QRfactor(MAT *A,VEC *diag),
103  /* QR factorisation of A with column pivoting */
104  *QRCPfactor(MAT *A,VEC *diag,PERM *pivot),
105  /* L.D.L^T factorisation of A */
106  *LDLfactor(MAT *A),
107  /* Hessenberg factorisation of A -- for schur() */
108  *Hfactor(MAT *A,VEC *diag1,VEC *diag2),
109  /* modified Cholesky factorisation of A;
110  actually factors A+D, D diagonal with no
111  diagonal entry in the factor < sqrt(tol) */
112  *MCHfactor(MAT *A,double tol),
113  *m_inverse(MAT *A,MAT *out);
114 
115  /* returns condition estimate for A after LUfactor() */
116 extern double LUcondest(MAT *A,PERM *pivot),
117  /* returns condition estimate for Q after QRfactor() */
118  QRcondest(MAT *A);
119 
120 /* Note: The make..() and ..update() routines assume that the factorisation
121  has already been carried out */
122 
123  /* Qout is the "Q" (orthongonal) matrix from QR factorisation */
124 extern MAT *makeQ(MAT *A,VEC *diag,MAT *Qout),
125  /* Rout is the "R" (upper triangular) matrix
126  from QR factorisation */
127  *makeR(MAT *A,MAT *Rout),
128  /* Qout is orthogonal matrix in Hessenberg factorisation */
129  *makeHQ(MAT *A,VEC *diag1,VEC *diag2,MAT *Qout),
130  /* Hout is the Hessenberg matrix in Hessenberg factorisation */
131  *makeH(MAT *A,MAT *Hout);
132 
133  /* updates L.D.L^T factorisation for A <- A + alpha.u.u^T */
134 extern MAT *LDLupdate(MAT *A,VEC *u,double alpha),
135  /* updates QR factorisation for QR <- Q.(R+u.v^T)
136  Note: we need explicit Q & R matrices,
137  from makeQ() and makeR() */
138  *QRupdate(MAT *Q,MAT *R,VEC *u,VEC *v);
139 
140 /* Solve routines assume that the corresponding factorisation routine
141  has already been applied to the matrix along with auxiliary
142  objects (such as pivot permutations)
143 
144  These solve the system A.x = b,
145  except for LUTsolve and QRTsolve which solve the transposed system
146  A^T.x. = b.
147  If x is NULL on entry, then it is created.
148 */
149 
150 extern VEC *BKPsolve(MAT *A,PERM *pivot,PERM *blocks,VEC *b,VEC *x),
151  *CHsolve(MAT *A,VEC *b,VEC *x),
152  *LDLsolve(MAT *A,VEC *b,VEC *x),
153  *LUsolve(MAT *A,PERM *pivot,VEC *b,VEC *x),
154  *_Qsolve(MAT *A,VEC *,VEC *,VEC *, VEC *),
155  *QRsolve(MAT *A,VEC *,VEC *b,VEC *x),
156  *QRTsolve(MAT *A,VEC *,VEC *b,VEC *x),
157 
158 
159  /* Triangular equations solve routines;
160  U for upper triangular, L for lower traingular, D for diagonal
161  if diag_val == 0.0 use that values in the matrix */
162 
163  *Usolve(MAT *A,VEC *b,VEC *x,double diag_val),
164  *Lsolve(MAT *A,VEC *b,VEC *x,double diag_val),
165  *Dsolve(MAT *A,VEC *b,VEC *x),
166  *LTsolve(MAT *A,VEC *b,VEC *x,double diag_val),
167  *UTsolve(MAT *A,VEC *b,VEC *x,double diag_val),
168  *LUTsolve(MAT *A,PERM *,VEC *,VEC *),
169  *QRCPsolve(MAT *QR,VEC *diag,PERM *pivot,VEC *b,VEC *x);
170 
171 extern BAND *bdLUfactor(BAND *A,PERM *pivot),
172  *bdLDLfactor(BAND *A);
173 extern VEC *bdLUsolve(BAND *A,PERM *pivot,VEC *b,VEC *x),
174  *bdLDLsolve(BAND *A,VEC *b,VEC *x);
175 
176 
177 
178 extern VEC *hhvec(VEC *,u_int,Real *,VEC *,Real *);
179 extern VEC *hhtrvec(VEC *,double,u_int,VEC *,VEC *);
180 extern MAT *hhtrrows(MAT *,u_int,u_int,VEC *,double);
181 extern MAT *hhtrcols(MAT *,u_int,u_int,VEC *,double);
182 
183 extern void givens(double,double,Real *,Real *);
184 extern VEC *rot_vec(VEC *,u_int,u_int,double,double,VEC *); /* in situ */
185 extern MAT *rot_rows(MAT *,u_int,u_int,double,double,MAT *); /* in situ */
186 extern MAT *rot_cols(MAT *,u_int,u_int,double,double,MAT *); /* in situ */
187 
188 
189 /* eigenvalue routines */
190 
191  /* compute eigenvalues of tridiagonal matrix
192  with diagonal entries a[i], super & sub diagonal entries
193  b[i]; eigenvectors stored in Q (if not NULL) */
194 extern VEC *trieig(VEC *a,VEC *b,MAT *Q),
195  /* sets out to be vector of eigenvectors; eigenvectors
196  stored in Q (if not NULL). A is unchanged */
197  *symmeig(MAT *A,MAT *Q,VEC *out);
198 
199  /* computes real Schur form = Q^T.A.Q */
200 extern MAT *schur(MAT *A,MAT *Q);
201  /* computes real and imaginary parts of the eigenvalues
202  of A after schur() */
203 extern void schur_evals(MAT *A,VEC *re_part,VEC *im_part);
204  /* computes real and imaginary parts of the eigenvectors
205  of A after schur() */
206 extern MAT *schur_vecs(MAT *T,MAT *Q,MAT *X_re,MAT *X_im);
207 
208 
209 /* singular value decomposition */
210 
211  /* computes singular values of bi-diagonal matrix with
212  diagonal entries a[i] and superdiagonal entries b[i];
213  singular vectors stored in U and V (if not NULL) */
214 VEC *bisvd(VEC *a,VEC *b,MAT *U,MAT *V),
215  /* sets out to be vector of singular values;
216  singular vectors stored in U and V */
217  *svd(MAT *A,MAT *U,MAT *V,VEC *out);
218 
219 /* matrix powers and exponent */
220 MAT *_m_pow(MAT *,int,MAT *,MAT *);
221 MAT *m_pow(MAT *,int, MAT *);
222 MAT *m_exp(MAT *,double,MAT *);
223 MAT *_m_exp(MAT *,double,MAT *,int *,int *);
224 MAT *m_poly(MAT *,VEC *,MAT *);
225 
226 /* FFT */
227 void fft(VEC *,VEC *);
228 void ifft(VEC *,VEC *);
229 
230 #endif
231 
232 #if defined(__cplusplus)
233 }
234 #endif
235 
236 #endif
VEC * QRCPsolve(MAT *QR, VEC *diag, PERM *pivot, VEC *b, VEC *x)
VEC * UTsolve(MAT *A, VEC *b, VEC *x, double diag_val)
double T
Definition: rbtqueue.cpp:25
MAT * _m_pow(MAT *, int, MAT *, MAT *)
Definition: mfunc.c:45
MAT * hhtrrows(MAT *, u_int, u_int, VEC *, double)
Definition: hsehldr.c:100
MAT * hhtrcols(MAT *, u_int, u_int, VEC *, double)
Definition: hsehldr.c:146
VEC * symmeig(MAT *A, MAT *Q, VEC *out)
Definition: symmeig.c:174
VEC * QRsolve(MAT *A, VEC *, VEC *b, VEC *x)
#define diag(s)
Definition: fmenu.cpp:188
void ifft(VEC *, VEC *)
Definition: fft.c:137
#define Real
Definition: machine.h:189
void givens(double, double, Real *, Real *)
Definition: givens.c:47
VEC * svd(MAT *A, MAT *U, MAT *V, VEC *out)
Definition: svd.c:350
#define v
Definition: md1redef.h:4
MAT * m_inverse(MAT *A, MAT *out)
Definition: lufactor.c:179
MAT * LDLfactor(MAT *A)
VEC * bdLUsolve(BAND *A, PERM *pivot, VEC *b, VEC *x)
MAT * MCHfactor(MAT *A, double tol)
MAT * rot_rows(MAT *, u_int, u_int, double, double, MAT *)
Definition: givens.c:85
MAT * QRfactor(MAT *A, VEC *diag)
MAT * BKPfactor(MAT *A, PERM *pivot, PERM *blocks)
VEC * LUsolve(MAT *A, PERM *pivot, VEC *b, VEC *x)
BAND * bdLDLfactor(BAND *A)
Definition: bdfactor.c:507
MAT * makeH(MAT *A, MAT *Hout)
Definition: hessen.c:133
VEC * LUTsolve(MAT *A, PERM *, VEC *, VEC *)
VEC * LTsolve(MAT *A, VEC *b, VEC *x, double diag_val)
MAT * rot_cols(MAT *, u_int, u_int, double, double, MAT *)
Definition: givens.c:114
Definition: matrix.h:67
VEC * BKPsolve(MAT *A, PERM *pivot, PERM *blocks, VEC *b, VEC *x)
double QRcondest(MAT *A)
Definition: qrfactor.c:449
VEC * rot_vec(VEC *, u_int, u_int, double, double, VEC *)
Definition: givens.c:61
uint32_t u_int
Definition: machine.h:38
VEC * _Qsolve(MAT *A, VEC *, VEC *, VEC *, VEC *)
MAT * makeHQ(MAT *A, VEC *diag1, VEC *diag2, MAT *Qout)
MAT * schur(MAT *A, MAT *Q)
Definition: schur.c:155
VEC * QRTsolve(MAT *A, VEC *, VEC *b, VEC *x)
double LUcondest(MAT *A, PERM *pivot)
#define alpha
Definition: bkpfacto.c:43
VEC * Usolve(MAT *A, VEC *b, VEC *x, double diag_val)
void schur_evals(MAT *A, VEC *re_part, VEC *im_part)
Definition: schur.c:432
VEC * trieig(VEC *a, VEC *b, MAT *Q)
Definition: matrix.h:80
VEC * bdLDLsolve(BAND *A, VEC *b, VEC *x)
Definition: bdfactor.c:554
MAT * makeQ(MAT *A, VEC *diag, MAT *Qout)
MAT * schur_vecs(MAT *T, MAT *Q, MAT *X_re, MAT *X_im)
Definition: schur.c:488
MAT * LUfactor(MAT *A, PERM *pivot)
MAT * CHfactor(MAT *A)
MAT * makeR(MAT *A, MAT *Rout)
MAT * Hfactor(MAT *A, VEC *diag1, VEC *diag2)
MAT * QRupdate(MAT *Q, MAT *R, VEC *u, VEC *v)
Definition: update.c:87
VEC * hhvec(VEC *, u_int, Real *, VEC *, Real *)
Definition: hsehldr.c:47
MAT * m_poly(MAT *, VEC *, MAT *)
Definition: mfunc.c:311
VEC * bisvd(VEC *a, VEC *b, MAT *U, MAT *V)
void fft(VEC *, VEC *)
Definition: fft.c:45
#define A(i)
Definition: multisplit.cpp:61
VEC * LDLsolve(MAT *A, VEC *b, VEC *x)
MAT * LDLupdate(MAT *A, VEC *u, double alpha)
VEC * hhtrvec(VEC *, double, u_int, VEC *, VEC *)
Definition: hsehldr.c:72
MAT * _m_exp(MAT *, double, MAT *, int *, int *)
Definition: mfunc.c:134
VEC * CHsolve(MAT *A, VEC *b, VEC *x)
VEC * Dsolve(MAT *A, VEC *b, VEC *x)
MAT * m_exp(MAT *, double, MAT *)
Definition: mfunc.c:297
BAND * bdLUfactor(BAND *A, PERM *pivot)
MAT * m_pow(MAT *, int, MAT *)
Definition: mfunc.c:99
MAT * QRCPfactor(MAT *A, VEC *diag, PERM *pivot)
VEC * Lsolve(MAT *A, VEC *b, VEC *x, double diag_val)
Definition: matrix.h:87
Definition: matrix.h:73