UltraScan III
List of all members | Static Public Member Functions | Static Private Member Functions
US_Matrix Class Reference

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)
 

Detailed Description

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.

Member Function Documentation

void US_Matrix::add ( double **  CC,
double  ss,
int  rows,
int  columns 
)
static

Matrix-scalar-add: Cij += s.

Add a scalar to all elements of a matrix

Parameters
CCThe source,destination matrix
ssThe scalar to add to all elements
rowsThe number of rows in the matrix
columnsThe number of columns in the matrix

Definition at line 373 of file us_matrix.cpp.

void US_Matrix::add_diag ( double **  CC,
double  ss,
int  size 
)
static

Diagonal add: Cii = Cii + s.

Add a scalar to the diagonal of a square matrix

Parameters
CCThe source,destination matrix
ssThe scalar to add to the diagonal
sizeThe size (rows, columns) of the matrix

Definition at line 366 of file us_matrix.cpp.

bool US_Matrix::Cholesky_Decomposition ( double **  a,
int  n 
)
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.

Parameters
aInput symmetric positive definite matrix A; lower triangle replaced by L on exit.
nDimensions of A.

Definition at line 95 of file us_matrix.cpp.

bool US_Matrix::Cholesky_Invert ( double **  AA,
double **  AI,
int  nn 
)
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)) .

Parameters
AAAn nn x nn input matrix
AIAn nn x nn solved inverted matrix
nnNumber of rows and columns in the matrices
Returns
A flag for whether a solution was found

Definition at line 178 of file us_matrix.cpp.

bool US_Matrix::Cholesky_SolveSystem ( double **  L,
double *  b,
int  n 
)
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".

Parameters
LCholesky-decomposed L-matrix.
bRight hand side.
nDimensions of L.

Definition at line 145 of file us_matrix.cpp.

double ** US_Matrix::construct ( QVector< double * > &  QVm,
QVector< double > &  QVd,
int  rows,
int  columns 
)
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.

Parameters
QVmThe QVector from which the matrix array is constructed
QVdThe QVector for holding contiguous data elements
rowsThe number of rows for the matrix
columnsThe number of columns for the matrix
Returns
The double** matrix array

Definition at line 210 of file us_matrix.cpp.

double US_Matrix::dotproduct ( double *  aa,
double *  bb,
int  size 
)
static

Vector dot product: p = sum( a[i] * b[i] )

Compute the dot product of two vectors

Parameters
aaThe operand "a" vector
bbThe operator "b" vector
sizeThe size of the vectors
Returns
Dot product of vectors

Definition at line 389 of file us_matrix.cpp.

double US_Matrix::dotproduct ( double *  aa,
int  size 
)
static

Vector dot product: p = sum( a[i] * a[i] )

Compute the dot product of a vector with itself

Parameters
aaThe operand "a" vector
sizeThe size of the vector
Returns
Dot product of vector with itself

Definition at line 400 of file us_matrix.cpp.

bool US_Matrix::lsfit ( double *  c,
double *  x,
double *  y,
int  N,
int  order 
)
static

Function to solve general linear least squares problem:

Parameters
creturns the coefficients for best least-squares fit
xcontains the x values of the raw data
ycontains the y values of the raw data
Ncontains the dimension of x and y
orderis the order of the function to be fitted

Definition at line 8 of file us_matrix.cpp.

void US_Matrix::LU_BackSubstitute ( double **  A,
double *&  b,
int *  index,
int  n 
)
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.

Parameters
AInput decomposed and output back-substituted matrix.
bRight hand side vector on input and solution on output.
indexArray to be used to mark row permutations.
nDimension of sides.

Definition at line 545 of file us_matrix.cpp.

void US_Matrix::LU_Decomposition ( double **  matrix,
int *  index,
bool  parity,
int  n 
)
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.

Parameters
matrixThe matrix to decompose.
indexAn index array to mark row permutations.
parityFlag of even number of permutations.
nDimension of matrix sides.

Definition at line 433 of file us_matrix.cpp.

void US_Matrix::LU_SolveSystem ( double **  A,
double *&  b,
int  n 
)
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.

Parameters
ASquare matrix of coefficients.
bRight hand side on input and solution on output.
nDimension of matrix sides and vectors.

Definition at line 583 of file us_matrix.cpp.

void US_Matrix::mcopy ( double **  AA,
double **  CC,
int  rows,
int  columns 
)
static

Matrix copy: C = A.

Copy the contents of one matrix to another of the same size

Parameters
AAThe source A matrix
CCThe destination C matrix copy
rowsThe number of rows in A and C
columnsThe number of columns in A and C

Definition at line 351 of file us_matrix.cpp.

void US_Matrix::mident ( double **  CC,
int  size 
)
static

Fills matrix C: Cij = ( i != j ? 0.0 : 1.0 )

Fill a square matrix so that it is the identity matrix.

Parameters
CCThe matrix product
sizeThe number of rows and columns in the matrix

Definition at line 343 of file us_matrix.cpp.

void US_Matrix::mmm ( double **  AA,
double **  BB,
double **  CC,
int  rows,
int  size,
int  columns 
)
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.

Parameters
AAThe A matrix operand (rows x size)
BBThe B matrix operator (size x columns)
CCThe C matrix product (rows x columns)
rowsThe number of rows in A and C
sizeThe number of columns in A and rows in B
columnsThe number of columns in B and C

Definition at line 309 of file us_matrix.cpp.

void US_Matrix::msum ( double **  AA,
double **  BB,
double **  CC,
int  rows,
int  columns 
)
static

Calculate A + B: a matrix sum with all matrices rows x columns.

Calculate the matrix sum of two matrices of the same dimensions.

Parameters
AAThe A matrix operand (rows x columns)
BBThe B matrix operator (rows x columns)
CCThe C matrix sum (rows x columns)
rowsThe number of rows in all matrices
columnsThe number of columns in all matrices

Definition at line 327 of file us_matrix.cpp.

void US_Matrix::mvv ( double **  AA,
double *  bb,
double *  cc,
int  rows,
int  columns 
)
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.

Parameters
AAThe A matrix operand (rows x columns)
bbThe b vector operator (columns x 1)
ccThe c vector product (rows x 1)
rowsThe number of rows in the matrix (output vector elements)
columnsThe number of columns in the matrix (operator vector size)

Definition at line 279 of file us_matrix.cpp.

void US_Matrix::print_matrix ( double **  A,
int  rows,
int  columns 
)
staticprivate

Definition at line 421 of file us_matrix.cpp.

void US_Matrix::print_vector ( double *  v,
int  n 
)
staticprivate

Definition at line 411 of file us_matrix.cpp.

void US_Matrix::scale ( double **  CC,
double  ss,
int  rows,
int  columns 
)
static

Matrix-scalar-multiply: Cij *= s.

Scale all matrix elements by a value

Parameters
CCThe source,destination matrix
ssThe scalar with which to multiply elements
rowsThe number of rows in the matrix
columnsThe number of columns in the matrix

Definition at line 381 of file us_matrix.cpp.

void US_Matrix::tmm ( double **  AA,
double **  CC,
int  rows,
int  columns 
)
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.

Parameters
AAThe A matrix operand.
CCThe C square matrix product of A-tranpose and A.
rowsThe number of A rows
columnsThe number of A columns (and output C size)

Definition at line 230 of file us_matrix.cpp.

void US_Matrix::tmm ( double **  AA,
double **  CC,
int  rows,
int  columns,
bool  fill 
)
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.

Parameters
AAThe A matrix operand.
CCThe C square matrix product of A-tranpose and A.
rowsThe number of A rows
columnsThe number of A columns (and output C size)
fillA flag for whether to fill in the upper triangle

Definition at line 264 of file us_matrix.cpp.

void US_Matrix::tvv ( double **  AA,
double *  bb,
double *  cc,
int  rows,
int  columns 
)
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.

Parameters
AAThe A matrix whose transpose is the operand
bbThe b vector operator (rows x 1)
ccThe c vector product (columns x 1)
rowsThe number of matrix rows (operator vector size)
columnsThe number of matrix columns (product vector size)

Definition at line 294 of file us_matrix.cpp.

void US_Matrix::vcopy ( double *  aa,
double *  cc,
int  size 
)
static

Vector copy: c = a.

Copy the contents of one vector to another of the same size

Parameters
aaThe source "a" vector
ccThe destination "c" vector copy
sizeThe size of the vectors

Definition at line 359 of file us_matrix.cpp.

void US_Matrix::vsum ( double *  aa,
double *  bb,
double *  cc,
int  size 
)
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.

Parameters
aaThe "a" vector operand
bbThe "b" vector operator
ccThe "c" vector sum (may be the same as "a")
sizeThe size of all vectors

Definition at line 336 of file us_matrix.cpp.


The documentation for this class was generated from the following files: