3 * Copyright (C) 1996, 1997, 1998, 1999, 2000, 2006, 2007 Gerard Jungman, Brian Gough, Patrick Alken
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or (at
8 * your option) any later version.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 #ifndef __GSL_LINALG_H__
21 #define __GSL_LINALG_H__
23 #include <gsl/gsl_mode.h>
24 #include <gsl/gsl_permutation.h>
25 #include <gsl/gsl_vector.h>
26 #include <gsl/gsl_matrix.h>
31 #define __BEGIN_DECLS extern "C" {
34 #define __BEGIN_DECLS /* empty */
35 #define __END_DECLS /* empty */
42 GSL_LINALG_MOD_NONE = 0,
43 GSL_LINALG_MOD_TRANSPOSE = 1,
44 GSL_LINALG_MOD_CONJUGATE = 2
46 gsl_linalg_matrix_mod_t;
49 /* Note: You can now use the gsl_blas_dgemm function instead of matmult */
51 /* Simple implementation of matrix multiply.
54 * exceptions: GSL_EBADLEN
56 int gsl_linalg_matmult (const gsl_matrix * A,
61 /* Simple implementation of matrix multiply.
62 * Allows transposition of either matrix, so it
63 * can compute A.B or Trans(A).B or A.Trans(B) or Trans(A).Trans(B)
65 * exceptions: GSL_EBADLEN
67 int gsl_linalg_matmult_mod (const gsl_matrix * A,
68 gsl_linalg_matrix_mod_t modA,
70 gsl_linalg_matrix_mod_t modB,
73 /* Calculate the matrix exponential by the scaling and
74 * squaring method described in Moler + Van Loan,
75 * SIAM Rev 20, 801 (1978). The mode argument allows
76 * choosing an optimal strategy, from the table
77 * given in the paper, for a given precision.
79 * exceptions: GSL_ENOTSQR, GSL_EBADLEN
81 int gsl_linalg_exponential_ss(
88 /* Householder Transformations */
90 double gsl_linalg_householder_transform (gsl_vector * v);
91 gsl_complex gsl_linalg_complex_householder_transform (gsl_vector_complex * v);
93 int gsl_linalg_householder_hm (double tau,
97 int gsl_linalg_householder_mh (double tau,
101 int gsl_linalg_householder_hv (double tau,
102 const gsl_vector * v,
105 int gsl_linalg_householder_hm1 (double tau,
108 int gsl_linalg_complex_householder_hm (gsl_complex tau,
109 const gsl_vector_complex * v,
110 gsl_matrix_complex * A);
112 int gsl_linalg_complex_householder_mh (gsl_complex tau,
113 const gsl_vector_complex * v,
114 gsl_matrix_complex * A);
116 int gsl_linalg_complex_householder_hv (gsl_complex tau,
117 const gsl_vector_complex * v,
118 gsl_vector_complex * w);
120 /* Hessenberg reduction */
122 int gsl_linalg_hessenberg_decomp(gsl_matrix *A, gsl_vector *tau);
123 int gsl_linalg_hessenberg_unpack(gsl_matrix * H, gsl_vector * tau,
125 int gsl_linalg_hessenberg_unpack_accum(gsl_matrix * H, gsl_vector * tau,
127 int gsl_linalg_hessenberg_set_zero(gsl_matrix * H);
128 int gsl_linalg_hessenberg_submatrix(gsl_matrix *M, gsl_matrix *A,
129 size_t top, gsl_vector *tau);
131 /* To support gsl-1.9 interface: DEPRECATED */
132 int gsl_linalg_hessenberg(gsl_matrix *A, gsl_vector *tau);
135 /* Hessenberg-Triangular reduction */
137 int gsl_linalg_hesstri_decomp(gsl_matrix * A, gsl_matrix * B,
138 gsl_matrix * U, gsl_matrix * V,
141 /* Singular Value Decomposition
147 gsl_linalg_SV_decomp (gsl_matrix * A,
153 gsl_linalg_SV_decomp_mod (gsl_matrix * A,
159 int gsl_linalg_SV_decomp_jacobi (gsl_matrix * A,
164 gsl_linalg_SV_solve (const gsl_matrix * U,
165 const gsl_matrix * Q,
166 const gsl_vector * S,
167 const gsl_vector * b,
171 /* LU Decomposition, Gaussian elimination with partial pivoting
174 int gsl_linalg_LU_decomp (gsl_matrix * A, gsl_permutation * p, int *signum);
176 int gsl_linalg_LU_solve (const gsl_matrix * LU,
177 const gsl_permutation * p,
178 const gsl_vector * b,
181 int gsl_linalg_LU_svx (const gsl_matrix * LU,
182 const gsl_permutation * p,
185 int gsl_linalg_LU_refine (const gsl_matrix * A,
186 const gsl_matrix * LU,
187 const gsl_permutation * p,
188 const gsl_vector * b,
190 gsl_vector * residual);
192 int gsl_linalg_LU_invert (const gsl_matrix * LU,
193 const gsl_permutation * p,
194 gsl_matrix * inverse);
196 double gsl_linalg_LU_det (gsl_matrix * LU, int signum);
197 double gsl_linalg_LU_lndet (gsl_matrix * LU);
198 int gsl_linalg_LU_sgndet (gsl_matrix * lu, int signum);
200 /* Complex LU Decomposition */
202 int gsl_linalg_complex_LU_decomp (gsl_matrix_complex * A,
206 int gsl_linalg_complex_LU_solve (const gsl_matrix_complex * LU,
207 const gsl_permutation * p,
208 const gsl_vector_complex * b,
209 gsl_vector_complex * x);
211 int gsl_linalg_complex_LU_svx (const gsl_matrix_complex * LU,
212 const gsl_permutation * p,
213 gsl_vector_complex * x);
215 int gsl_linalg_complex_LU_refine (const gsl_matrix_complex * A,
216 const gsl_matrix_complex * LU,
217 const gsl_permutation * p,
218 const gsl_vector_complex * b,
219 gsl_vector_complex * x,
220 gsl_vector_complex * residual);
222 int gsl_linalg_complex_LU_invert (const gsl_matrix_complex * LU,
223 const gsl_permutation * p,
224 gsl_matrix_complex * inverse);
226 gsl_complex gsl_linalg_complex_LU_det (gsl_matrix_complex * LU,
229 double gsl_linalg_complex_LU_lndet (gsl_matrix_complex * LU);
231 gsl_complex gsl_linalg_complex_LU_sgndet (gsl_matrix_complex * LU,
234 /* QR decomposition */
236 int gsl_linalg_QR_decomp (gsl_matrix * A,
239 int gsl_linalg_QR_solve (const gsl_matrix * QR,
240 const gsl_vector * tau,
241 const gsl_vector * b,
244 int gsl_linalg_QR_svx (const gsl_matrix * QR,
245 const gsl_vector * tau,
248 int gsl_linalg_QR_lssolve (const gsl_matrix * QR,
249 const gsl_vector * tau,
250 const gsl_vector * b,
252 gsl_vector * residual);
255 int gsl_linalg_QR_QRsolve (gsl_matrix * Q,
257 const gsl_vector * b,
260 int gsl_linalg_QR_Rsolve (const gsl_matrix * QR,
261 const gsl_vector * b,
264 int gsl_linalg_QR_Rsvx (const gsl_matrix * QR,
267 int gsl_linalg_QR_update (gsl_matrix * Q,
270 const gsl_vector * v);
272 int gsl_linalg_QR_QTvec (const gsl_matrix * QR,
273 const gsl_vector * tau,
276 int gsl_linalg_QR_Qvec (const gsl_matrix * QR,
277 const gsl_vector * tau,
280 int gsl_linalg_QR_QTmat (const gsl_matrix * QR,
281 const gsl_vector * tau,
284 int gsl_linalg_QR_unpack (const gsl_matrix * QR,
285 const gsl_vector * tau,
289 int gsl_linalg_R_solve (const gsl_matrix * R,
290 const gsl_vector * b,
293 int gsl_linalg_R_svx (const gsl_matrix * R,
297 /* Q R P^T decomposition */
299 int gsl_linalg_QRPT_decomp (gsl_matrix * A,
305 int gsl_linalg_QRPT_decomp2 (const gsl_matrix * A,
306 gsl_matrix * q, gsl_matrix * r,
312 int gsl_linalg_QRPT_solve (const gsl_matrix * QR,
313 const gsl_vector * tau,
314 const gsl_permutation * p,
315 const gsl_vector * b,
319 int gsl_linalg_QRPT_svx (const gsl_matrix * QR,
320 const gsl_vector * tau,
321 const gsl_permutation * p,
324 int gsl_linalg_QRPT_QRsolve (const gsl_matrix * Q,
325 const gsl_matrix * R,
326 const gsl_permutation * p,
327 const gsl_vector * b,
330 int gsl_linalg_QRPT_Rsolve (const gsl_matrix * QR,
331 const gsl_permutation * p,
332 const gsl_vector * b,
335 int gsl_linalg_QRPT_Rsvx (const gsl_matrix * QR,
336 const gsl_permutation * p,
339 int gsl_linalg_QRPT_update (gsl_matrix * Q,
341 const gsl_permutation * p,
343 const gsl_vector * v);
345 /* LQ decomposition */
347 int gsl_linalg_LQ_decomp (gsl_matrix * A, gsl_vector * tau);
349 int gsl_linalg_LQ_solve_T (const gsl_matrix * LQ, const gsl_vector * tau,
350 const gsl_vector * b, gsl_vector * x);
352 int gsl_linalg_LQ_svx_T (const gsl_matrix * LQ, const gsl_vector * tau,
355 int gsl_linalg_LQ_lssolve_T (const gsl_matrix * LQ, const gsl_vector * tau,
356 const gsl_vector * b, gsl_vector * x,
357 gsl_vector * residual);
359 int gsl_linalg_LQ_Lsolve_T (const gsl_matrix * LQ, const gsl_vector * b,
362 int gsl_linalg_LQ_Lsvx_T (const gsl_matrix * LQ, gsl_vector * x);
364 int gsl_linalg_L_solve_T (const gsl_matrix * L, const gsl_vector * b,
367 int gsl_linalg_LQ_vecQ (const gsl_matrix * LQ, const gsl_vector * tau,
370 int gsl_linalg_LQ_vecQT (const gsl_matrix * LQ, const gsl_vector * tau,
373 int gsl_linalg_LQ_unpack (const gsl_matrix * LQ, const gsl_vector * tau,
374 gsl_matrix * Q, gsl_matrix * L);
376 int gsl_linalg_LQ_update (gsl_matrix * Q, gsl_matrix * R,
377 const gsl_vector * v, gsl_vector * w);
378 int gsl_linalg_LQ_LQsolve (gsl_matrix * Q, gsl_matrix * L,
379 const gsl_vector * b, gsl_vector * x);
381 /* P^T L Q decomposition */
383 int gsl_linalg_PTLQ_decomp (gsl_matrix * A, gsl_vector * tau,
384 gsl_permutation * p, int *signum,
387 int gsl_linalg_PTLQ_decomp2 (const gsl_matrix * A, gsl_matrix * q,
388 gsl_matrix * r, gsl_vector * tau,
389 gsl_permutation * p, int *signum,
392 int gsl_linalg_PTLQ_solve_T (const gsl_matrix * QR,
393 const gsl_vector * tau,
394 const gsl_permutation * p,
395 const gsl_vector * b,
398 int gsl_linalg_PTLQ_svx_T (const gsl_matrix * LQ,
399 const gsl_vector * tau,
400 const gsl_permutation * p,
403 int gsl_linalg_PTLQ_LQsolve_T (const gsl_matrix * Q, const gsl_matrix * L,
404 const gsl_permutation * p,
405 const gsl_vector * b,
408 int gsl_linalg_PTLQ_Lsolve_T (const gsl_matrix * LQ,
409 const gsl_permutation * p,
410 const gsl_vector * b,
413 int gsl_linalg_PTLQ_Lsvx_T (const gsl_matrix * LQ,
414 const gsl_permutation * p,
417 int gsl_linalg_PTLQ_update (gsl_matrix * Q, gsl_matrix * L,
418 const gsl_permutation * p,
419 const gsl_vector * v, gsl_vector * w);
421 /* Cholesky Decomposition */
423 int gsl_linalg_cholesky_decomp (gsl_matrix * A);
425 int gsl_linalg_cholesky_solve (const gsl_matrix * cholesky,
426 const gsl_vector * b,
429 int gsl_linalg_cholesky_svx (const gsl_matrix * cholesky,
433 /* Cholesky decomposition with unit-diagonal triangular parts.
434 * A = L D L^T, where diag(L) = (1,1,...,1).
435 * Upon exit, A contains L and L^T as for Cholesky, and
436 * the diagonal of A is (1,1,...,1). The vector Dis set
437 * to the diagonal elements of the diagonal matrix D.
439 int gsl_linalg_cholesky_decomp_unit(gsl_matrix * A, gsl_vector * D);
441 /* Complex Cholesky Decomposition */
443 int gsl_linalg_complex_cholesky_decomp (gsl_matrix_complex * A);
445 int gsl_linalg_complex_cholesky_solve (const gsl_matrix_complex * cholesky,
446 const gsl_vector_complex * b,
447 gsl_vector_complex * x);
449 int gsl_linalg_complex_cholesky_svx (const gsl_matrix_complex * cholesky,
450 gsl_vector_complex * x);
452 /* Symmetric to symmetric tridiagonal decomposition */
454 int gsl_linalg_symmtd_decomp (gsl_matrix * A,
457 int gsl_linalg_symmtd_unpack (const gsl_matrix * A,
458 const gsl_vector * tau,
461 gsl_vector * subdiag);
463 int gsl_linalg_symmtd_unpack_T (const gsl_matrix * A,
465 gsl_vector * subdiag);
467 /* Hermitian to symmetric tridiagonal decomposition */
469 int gsl_linalg_hermtd_decomp (gsl_matrix_complex * A,
470 gsl_vector_complex * tau);
472 int gsl_linalg_hermtd_unpack (const gsl_matrix_complex * A,
473 const gsl_vector_complex * tau,
474 gsl_matrix_complex * Q,
476 gsl_vector * sudiag);
478 int gsl_linalg_hermtd_unpack_T (const gsl_matrix_complex * A,
480 gsl_vector * subdiag);
482 /* Linear Solve Using Householder Transformations
487 int gsl_linalg_HH_solve (gsl_matrix * A, const gsl_vector * b, gsl_vector * x);
488 int gsl_linalg_HH_svx (gsl_matrix * A, gsl_vector * x);
490 /* Linear solve for a symmetric tridiagonal system.
492 * The input vectors represent the NxN matrix as follows:
494 * diag[0] offdiag[0] 0 ...
495 * offdiag[0] diag[1] offdiag[1] ...
496 * 0 offdiag[1] diag[2] ...
500 int gsl_linalg_solve_symm_tridiag (const gsl_vector * diag,
501 const gsl_vector * offdiag,
502 const gsl_vector * b,
505 /* Linear solve for a nonsymmetric tridiagonal system.
507 * The input vectors represent the NxN matrix as follows:
509 * diag[0] abovediag[0] 0 ...
510 * belowdiag[0] diag[1] abovediag[1] ...
511 * 0 belowdiag[1] diag[2] ...
512 * 0 0 belowdiag[2] ...
515 int gsl_linalg_solve_tridiag (const gsl_vector * diag,
516 const gsl_vector * abovediag,
517 const gsl_vector * belowdiag,
518 const gsl_vector * b,
522 /* Linear solve for a symmetric cyclic tridiagonal system.
524 * The input vectors represent the NxN matrix as follows:
526 * diag[0] offdiag[0] 0 ..... offdiag[N-1]
527 * offdiag[0] diag[1] offdiag[1] .....
528 * 0 offdiag[1] diag[2] .....
529 * 0 0 offdiag[2] .....
533 int gsl_linalg_solve_symm_cyc_tridiag (const gsl_vector * diag,
534 const gsl_vector * offdiag,
535 const gsl_vector * b,
538 /* Linear solve for a nonsymmetric cyclic tridiagonal system.
540 * The input vectors represent the NxN matrix as follows:
542 * diag[0] abovediag[0] 0 ..... belowdiag[N-1]
543 * belowdiag[0] diag[1] abovediag[1] .....
544 * 0 belowdiag[1] diag[2]
545 * 0 0 belowdiag[2] .....
549 int gsl_linalg_solve_cyc_tridiag (const gsl_vector * diag,
550 const gsl_vector * abovediag,
551 const gsl_vector * belowdiag,
552 const gsl_vector * b,
556 /* Bidiagonal decomposition */
558 int gsl_linalg_bidiag_decomp (gsl_matrix * A,
562 int gsl_linalg_bidiag_unpack (const gsl_matrix * A,
563 const gsl_vector * tau_U,
565 const gsl_vector * tau_V,
568 gsl_vector * superdiag);
570 int gsl_linalg_bidiag_unpack2 (gsl_matrix * A,
575 int gsl_linalg_bidiag_unpack_B (const gsl_matrix * A,
577 gsl_vector * superdiag);
581 int gsl_linalg_balance_matrix (gsl_matrix * A, gsl_vector * D);
582 int gsl_linalg_balance_accum (gsl_matrix * A, gsl_vector * D);
583 int gsl_linalg_balance_columns (gsl_matrix * A, gsl_vector * D);
588 #endif /* __GSL_LINALG_H__ */