GNU Scientific Library
Reference Manual
Edition 1.14, for GSL Version 1.14
10 March 2010
Mark Galassi
Los Alamos National Laboratory
Jim Davies
Department of Computer Science, Georgia Institute of Technology
James Theiler
Astrophysics and Radiation Measurements Group, Los Alamos National Laboratory
Brian Gough
Network Theory Limited
Gerard Jungman
Theoretical Astrophysics Group, Los Alamos National Laboratory
Patrick Alken
Department of Physics, University of Colorado at Boulder
Michael Booth
Department of Physics and Astronomy, The Johns Hopkins University
Fabrice Rossi
University of Paris-Dauphine
Copyright c 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
2009, 2010 The GSL Team.
Permission is granted to copy, distribute and/or modify this document under the terms of
the GNU Free Documentation License, Version 1.3 or any later version published by the Free
Software Foundation; with the Invariant Sections being “GNU General Public License” and
“Free Software Needs Free Documentation”, the Front-Cover text being “A GNU Manual”,
and with the Back-Cover Text being (a) (see below). A copy of the license is included in
the section entitled “GNU Free Documentation License”.
(a) The Back-Cover Text is: “You have the freedom to copy and modify this GNU
Manual.” Printed copies of this manual can be purchased from Network Theory Ltd at
http://www.network-theory.co.uk/gsl/manual/.
The money raised from sales of the manual helps support the development of GSL.
i
Table of Contents
1
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.1 Routines available in GSL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.2 GSL is Free Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.3 Obtaining GSL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.4 No Warranty . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.5 Reporting Bugs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.6 Further Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.7 Conventions used in this manual. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2 Using the library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2.1 An Example Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2.2 Compiling and Linking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2.2.1 Linking programs with the library . . . . . . . . . . . . . . . . . . . . . . . . . 4
2.2.2 Linking with an alternative BLAS library . . . . . . . . . . . . . . . . . . 5
2.3 Shared Libraries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2.4 ANSI C Compliance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2.5
Inline functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2.6 Long double. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2.7 Portability functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
2.8 Alternative optimized functions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
2.9 Support for different numeric types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
2.10 Compatibility with C++ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
2.11 Aliasing of arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
2.12 Thread-safety . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
2.13 Deprecated Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
2.14 Code Reuse . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
3 Error Handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
3.1 Error Reporting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
3.2 Error Codes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
3.3 Error Handlers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
3.4 Using GSL error reporting in your own functions . . . . . . . . . . . . . . 13
3.5 Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
4 Mathematical Functions . . . . . . . . . . . . . . . . . . . . . . 16
4.1 Mathematical Constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
4.2
Infinities and Not-a-number . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
4.3 Elementary Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
4.4 Small integer powers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
4.5 Testing the Sign of Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
4.6 Testing for Odd and Even Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
4.7 Maximum and Minimum functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
4.8 Approximate Comparison of Floating Point Numbers . . . . . . . . . . 19
ii
5 Complex Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
5.1 Representation of complex numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
5.2 Properties of complex numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
5.3 Complex arithmetic operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
5.4 Elementary Complex Functions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
5.5 Complex Trigonometric Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
5.6
Inverse Complex Trigonometric Functions . . . . . . . . . . . . . . . . . . . . . 24
5.7 Complex Hyperbolic Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
5.8
Inverse Complex Hyperbolic Functions . . . . . . . . . . . . . . . . . . . . . . . . 26
5.9 References and Further Reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
6 Polynomials . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
6.1 Polynomial Evaluation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
6.2 Divided Difference Representation of Polynomials . . . . . . . . . . . . . . 28
6.3 Quadratic Equations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
6.4 Cubic Equations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
6.5 General Polynomial Equations. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
6.6 Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
6.7 References and Further Reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
7 Special Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
7.1 Usage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
7.2 The gsl sf result struct . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
7.3 Modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
7.4 Airy Functions and Derivatives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
7.4.1 Airy Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
7.4.2 Derivatives of Airy Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
7.4.3 Zeros of Airy Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
7.4.4 Zeros of Derivatives of Airy Functions . . . . . . . . . . . . . . . . . . . . 36
7.5 Bessel Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
7.5.1 Regular Cylindrical Bessel Functions . . . . . . . . . . . . . . . . . . . . . 36
7.5.2
Irregular Cylindrical Bessel Functions. . . . . . . . . . . . . . . . . . . . . 37
7.5.3 Regular Modified Cylindrical Bessel Functions . . . . . . . . . . . . 37
7.5.4
Irregular Modified Cylindrical Bessel Functions . . . . . . . . . . . 38
7.5.5 Regular Spherical Bessel Functions . . . . . . . . . . . . . . . . . . . . . . . 39
7.5.6
Irregular Spherical Bessel Functions . . . . . . . . . . . . . . . . . . . . . . 40
7.5.7 Regular Modified Spherical Bessel Functions . . . . . . . . . . . . . . 40
7.5.8
Irregular Modified Spherical Bessel Functions . . . . . . . . . . . . . 41
7.5.9 Regular Bessel Function—Fractional Order . . . . . . . . . . . . . . . 42
7.5.10
Irregular Bessel Functions—Fractional Order . . . . . . . . . . . . 42
7.5.11 Regular Modified Bessel Functions—Fractional Order . . . . 42
7.5.12
Irregular Modified Bessel Functions—Fractional Order . . . 42
7.5.13 Zeros of Regular Bessel Functions . . . . . . . . . . . . . . . . . . . . . . . 43
7.6 Clausen Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
7.7 Coulomb Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
7.7.1 Normalized Hydrogenic Bound States . . . . . . . . . . . . . . . . . . . . . 44
7.7.2 Coulomb Wave Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
iii
7.8.1
7.8.2
7.8.3
7.7.3 Coulomb Wave Function Normalization Constant . . . . . . . . . 45
7.8 Coupling Coefficients . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
3-j Symbols . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
6-j Symbols . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
9-j Symbols . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
7.9 Dawson Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
7.10 Debye Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
7.11 Dilogarithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
7.11.1 Real Argument. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
7.11.2 Complex Argument . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
7.12 Elementary Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
7.13 Elliptic Integrals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
7.13.1 Definition of Legendre Forms . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
7.13.2 Definition of Carlson Forms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
7.13.3 Legendre Form of Complete Elliptic Integrals . . . . . . . . . . . . 49
7.13.4 Legendre Form of Incomplete Elliptic Integrals . . . . . . . . . . 49
7.13.5 Carlson Forms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
7.14 Elliptic Functions (Jacobi) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
7.15 Error Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
7.15.1 Error Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
7.15.2 Complementary Error Function . . . . . . . . . . . . . . . . . . . . . . . . . 51
7.15.3 Log Complementary Error Function . . . . . . . . . . . . . . . . . . . . . 51
7.15.4 Probability functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
7.16 Exponential Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
7.16.1 Exponential Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
7.16.2 Relative Exponential Functions . . . . . . . . . . . . . . . . . . . . . . . . . . 52
7.16.3 Exponentiation With Error Estimate . . . . . . . . . . . . . . . . . . . . 53
7.17 Exponential Integrals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
7.17.1 Exponential Integral . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
7.17.2 Ei(x) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
7.17.3 Hyperbolic Integrals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
7.17.4 Ei 3(x) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
7.17.5 Trigonometric Integrals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
7.17.6 Arctangent Integral . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
7.18 Fermi-Dirac Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
7.18.1 Complete Fermi-Dirac Integrals . . . . . . . . . . . . . . . . . . . . . . . . . 55
7.18.2
Incomplete Fermi-Dirac Integrals . . . . . . . . . . . . . . . . . . . . . . . . 56
7.19 Gamma and Beta Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
7.19.1 Gamma Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
7.19.2 Factorials . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
7.19.3 Pochhammer Symbol . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
7.19.4
Incomplete Gamma Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
7.19.5 Beta Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
Incomplete Beta Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
7.19.6
7.20 Gegenbauer Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
7.21 Hypergeometric Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
7.22 Laguerre Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
7.23 Lambert W Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
iv
7.24 Legendre Functions and Spherical Harmonics . . . . . . . . . . . . . . . . . 63
7.24.1 Legendre Polynomials . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
7.24.2 Associated Legendre Polynomials and Spherical Harmonics
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
7.24.3 Conical Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
7.24.4 Radial Functions for Hyperbolic Space. . . . . . . . . . . . . . . . . . . 65
7.25 Logarithm and Related Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
7.26 Mathieu Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
7.26.1 Mathieu Function Workspace . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
7.26.2 Mathieu Function Characteristic Values . . . . . . . . . . . . . . . . . 67
7.26.3 Angular Mathieu Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
7.26.4 Radial Mathieu Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
7.27 Power Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
7.28 Psi (Digamma) Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
7.28.1 Digamma Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
7.28.2 Trigamma Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
7.28.3 Polygamma Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
7.29 Synchrotron Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
7.30 Transport Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
7.31 Trigonometric Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
7.31.1 Circular Trigonometric Functions . . . . . . . . . . . . . . . . . . . . . . . . 70
7.31.2 Trigonometric Functions for Complex Arguments . . . . . . . . 71
7.31.3 Hyperbolic Trigonometric Functions . . . . . . . . . . . . . . . . . . . . . 71
7.31.4 Conversion Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
7.31.5 Restriction Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
7.31.6 Trigonometric Functions With Error Estimates . . . . . . . . . . 72
7.32 Zeta Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
7.32.1 Riemann Zeta Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
7.32.2 Riemann Zeta Function Minus One . . . . . . . . . . . . . . . . . . . . . . 72
7.32.3 Hurwitz Zeta Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
7.32.4 Eta Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
7.33 Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
7.34 References and Further Reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
8 Vectors and Matrices . . . . . . . . . . . . . . . . . . . . . . . . . . 75
8.1 Data types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
8.2 Blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
8.2.1 Block allocation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
8.2.2 Reading and writing blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
8.2.3 Example programs for blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
8.3 Vectors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
8.3.1 Vector allocation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
8.3.2 Accessing vector elements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
8.3.3
Initializing vector elements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
8.3.4 Reading and writing vectors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
8.3.5 Vector views . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
8.3.6 Copying vectors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
8.3.7 Exchanging elements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
v
8.3.8 Vector operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
8.3.9 Finding maximum and minimum elements of vectors . . . . . . 84
8.3.10 Vector properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
8.3.11 Example programs for vectors . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
8.4 Matrices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
8.4.1 Matrix allocation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
8.4.2 Accessing matrix elements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
8.4.3
Initializing matrix elements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
8.4.4 Reading and writing matrices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
8.4.5 Matrix views . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
8.4.6 Creating row and column views . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
8.4.7 Copying matrices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
8.4.8 Copying rows and columns . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
8.4.9 Exchanging rows and columns . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
8.4.10 Matrix operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
8.4.11 Finding maximum and minimum elements of matrices . . . 95
8.4.12 Matrix properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
8.4.13 Example programs for matrices . . . . . . . . . . . . . . . . . . . . . . . . . . 96
8.5 References and Further Reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
9 Permutations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
9.1 The Permutation struct . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
9.2 Permutation allocation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
9.3 Accessing permutation elements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
9.4 Permutation properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
9.5 Permutation functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
9.6 Applying Permutations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
9.7 Reading and writing permutations . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
9.8 Permutations in cyclic form . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
9.9 Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
9.10 References and Further Reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
10 Combinations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
10.1 The Combination struct . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
10.2 Combination allocation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
10.3 Accessing combination elements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
10.4 Combination properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
10.5 Combination functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
10.6 Reading and writing combinations . . . . . . . . . . . . . . . . . . . . . . . . . . 108
10.7 Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
10.8 References and Further Reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110
vi
11 Multisets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
11.1 The Multiset struct . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
11.2 Multiset allocation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
11.3 Accessing multiset elements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112
11.4 Multiset properties. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112
11.5 Multiset functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112
11.6 Reading and writing multisets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112
11.7 Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
12 Sorting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116
12.1 Sorting objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116
12.2 Sorting vectors. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
12.3 Selecting the k smallest or largest elements . . . . . . . . . . . . . . . . . . 118
12.4 Computing the rank . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119
12.5 Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119
12.6 References and Further Reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
13 BLAS Support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122
13.1 GSL BLAS Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123
13.1.1 Level 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123
13.1.2 Level 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126
13.1.3 Level 3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129
13.2 Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132
13.3 References and Further Reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133
14 Linear Algebra . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134
14.1 LU Decomposition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134
14.2 QR Decomposition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136
14.3 QR Decomposition with Column Pivoting . . . . . . . . . . . . . . . . . . . 138
14.4 Singular Value Decomposition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
14.5 Cholesky Decomposition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140
14.6 Tridiagonal Decomposition of Real Symmetric Matrices . . . . . . 141
14.7 Tridiagonal Decomposition of Hermitian Matrices . . . . . . . . . . . 142
14.8 Hessenberg Decomposition of Real Matrices . . . . . . . . . . . . . . . . . 142
14.9 Hessenberg-Triangular Decomposition of Real Matrices . . . . . . 143
14.10 Bidiagonalization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143
14.11 Householder Transformations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144
14.12 Householder solver for linear systems . . . . . . . . . . . . . . . . . . . . . . . 145
14.13 Tridiagonal Systems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145
14.14 Balancing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146
14.15 Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147
14.16 References and Further Reading . . . . . . . . . . . . . . . . . . . . . . . . . . . 148