PsiLAB Help Manual
Page
Section:
Linear Algebra
Name:
LinAlg
Linear Algebra module.
This module provides several generic functions to solve linear equations, solving linear least square problems, and some special matrix operations. Matrix Inversion
LinAlg.inva a:(float, 'a, 'b) Matrix.t
LinAlg.invab a:(float, 'a, 'b) Matrix.t b:(float, 'a, 'b) Matrix.t
The inva function inverts the matrix a inplace using LAPACK's DGETRF and DEGTRI routines, and the inab function inverts matrix a and stores the result in the already allocated matrix b .
Matrix transpoition
LinAlg.transpose a:('a, 'b, 'c) Matrix.t
The transpose function transpose matrix a inplace. Supported formats: [ float, complex ] .
Solving linear equation systems
LinAlg.solve
a:(float, 'a, 'b) Matrix.t
b:(float, 'a, 'b) Matrix.t
x:(float, 'a, 'b) Matrix.t
This functions solves the linear equation
A * x = b
using LAPACK's DGESV routine with
A : Matrix of size (n,m)
b : Right hand side vector, size (n)
x : Solution vector, size (m)
Determinat of a matrix
[ d:float ] = LinAlg.detnn a:(float, 'a, 'b) Matrix.t
This function calculates the determinant of a square matrix a using LAPACK's DGETRF routine and returns the float value d .
Linear Least Square Problems
[ sig:float ] = LinAlg.lls
a:(float, 'a, 'b) Matrix.t
b:(float, 'a, 'b) Matrix.t
x:(float, 'a, 'b) Matrix.t
The lls function solves the minimization problem
minimize x || b - A * x || 2
using LAPACK's DGELS routine. It returns the standard deviation sigma. More special regression function based on this LLS can be found in the Reg module.
Examples:
[] let a = fmatrix ~const:[
(-1.0,1.0,2.0);
(3.0,-1.0,1.0);
(-1.0,3.0,4.0)] () ;;
[] print_fmat a ;;
| -1 1 2 |
| 3 -1 1 |
| -1 3 4 |
- : unit = ()
[] let b = fmatrix ~const:[2.0;6.0;4.0] () ;;
[] let x = fmatrix ~dim:[3] () ;;
[] LinAlg.solve a b x ;;
- : unit = ()
[] print_fmat x ;;
| 1 |
| -1 |
| 2 |
- : unit = ()
Printed by PsiLAB