# gsl.lsp

Module index

## Module: gsl.lsp

Selected functions from the GNU Scientific Library

Version: 1.0 - initial release. Minimum newLISP version is 10.4.0.
Version: 1.1 - added check for extended ffi enabled version.
Version: 1.2 - changed ostype Win32 to Windows
Version: 1.3 - replaced 0.0 in CholeskyD with (float 0) for all locales
Author: Lutz Mueller 2012, 2014

## Module GSL For The GNU Scientific Library

The GSL GNU Scientific Library implements over a 1000 functions from different subject areas. In this release of the gsl.lsp module only a few linear algebra functions are implemented. To use this module, the main GSL library libgsl and a supporting library libgslcblas must be installed.

This module requires newLISP version 10.4.0 as a minimum. For 64-bit newLISP on Mac OSX, Linux and other Unix, 10.4.2 is the minimum.

Precompiled 32-bit and 64-bit libraries for the binary distributions i of newLISP versions are available in the http://www.nuevatec.com/GSL/ directory. See the INSTALL.txt file in that directory for instructions how to install the library files.

The module contains (test-gsl) to test all implemented functions.

§

### gsl:CholeskyD

syntax: (gsl:CholeskyD matrix-A)
parameter: matrix-A - A square matrix of m row vectors with n = m column elements each.

return: The matrix L .

The function performs a Cholesky decomposition of matrix-A. The matrix A must be symmetric and positive definite square.

A = L * Lt

Lt is the transposition of L.

Example:
``` (gsl:CholeskyD '((4 2 -2) (2 10 2) (-2 2 5)))

gsl:Cholesky-L =>

(  ( 2 0 0 )
( 1 3 0 )
(-1 1 1.732050808)  )
```

§

### gsl:Cholesky-solve

syntax: (gsl:Cholesky-solve matrix-A vector-b)
parameter: matrix-A - A square matrix of m row vectors with n = m column elements each.
Params: A vector of n elements.

return: Vector x containing a solution for Ax = b .

Example:
``` (gsl:Cholesky-solve '((4 2 -2) (2 10 2) (-2 2 5)) '(1 2 3))

=> (0.8333333333 -0.1666666667 1)
```

§

### gsl:QRD

syntax: (gsl:QRD matrix-A)
parameter: matrix-A - A list of m row vector lists with n column elements each.

return: Vector tau of k = min(n, m) elements.

The function does QR decomposition of a matrix A.

A = Q * R

The function works for both, square and rectangular matrices. The number of rows m in A must be equal to or greater than the number of columns n. The orthogonal m * m matrix Q can be found in the variable gsl:QR-Q. The m * n matrix R can be found in the variable gsl:QR-R.

Example:
``` (gsl:QRD '((12 -51 4) (6 167 -68) (-4 24 -41)) ) => (1.857142857 1.993846154 0)

gsl:QR-Q =>

(  ( 0.8571428571 -0.3942857143 -0.3314285714 )
( 0.4285714286  0.9028571429  0.03428571429)
(-0.2857142857  0.1714285714 -0.9428571429 )  )

gsl:QR-R =>

(  (14  21 -14 )
( 0 175 -70 )
( 0   0  35 )  )```

§

### gsl:QR-solve

syntax: (gsl:QR-solve matrix-A vector-b)
parameter: matrix-A - A matrix of m row vectors with n column elements each.
Params: A vector of n elements.

return: Vector x containing a solution for Ax = b .

Matrix A is either square or overdetermined with m > n, more rows than columns. When m > n, then the variable gsl:QR-residual contains a vector of residuals. For a square matrix A this vector contains 0's.

Example:
``` (gsl:QR-solve '((12 -51 4) (6 167 -68) (-4 24 -41)) '(1 2 3))

=> (0.009387755102 -0.02432653061 -0.08832653061)

(gsl:QR-solve '((1 2) (3 4) (5 6) (7 8)) '(1 2 3 4))
=> (9.690821045e-16 0.5)

gsl:QR-residual
=> (2.512815377e-17 1.103917396e-16 -2.961679405e-16 1.606480472e-16)```

§

### gsl:SVD

syntax: (gsl:SVD matrix-A)
parameter: matrix-A - A matrix of m row vectors with n column elements each.

return: A vector of diagonal elements from the S matrix.

The function does a SVD (Singular Value Decomposition) of the matrix-A into its components U, S and V. Matrix U is orthogonal m*n. S is a diagonal square matrix of n singular values. V is a n*n square orthogonal matrix. The function works for both, square and rectangular matrices.

A = U * S * Vt

Vt is the transposition of V.

The number of rows m in A must be equal to or greater than the number of columns n. The m*n matrix U can be found in the variable gsl:SVD-U. The diagonal elements of matrix S can be found in the vector variable gsl:SVD-S. The n*n matrix V can be found in the variable gsl:SVD-V.

Example:
``` (gsl:SVD '((1 2) (3 4) (5 6) (7 8))) => (14.2690955 0.6268282324)

gsl:SVD-U =>
(  (-0.1524832333 -0.8226474722 )
(-0.3499183718 -0.4213752877 )
(-0.5473535103 -0.02010310314)
(-0.7447886488  0.3811690814 )  )

gsl:SVD-S =>

(14.2690955 0.6268282324)

gsl:SVD-V =>

(  (-0.641423028   0.7671873951)
(-0.7671873951 -0.641423028 )  )```

§

### gsl:SVD-solve

syntax: (gsl:SVD-solve matrix-A vector-b)
parameter: matrix-A - A matrix of m row vectors with n column elements each.
Params: A vector of n elements

return: a vector x containing a solution for Ax = b .

The number of rows m in A must be equal to or greater than the number n of columns.

Example:
``` (gsl:SV-solve '((1 2) (3 4) (5 6) (7 8)) '(1 2 3 4))

=> (5.551115123e-16 0.5 0 0)
```

- ∂ -

generated with newLISP  and newLISPdoc