A set of general purpose matrix functions. All functions are static. More...
#include "us_matrix.h"
Static Public Member Functions | |
static bool | lsfit (double *, double *, double *, int, int) |
Function to solve general linear least squares problem: More... | |
static bool | Cholesky_Decomposition (double **, int) |
Function to factor an n x n symmetric positive definite matrix. More... | |
static bool | Cholesky_SolveSystem (double **, double *, int) |
Function to solve a Cholesky-decomposed L-matrix. More... | |
static bool | Cholesky_Invert (double **, double **, int) |
Cholesky Invert to solve Ax=b by Cholesky decomposition. More... | |
static void | LU_SolveSystem (double **, double *&, int) |
Solve a set of linear equations. More... | |
static void | LU_Decomposition (double **, int *, bool, int) |
LU Decomposition of a matrix. More... | |
static void | LU_BackSubstitute (double **, double *&, int *, int) |
Back substitution on a matrix which is the LU decomposition of the original matrix. More... | |
static double ** | construct (QVector< double * > &, QVector< double > &, int, int) |
Create a matrix array from QVectors. More... | |
static void | tmm (double **, double **, int, int) |
Calculates A' * A , A-transpose times A. More... | |
static void | tmm (double **, double **, int, int, bool) |
Calculates A' * A: A-transpose times A. More... | |
static void | mvv (double **, double *, double *, int, int) |
Calculates A * b: a vector product whose size is A's rows. More... | |
static void | tvv (double **, double *, double *, int, int) |
Calculates A' * b: a vector product whose size is A's columns. More... | |
static void | mmm (double **, double **, double **, int, int, int) |
Calculates A * B: a matrix product of A-rows by B-columns. More... | |
static void | msum (double **, double **, double **, int, int) |
Calculate A + B: a matrix sum with all matrices rows x columns. More... | |
static void | vsum (double *, double *, double *, int) |
Calculate a + b: a vector sum with all vectors the same size. More... | |
static void | mident (double **, int) |
Fills matrix C: Cij = ( i != j ? 0.0 : 1.0 ) More... | |
static void | mcopy (double **, double **, int, int) |
Matrix copy: C = A. More... | |
static void | vcopy (double *, double *, int) |
Vector copy: c = a. More... | |
static void | add_diag (double **, double, int) |
Diagonal add: Cii = Cii + s. More... | |
static void | add (double **, double, int, int) |
Matrix-scalar-add: Cij += s. More... | |
static void | scale (double **, double, int, int) |
Matrix-scalar-multiply: Cij *= s. More... | |
static double | dotproduct (double *, double *, int) |
Vector dot product: p = sum( a[i] * b[i] ) More... | |
static double | dotproduct (double *, int) |
Vector dot product: p = sum( a[i] * a[i] ) More... | |
Static Private Member Functions | |
static void | print_matrix (double **, int, int) |
static void | print_vector (double *, int) |
A set of general purpose matrix functions. All functions are static.
A class of general purpose static matrix functions. The elements of all matrices and vectors are doubles. The matrix arguments are arrays of pointers to arrays of doubles (rows). The vector arguments are arrays of doubles.
Definition at line 14 of file us_matrix.h.
|
static |
Matrix-scalar-add: Cij += s.
Add a scalar to all elements of a matrix
CC | The source,destination matrix |
ss | The scalar to add to all elements |
rows | The number of rows in the matrix |
columns | The number of columns in the matrix |
Definition at line 373 of file us_matrix.cpp.
|
static |
Diagonal add: Cii = Cii + s.
Add a scalar to the diagonal of a square matrix
CC | The source,destination matrix |
ss | The scalar to add to the diagonal |
size | The size (rows, columns) of the matrix |
Definition at line 366 of file us_matrix.cpp.
|
static |
Function to factor an n x n symmetric positive definite matrix.
This method factors the n by n symmetric positive definite matrix A as LL(T) where L is a lower triangular matrix. The method assumes that at least the lower triangle of A is filled on entry. On exit, the lower triangle of A has been replaced by L.
a | Input symmetric positive definite matrix A; lower triangle replaced by L on exit. |
n | Dimensions of A. |
Definition at line 95 of file us_matrix.cpp.
|
static |
Cholesky Invert to solve Ax=b by Cholesky decomposition.
Cholesky Invert: solve Ax=b using Cholesky decomposition: A * A(-1) = I ; A = LL' ; L (L' * A(-1) ) = I ; L * y = I (solve for y) , now L' * A(-1) = y (solve for A(-1)) .
AA | An nn x nn input matrix |
AI | An nn x nn solved inverted matrix |
nn | Number of rows and columns in the matrices |
Definition at line 178 of file us_matrix.cpp.
|
static |
Function to solve a Cholesky-decomposed L-matrix.
Cholesky_SolveSystem expects a Cholesky-decomposed L-matrix (n x n) with the lower diagonal filled, and the right hand side "b". Using forward and backward substitution, the right hand side "b" is replaced by the solution vector "x".
L | Cholesky-decomposed L-matrix. |
b | Right hand side. |
n | Dimensions of L. |
Definition at line 145 of file us_matrix.cpp.
|
static |
Create a matrix array from QVectors.
Construct and initialize a matrix array of double pointers from a QVector of double pointers and a QVector of doubles holding the (rows times columns) contiguous matrix elements, initialized to zero.
QVm | The QVector from which the matrix array is constructed |
QVd | The QVector for holding contiguous data elements |
rows | The number of rows for the matrix |
columns | The number of columns for the matrix |
Definition at line 210 of file us_matrix.cpp.
|
static |
Vector dot product: p = sum( a[i] * b[i] )
Compute the dot product of two vectors
aa | The operand "a" vector |
bb | The operator "b" vector |
size | The size of the vectors |
Definition at line 389 of file us_matrix.cpp.
|
static |
Vector dot product: p = sum( a[i] * a[i] )
Compute the dot product of a vector with itself
aa | The operand "a" vector |
size | The size of the vector |
Definition at line 400 of file us_matrix.cpp.
|
static |
Function to solve general linear least squares problem:
c | returns the coefficients for best least-squares fit |
x | contains the x values of the raw data |
y | contains the y values of the raw data |
N | contains the dimension of x and y |
order | is the order of the function to be fitted |
Definition at line 8 of file us_matrix.cpp.
|
static |
Back substitution on a matrix which is the LU decomposition of the original matrix.
Do the backsubstitution on matrix A which is the LU decomposition of the original matrix. b is the n x 1 right hand side vector. b is replaced by the solution. index is the array that marks the row permutations.
A | Input decomposed and output back-substituted matrix. |
b | Right hand side vector on input and solution on output. |
index | Array to be used to mark row permutations. |
n | Dimension of sides. |
Definition at line 545 of file us_matrix.cpp.
|
static |
LU Decomposition of a matrix.
Performs LU Decomposition on a matrix. This routine must be given an array to mark the row permutations and a flag to mark whether the number of permutations was even or odd. Reference: Numerical Recipes in C.
matrix | The matrix to decompose. |
index | An index array to mark row permutations. |
parity | Flag of even number of permutations. |
n | Dimension of matrix sides. |
Definition at line 433 of file us_matrix.cpp.
|
static |
Solve a set of linear equations.
Solve a set of linear equations. A is a square matrix of coefficients. b is the right hand side. b is replaced by solution. Target is replaced by its LU decomposition.
A | Square matrix of coefficients. |
b | Right hand side on input and solution on output. |
n | Dimension of matrix sides and vectors. |
Definition at line 583 of file us_matrix.cpp.
|
static |
Matrix copy: C = A.
Copy the contents of one matrix to another of the same size
AA | The source A matrix |
CC | The destination C matrix copy |
rows | The number of rows in A and C |
columns | The number of columns in A and C |
Definition at line 351 of file us_matrix.cpp.
|
static |
Fills matrix C: Cij = ( i != j ? 0.0 : 1.0 )
Fill a square matrix so that it is the identity matrix.
CC | The matrix product |
size | The number of rows and columns in the matrix |
Definition at line 343 of file us_matrix.cpp.
|
static |
Calculates A * B: a matrix product of A-rows by B-columns.
Calculate the matrix product of two matrices, the rows by columns product of a (rows x size) matrix and a (size x columns) matrix.
AA | The A matrix operand (rows x size) |
BB | The B matrix operator (size x columns) |
CC | The C matrix product (rows x columns) |
rows | The number of rows in A and C |
size | The number of columns in A and rows in B |
columns | The number of columns in B and C |
Definition at line 309 of file us_matrix.cpp.
|
static |
Calculate A + B: a matrix sum with all matrices rows x columns.
Calculate the matrix sum of two matrices of the same dimensions.
AA | The A matrix operand (rows x columns) |
BB | The B matrix operator (rows x columns) |
CC | The C matrix sum (rows x columns) |
rows | The number of rows in all matrices |
columns | The number of columns in all matrices |
Definition at line 327 of file us_matrix.cpp.
|
static |
Calculates A * b: a vector product whose size is A's rows.
Calculate the (rows size) product of a (rows x columns) matrix and a (columns size) vector.
AA | The A matrix operand (rows x columns) |
bb | The b vector operator (columns x 1) |
cc | The c vector product (rows x 1) |
rows | The number of rows in the matrix (output vector elements) |
columns | The number of columns in the matrix (operator vector size) |
Definition at line 279 of file us_matrix.cpp.
|
staticprivate |
Definition at line 421 of file us_matrix.cpp.
|
staticprivate |
Definition at line 411 of file us_matrix.cpp.
|
static |
Matrix-scalar-multiply: Cij *= s.
Scale all matrix elements by a value
CC | The source,destination matrix |
ss | The scalar with which to multiply elements |
rows | The number of rows in the matrix |
columns | The number of columns in the matrix |
Definition at line 381 of file us_matrix.cpp.
|
static |
Calculates A' * A , A-transpose times A.
Calculate the (columns x columns) square matrix product of a matrix transpose and the matrix. Only the lower triangle is computed.
AA | The A matrix operand. |
CC | The C square matrix product of A-tranpose and A. |
rows | The number of A rows |
columns | The number of A columns (and output C size) |
Definition at line 230 of file us_matrix.cpp.
|
static |
Calculates A' * A: A-transpose times A.
Calculate the (columns x columns) square matrix product of a matrix transpose and the matrix. The entire matrix may optionally be filled.
AA | The A matrix operand. |
CC | The C square matrix product of A-tranpose and A. |
rows | The number of A rows |
columns | The number of A columns (and output C size) |
fill | A flag for whether to fill in the upper triangle |
Definition at line 264 of file us_matrix.cpp.
|
static |
Calculates A' * b: a vector product whose size is A's columns.
Calculate the (columns size) product of a (columns x rows) matrix-tranpose and a (rows size) vector.
AA | The A matrix whose transpose is the operand |
bb | The b vector operator (rows x 1) |
cc | The c vector product (columns x 1) |
rows | The number of matrix rows (operator vector size) |
columns | The number of matrix columns (product vector size) |
Definition at line 294 of file us_matrix.cpp.
|
static |
Vector copy: c = a.
Copy the contents of one vector to another of the same size
aa | The source "a" vector |
cc | The destination "c" vector copy |
size | The size of the vectors |
Definition at line 359 of file us_matrix.cpp.
|
static |
Calculate a + b: a vector sum with all vectors the same size.
Calculate the vector sum of two vectors of the same dimensions. The destination sum vector may be the same as the operand.
aa | The "a" vector operand |
bb | The "b" vector operator |
cc | The "c" vector sum (may be the same as "a") |
size | The size of all vectors |
Definition at line 336 of file us_matrix.cpp.