gsl_linalg.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585
  1. /* linalg/gsl_linalg.h
  2. *
  3. * Copyright (C) 1996, 1997, 1998, 1999, 2000, 2006, 2007 Gerard Jungman, Brian Gough, Patrick Alken
  4. *
  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.
  9. *
  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.
  14. *
  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.
  18. */
  19. #ifndef __GSL_LINALG_H__
  20. #define __GSL_LINALG_H__
  21. #include "gsl_mode.h"
  22. #include "gsl_permutation.h"
  23. #include "gsl_vector.h"
  24. #include "gsl_matrix.h"
  25. #undef __BEGIN_DECLS
  26. #undef __END_DECLS
  27. #ifdef __cplusplus
  28. #define __BEGIN_DECLS extern "C" {
  29. #define __END_DECLS }
  30. #else
  31. #define __BEGIN_DECLS /* empty */
  32. #define __END_DECLS /* empty */
  33. #endif
  34. __BEGIN_DECLS
  35. typedef enum
  36. {
  37. GSL_LINALG_MOD_NONE = 0,
  38. GSL_LINALG_MOD_TRANSPOSE = 1,
  39. GSL_LINALG_MOD_CONJUGATE = 2
  40. }
  41. gsl_linalg_matrix_mod_t;
  42. /* Note: You can now use the gsl_blas_dgemm function instead of matmult */
  43. /* Simple implementation of matrix multiply.
  44. * Calculates C = A.B
  45. *
  46. * exceptions: GSL_EBADLEN
  47. */
  48. int gsl_linalg_matmult (const gsl_matrix * A,
  49. const gsl_matrix * B,
  50. gsl_matrix * C);
  51. /* Simple implementation of matrix multiply.
  52. * Allows transposition of either matrix, so it
  53. * can compute A.B or Trans(A).B or A.Trans(B) or Trans(A).Trans(B)
  54. *
  55. * exceptions: GSL_EBADLEN
  56. */
  57. int gsl_linalg_matmult_mod (const gsl_matrix * A,
  58. gsl_linalg_matrix_mod_t modA,
  59. const gsl_matrix * B,
  60. gsl_linalg_matrix_mod_t modB,
  61. gsl_matrix * C);
  62. /* Calculate the matrix exponential by the scaling and
  63. * squaring method described in Moler + Van Loan,
  64. * SIAM Rev 20, 801 (1978). The mode argument allows
  65. * choosing an optimal strategy, from the table
  66. * given in the paper, for a given precision.
  67. *
  68. * exceptions: GSL_ENOTSQR, GSL_EBADLEN
  69. */
  70. int gsl_linalg_exponential_ss(
  71. const gsl_matrix * A,
  72. gsl_matrix * eA,
  73. gsl_mode_t mode
  74. );
  75. /* Householder Transformations */
  76. double gsl_linalg_householder_transform (gsl_vector * v);
  77. gsl_complex gsl_linalg_complex_householder_transform (gsl_vector_complex * v);
  78. int gsl_linalg_householder_hm (double tau,
  79. const gsl_vector * v,
  80. gsl_matrix * A);
  81. int gsl_linalg_householder_mh (double tau,
  82. const gsl_vector * v,
  83. gsl_matrix * A);
  84. int gsl_linalg_householder_hv (double tau,
  85. const gsl_vector * v,
  86. gsl_vector * w);
  87. int gsl_linalg_householder_hm1 (double tau,
  88. gsl_matrix * A);
  89. int gsl_linalg_complex_householder_hm (gsl_complex tau,
  90. const gsl_vector_complex * v,
  91. gsl_matrix_complex * A);
  92. int gsl_linalg_complex_householder_mh (gsl_complex tau,
  93. const gsl_vector_complex * v,
  94. gsl_matrix_complex * A);
  95. int gsl_linalg_complex_householder_hv (gsl_complex tau,
  96. const gsl_vector_complex * v,
  97. gsl_vector_complex * w);
  98. /* Hessenberg reduction */
  99. int gsl_linalg_hessenberg_decomp(gsl_matrix *A, gsl_vector *tau);
  100. int gsl_linalg_hessenberg_unpack(gsl_matrix * H, gsl_vector * tau,
  101. gsl_matrix * U);
  102. int gsl_linalg_hessenberg_unpack_accum(gsl_matrix * H, gsl_vector * tau,
  103. gsl_matrix * U);
  104. int gsl_linalg_hessenberg_set_zero(gsl_matrix * H);
  105. int gsl_linalg_hessenberg_submatrix(gsl_matrix *M, gsl_matrix *A,
  106. size_t top, gsl_vector *tau);
  107. /* Hessenberg-Triangular reduction */
  108. int gsl_linalg_hesstri_decomp(gsl_matrix * A, gsl_matrix * B,
  109. gsl_matrix * U, gsl_matrix * V,
  110. gsl_vector * work);
  111. /* Singular Value Decomposition
  112. * exceptions:
  113. */
  114. int
  115. gsl_linalg_SV_decomp (gsl_matrix * A,
  116. gsl_matrix * V,
  117. gsl_vector * S,
  118. gsl_vector * work);
  119. int
  120. gsl_linalg_SV_decomp_mod (gsl_matrix * A,
  121. gsl_matrix * X,
  122. gsl_matrix * V,
  123. gsl_vector * S,
  124. gsl_vector * work);
  125. int gsl_linalg_SV_decomp_jacobi (gsl_matrix * A,
  126. gsl_matrix * Q,
  127. gsl_vector * S);
  128. int
  129. gsl_linalg_SV_solve (const gsl_matrix * U,
  130. const gsl_matrix * Q,
  131. const gsl_vector * S,
  132. const gsl_vector * b,
  133. gsl_vector * x);
  134. /* LU Decomposition, Gaussian elimination with partial pivoting
  135. */
  136. int gsl_linalg_LU_decomp (gsl_matrix * A, gsl_permutation * p, int *signum);
  137. int gsl_linalg_LU_solve (const gsl_matrix * LU,
  138. const gsl_permutation * p,
  139. const gsl_vector * b,
  140. gsl_vector * x);
  141. int gsl_linalg_LU_svx (const gsl_matrix * LU,
  142. const gsl_permutation * p,
  143. gsl_vector * x);
  144. int gsl_linalg_LU_refine (const gsl_matrix * A,
  145. const gsl_matrix * LU,
  146. const gsl_permutation * p,
  147. const gsl_vector * b,
  148. gsl_vector * x,
  149. gsl_vector * residual);
  150. int gsl_linalg_LU_invert (const gsl_matrix * LU,
  151. const gsl_permutation * p,
  152. gsl_matrix * inverse);
  153. double gsl_linalg_LU_det (gsl_matrix * LU, int signum);
  154. double gsl_linalg_LU_lndet (gsl_matrix * LU);
  155. int gsl_linalg_LU_sgndet (gsl_matrix * lu, int signum);
  156. /* Complex LU Decomposition */
  157. int gsl_linalg_complex_LU_decomp (gsl_matrix_complex * A,
  158. gsl_permutation * p,
  159. int *signum);
  160. int gsl_linalg_complex_LU_solve (const gsl_matrix_complex * LU,
  161. const gsl_permutation * p,
  162. const gsl_vector_complex * b,
  163. gsl_vector_complex * x);
  164. int gsl_linalg_complex_LU_svx (const gsl_matrix_complex * LU,
  165. const gsl_permutation * p,
  166. gsl_vector_complex * x);
  167. int gsl_linalg_complex_LU_refine (const gsl_matrix_complex * A,
  168. const gsl_matrix_complex * LU,
  169. const gsl_permutation * p,
  170. const gsl_vector_complex * b,
  171. gsl_vector_complex * x,
  172. gsl_vector_complex * residual);
  173. int gsl_linalg_complex_LU_invert (const gsl_matrix_complex * LU,
  174. const gsl_permutation * p,
  175. gsl_matrix_complex * inverse);
  176. gsl_complex gsl_linalg_complex_LU_det (gsl_matrix_complex * LU,
  177. int signum);
  178. double gsl_linalg_complex_LU_lndet (gsl_matrix_complex * LU);
  179. gsl_complex gsl_linalg_complex_LU_sgndet (gsl_matrix_complex * LU,
  180. int signum);
  181. /* QR decomposition */
  182. int gsl_linalg_QR_decomp (gsl_matrix * A,
  183. gsl_vector * tau);
  184. int gsl_linalg_QR_solve (const gsl_matrix * QR,
  185. const gsl_vector * tau,
  186. const gsl_vector * b,
  187. gsl_vector * x);
  188. int gsl_linalg_QR_svx (const gsl_matrix * QR,
  189. const gsl_vector * tau,
  190. gsl_vector * x);
  191. int gsl_linalg_QR_lssolve (const gsl_matrix * QR,
  192. const gsl_vector * tau,
  193. const gsl_vector * b,
  194. gsl_vector * x,
  195. gsl_vector * residual);
  196. int gsl_linalg_QR_QRsolve (gsl_matrix * Q,
  197. gsl_matrix * R,
  198. const gsl_vector * b,
  199. gsl_vector * x);
  200. int gsl_linalg_QR_Rsolve (const gsl_matrix * QR,
  201. const gsl_vector * b,
  202. gsl_vector * x);
  203. int gsl_linalg_QR_Rsvx (const gsl_matrix * QR,
  204. gsl_vector * x);
  205. int gsl_linalg_QR_update (gsl_matrix * Q,
  206. gsl_matrix * R,
  207. gsl_vector * w,
  208. const gsl_vector * v);
  209. int gsl_linalg_QR_QTvec (const gsl_matrix * QR,
  210. const gsl_vector * tau,
  211. gsl_vector * v);
  212. int gsl_linalg_QR_Qvec (const gsl_matrix * QR,
  213. const gsl_vector * tau,
  214. gsl_vector * v);
  215. int gsl_linalg_QR_QTmat (const gsl_matrix * QR,
  216. const gsl_vector * tau,
  217. gsl_matrix * A);
  218. int gsl_linalg_QR_unpack (const gsl_matrix * QR,
  219. const gsl_vector * tau,
  220. gsl_matrix * Q,
  221. gsl_matrix * R);
  222. int gsl_linalg_R_solve (const gsl_matrix * R,
  223. const gsl_vector * b,
  224. gsl_vector * x);
  225. int gsl_linalg_R_svx (const gsl_matrix * R,
  226. gsl_vector * x);
  227. /* Q R P^T decomposition */
  228. int gsl_linalg_QRPT_decomp (gsl_matrix * A,
  229. gsl_vector * tau,
  230. gsl_permutation * p,
  231. int *signum,
  232. gsl_vector * norm);
  233. int gsl_linalg_QRPT_decomp2 (const gsl_matrix * A,
  234. gsl_matrix * q, gsl_matrix * r,
  235. gsl_vector * tau,
  236. gsl_permutation * p,
  237. int *signum,
  238. gsl_vector * norm);
  239. int gsl_linalg_QRPT_solve (const gsl_matrix * QR,
  240. const gsl_vector * tau,
  241. const gsl_permutation * p,
  242. const gsl_vector * b,
  243. gsl_vector * x);
  244. int gsl_linalg_QRPT_svx (const gsl_matrix * QR,
  245. const gsl_vector * tau,
  246. const gsl_permutation * p,
  247. gsl_vector * x);
  248. int gsl_linalg_QRPT_QRsolve (const gsl_matrix * Q,
  249. const gsl_matrix * R,
  250. const gsl_permutation * p,
  251. const gsl_vector * b,
  252. gsl_vector * x);
  253. int gsl_linalg_QRPT_Rsolve (const gsl_matrix * QR,
  254. const gsl_permutation * p,
  255. const gsl_vector * b,
  256. gsl_vector * x);
  257. int gsl_linalg_QRPT_Rsvx (const gsl_matrix * QR,
  258. const gsl_permutation * p,
  259. gsl_vector * x);
  260. int gsl_linalg_QRPT_update (gsl_matrix * Q,
  261. gsl_matrix * R,
  262. const gsl_permutation * p,
  263. gsl_vector * u,
  264. const gsl_vector * v);
  265. /* LQ decomposition */
  266. int gsl_linalg_LQ_decomp (gsl_matrix * A, gsl_vector * tau);
  267. int gsl_linalg_LQ_solve_T (const gsl_matrix * LQ, const gsl_vector * tau,
  268. const gsl_vector * b, gsl_vector * x);
  269. int gsl_linalg_LQ_svx_T (const gsl_matrix * LQ, const gsl_vector * tau,
  270. gsl_vector * x);
  271. int gsl_linalg_LQ_lssolve_T (const gsl_matrix * LQ, const gsl_vector * tau,
  272. const gsl_vector * b, gsl_vector * x,
  273. gsl_vector * residual);
  274. int gsl_linalg_LQ_Lsolve_T (const gsl_matrix * LQ, const gsl_vector * b,
  275. gsl_vector * x);
  276. int gsl_linalg_LQ_Lsvx_T (const gsl_matrix * LQ, gsl_vector * x);
  277. int gsl_linalg_L_solve_T (const gsl_matrix * L, const gsl_vector * b,
  278. gsl_vector * x);
  279. int gsl_linalg_LQ_vecQ (const gsl_matrix * LQ, const gsl_vector * tau,
  280. gsl_vector * v);
  281. int gsl_linalg_LQ_vecQT (const gsl_matrix * LQ, const gsl_vector * tau,
  282. gsl_vector * v);
  283. int gsl_linalg_LQ_unpack (const gsl_matrix * LQ, const gsl_vector * tau,
  284. gsl_matrix * Q, gsl_matrix * L);
  285. int gsl_linalg_LQ_update (gsl_matrix * Q, gsl_matrix * R,
  286. const gsl_vector * v, gsl_vector * w);
  287. int gsl_linalg_LQ_LQsolve (gsl_matrix * Q, gsl_matrix * L,
  288. const gsl_vector * b, gsl_vector * x);
  289. /* P^T L Q decomposition */
  290. int gsl_linalg_PTLQ_decomp (gsl_matrix * A, gsl_vector * tau,
  291. gsl_permutation * p, int *signum,
  292. gsl_vector * norm);
  293. int gsl_linalg_PTLQ_decomp2 (const gsl_matrix * A, gsl_matrix * q,
  294. gsl_matrix * r, gsl_vector * tau,
  295. gsl_permutation * p, int *signum,
  296. gsl_vector * norm);
  297. int gsl_linalg_PTLQ_solve_T (const gsl_matrix * QR,
  298. const gsl_vector * tau,
  299. const gsl_permutation * p,
  300. const gsl_vector * b,
  301. gsl_vector * x);
  302. int gsl_linalg_PTLQ_svx_T (const gsl_matrix * LQ,
  303. const gsl_vector * tau,
  304. const gsl_permutation * p,
  305. gsl_vector * x);
  306. int gsl_linalg_PTLQ_LQsolve_T (const gsl_matrix * Q, const gsl_matrix * L,
  307. const gsl_permutation * p,
  308. const gsl_vector * b,
  309. gsl_vector * x);
  310. int gsl_linalg_PTLQ_Lsolve_T (const gsl_matrix * LQ,
  311. const gsl_permutation * p,
  312. const gsl_vector * b,
  313. gsl_vector * x);
  314. int gsl_linalg_PTLQ_Lsvx_T (const gsl_matrix * LQ,
  315. const gsl_permutation * p,
  316. gsl_vector * x);
  317. int gsl_linalg_PTLQ_update (gsl_matrix * Q, gsl_matrix * L,
  318. const gsl_permutation * p,
  319. const gsl_vector * v, gsl_vector * w);
  320. /* Cholesky Decomposition */
  321. int gsl_linalg_cholesky_decomp (gsl_matrix * A);
  322. int gsl_linalg_cholesky_solve (const gsl_matrix * cholesky,
  323. const gsl_vector * b,
  324. gsl_vector * x);
  325. int gsl_linalg_cholesky_svx (const gsl_matrix * cholesky,
  326. gsl_vector * x);
  327. /* Cholesky decomposition with unit-diagonal triangular parts.
  328. * A = L D L^T, where diag(L) = (1,1,...,1).
  329. * Upon exit, A contains L and L^T as for Cholesky, and
  330. * the diagonal of A is (1,1,...,1). The vector Dis set
  331. * to the diagonal elements of the diagonal matrix D.
  332. */
  333. int gsl_linalg_cholesky_decomp_unit(gsl_matrix * A, gsl_vector * D);
  334. /* Complex Cholesky Decomposition */
  335. int gsl_linalg_complex_cholesky_decomp (gsl_matrix_complex * A);
  336. int gsl_linalg_complex_cholesky_solve (const gsl_matrix_complex * cholesky,
  337. const gsl_vector_complex * b,
  338. gsl_vector_complex * x);
  339. int gsl_linalg_complex_cholesky_svx (const gsl_matrix_complex * cholesky,
  340. gsl_vector_complex * x);
  341. /* Symmetric to symmetric tridiagonal decomposition */
  342. int gsl_linalg_symmtd_decomp (gsl_matrix * A,
  343. gsl_vector * tau);
  344. int gsl_linalg_symmtd_unpack (const gsl_matrix * A,
  345. const gsl_vector * tau,
  346. gsl_matrix * Q,
  347. gsl_vector * diag,
  348. gsl_vector * subdiag);
  349. int gsl_linalg_symmtd_unpack_T (const gsl_matrix * A,
  350. gsl_vector * diag,
  351. gsl_vector * subdiag);
  352. /* Hermitian to symmetric tridiagonal decomposition */
  353. int gsl_linalg_hermtd_decomp (gsl_matrix_complex * A,
  354. gsl_vector_complex * tau);
  355. int gsl_linalg_hermtd_unpack (const gsl_matrix_complex * A,
  356. const gsl_vector_complex * tau,
  357. gsl_matrix_complex * Q,
  358. gsl_vector * diag,
  359. gsl_vector * sudiag);
  360. int gsl_linalg_hermtd_unpack_T (const gsl_matrix_complex * A,
  361. gsl_vector * diag,
  362. gsl_vector * subdiag);
  363. /* Linear Solve Using Householder Transformations
  364. * exceptions:
  365. */
  366. int gsl_linalg_HH_solve (gsl_matrix * A, const gsl_vector * b, gsl_vector * x);
  367. int gsl_linalg_HH_svx (gsl_matrix * A, gsl_vector * x);
  368. /* Linear solve for a symmetric tridiagonal system.
  369. * The input vectors represent the NxN matrix as follows:
  370. *
  371. * diag[0] offdiag[0] 0 ...
  372. * offdiag[0] diag[1] offdiag[1] ...
  373. * 0 offdiag[1] diag[2] ...
  374. * 0 0 offdiag[2] ...
  375. * ... ... ... ...
  376. */
  377. int gsl_linalg_solve_symm_tridiag (const gsl_vector * diag,
  378. const gsl_vector * offdiag,
  379. const gsl_vector * b,
  380. gsl_vector * x);
  381. /* Linear solve for a nonsymmetric tridiagonal system.
  382. * The input vectors represent the NxN matrix as follows:
  383. *
  384. * diag[0] abovediag[0] 0 ...
  385. * belowdiag[0] diag[1] abovediag[1] ...
  386. * 0 belowdiag[1] diag[2] ...
  387. * 0 0 belowdiag[2] ...
  388. * ... ... ... ...
  389. */
  390. int gsl_linalg_solve_tridiag (const gsl_vector * diag,
  391. const gsl_vector * abovediag,
  392. const gsl_vector * belowdiag,
  393. const gsl_vector * b,
  394. gsl_vector * x);
  395. /* Linear solve for a symmetric cyclic tridiagonal system.
  396. * The input vectors represent the NxN matrix as follows:
  397. *
  398. * diag[0] offdiag[0] 0 ..... offdiag[N-1]
  399. * offdiag[0] diag[1] offdiag[1] .....
  400. * 0 offdiag[1] diag[2] .....
  401. * 0 0 offdiag[2] .....
  402. * ... ...
  403. * offdiag[N-1] ...
  404. */
  405. int gsl_linalg_solve_symm_cyc_tridiag (const gsl_vector * diag,
  406. const gsl_vector * offdiag,
  407. const gsl_vector * b,
  408. gsl_vector * x);
  409. /* Linear solve for a nonsymmetric cyclic tridiagonal system.
  410. * The input vectors represent the NxN matrix as follows:
  411. *
  412. * diag[0] abovediag[0] 0 ..... belowdiag[N-1]
  413. * belowdiag[0] diag[1] abovediag[1] .....
  414. * 0 belowdiag[1] diag[2]
  415. * 0 0 belowdiag[2] .....
  416. * ... ...
  417. * abovediag[N-1] ...
  418. */
  419. int gsl_linalg_solve_cyc_tridiag (const gsl_vector * diag,
  420. const gsl_vector * abovediag,
  421. const gsl_vector * belowdiag,
  422. const gsl_vector * b,
  423. gsl_vector * x);
  424. /* Bidiagonal decomposition */
  425. int gsl_linalg_bidiag_decomp (gsl_matrix * A,
  426. gsl_vector * tau_U,
  427. gsl_vector * tau_V);
  428. int gsl_linalg_bidiag_unpack (const gsl_matrix * A,
  429. const gsl_vector * tau_U,
  430. gsl_matrix * U,
  431. const gsl_vector * tau_V,
  432. gsl_matrix * V,
  433. gsl_vector * diag,
  434. gsl_vector * superdiag);
  435. int gsl_linalg_bidiag_unpack2 (gsl_matrix * A,
  436. gsl_vector * tau_U,
  437. gsl_vector * tau_V,
  438. gsl_matrix * V);
  439. int gsl_linalg_bidiag_unpack_B (const gsl_matrix * A,
  440. gsl_vector * diag,
  441. gsl_vector * superdiag);
  442. /* Balancing */
  443. int gsl_linalg_balance_matrix (gsl_matrix * A, gsl_vector * D);
  444. int gsl_linalg_balance_accum (gsl_matrix * A, gsl_vector * D);
  445. int gsl_linalg_balance_columns (gsl_matrix * A, gsl_vector * D);
  446. __END_DECLS
  447. #endif /* __GSL_LINALG_H__ */