All Packages Class Hierarchy This Package Previous Next Index
Class crw.math.FMatrix
java.lang.Object
|
+----crw.math.FMatrix
- public class FMatrix
- extends Object
Class of matrix of floating numbers. Useful mostly for
a square matrix. The matrix is represented by a unit-offset 2D array.
The zeroth row and column, [0][i] and [i][0], are ignored (i.e., wasted).
- Version:
- 1.0, 1997/6/18
- Author:
- C.R.Wie
-
FMatrix()
- Creates a 1 x 1 matrix of floating numbers.
-
FMatrix(float[][])
- Creates a floating number matrix whose elements are initialized to
the 2D floating number array, the argument.
-
FMatrix(FMatrix)
- Creates a matrix initialized to the FMatrix object, the argument.
-
FMatrix(int)
- Creates a n x n square matrix of floating numbers.
-
FMatrix(int, int)
- Creates a n x m matrix of floating numbers.
-
add(float)
- Adds a constant to the diagonal elements of this matrix.
-
add(float, float[][])
- Returns addition of a square matrix and a constant times the unity matrix.
-
add(float, FMatrix)
- Returns addition of a square matrix and a constant times the unity matrix.
-
add(float[][])
- Adds the argument matrix to this one.
-
add(float[][], float)
- Returns addition of a square matrix and a constant times the unity matrix.
-
add(float[][], float[][])
- Returns addition of two matrices.
-
add(FMatrix)
- Adds the argument matrix to this one.
-
add(FMatrix, float)
- Returns addition of a square matrix and a constant times the unity matrix.
-
add(FMatrix, FMatrix)
- Returns the addition of two matrices of equal dimensions, null if
different dimensions.
-
det()
- Return the determinant of this FMatrix object.
-
det(float[][])
- Returns the determinant value.
-
det(FMatrix)
- Returns the determinant value.
-
gaussj(float[][], float[][])
- Linear equation solution by Gauss-Jordan elimination, eq.(2.1.1)
on p.33 of NUMERICAL RECIPES IN C.
-
inverse()
- Turns this square matrix into its own inverse matrix.
-
inverse(float[][])
- Returns the inverse matrix found with the LU Decomposition method.
-
inverse(FMatrix)
- Returns the inverse matrix of a FMatrix object.
-
lubksb(float[][], int[], float[])
- Solves the set of n linear equations A.X = B.
-
ludcmp(float[][], int[], float[])
- Given an (n-1) x (n-1) matrix a[1..n-1][1..n-1], this routine replaces it by the LU
decomposition of a rowwise permutation of itself.
-
mul(float)
- Multiplies a constant to every element of this matrix.
-
mul(float, float[][])
- Multiplies a constant to every element, returns the result.
-
mul(float, FMatrix)
- Multiplies a constant to every element, returns the result.
-
mul(float[][])
- Multiplies a 2D float array from the RHS to this one and replace
this object by the product.
-
mul(float[][], float)
- Multiplies a constant to every element, returns the result.
-
mul(float[][], float[][])
- Returns the result of multiplying the first 2D
float array to the second argument.
-
mul(FMatrix)
- Multiplies a FMatrix object from the RHS to this one and replace
this by the product.
-
mul(FMatrix, float)
- Multiplies a constant to every element, returns the result.
-
mul(FMatrix, FMatrix)
- Multiplies a FMatrix object to another and returns the result.
-
print()
- Prints out the matrix to standard out.
-
sub(float)
- Subtracts a constant from the diagonal element of this matrix.
-
sub(float, float[][])
- Returns subtraction of the second argument from the first, or a null
if not a square matrix
-
sub(float, FMatrix)
- Returns subtraction of the second argument from the first, or a null
if not a square matrix
-
sub(float[][])
- Subtracts the argument matrix from this one.
-
sub(float[][], float)
- Returns subtraction of the second argument from the first, or a null
if not a square matrix
-
sub(float[][], float[][])
- Returns subtraction of the second argument from the first.
-
sub(FMatrix)
- Subtracts the argument matrix from this one.
-
sub(FMatrix, float)
- Returns subtraction of the second argument from the first, or a null
if not a square matrix
-
sub(FMatrix, FMatrix)
- Returns subtraction of the second argument from the first.
-
trans()
- Turns this FMatrix into its own transpose.
FMatrix
public FMatrix()
- Creates a 1 x 1 matrix of floating numbers. Since I use
unit-offset arrays as matrix, this object contains NO useful element.
FMatrix
public FMatrix(int n)
- Creates a n x n square matrix of floating numbers.
FMatrix
public FMatrix(int n,
int m)
- Creates a n x m matrix of floating numbers.
FMatrix
public FMatrix(float a[][])
- Creates a floating number matrix whose elements are initialized to
the 2D floating number array, the argument.
- Parameters:
- a[][] - a 2D array of floating numbers
FMatrix
public FMatrix(FMatrix f)
- Creates a matrix initialized to the FMatrix object, the argument.
- Parameters:
- f - a FMatrix object
add
public static float[][] add(float a[][],
float b[][])
- Returns addition of two matrices.
- Parameters:
- a[][] - 2D array of floating numbers
- b[][] - 2D array of floating numbers
- Returns:
- the addition of the argument matrices, or null if not the same dimension.
add
public static float[][] add(float a[][],
float lambda)
- Returns addition of a square matrix and a constant times the unity matrix.
Returns null if not a square matrix.
- Parameters:
- a[][] - 2D array -- square matrix.
- lambda - a constant
- Returns:
- matrix addition of a constant to the diagonal elements
add
public static float[][] add(float lambda,
float a[][])
- Returns addition of a square matrix and a constant times the unity matrix.
Returns null if not a square matrix.
- Parameters:
- a[][] - 2D array -- square matrix.
- lambda - a constant
- Returns:
- matrix addition of a constant to the diagonal elements
add
public static FMatrix add(FMatrix a,
FMatrix b)
- Returns the addition of two matrices of equal dimensions, null if
different dimensions.
- Parameters:
- a - FMatrix object
- b - FMatrix object
- Returns:
- the addition of the two arguments, null if different dimensions.
add
public static FMatrix add(FMatrix f,
float lambda)
- Returns addition of a square matrix and a constant times the unity matrix.
Returns null if not a square matrix.
- Parameters:
- f - a square matrix.
- lambda - a constant
- Returns:
- matrix addition of a constant to the diagonal elements
add
public static FMatrix add(float lambda,
FMatrix f)
- Returns addition of a square matrix and a constant times the unity matrix.
Returns null if not a square matrix.
- Parameters:
- f - a square matrix.
- lambda - a constant
- Returns:
- matrix addition of a constant to the diagonal elements
add
public void add(float a[][])
- Adds the argument matrix to this one. Nothing happens if this matrix
has a different dimension from the argument matrix.
- Parameters:
- a[][] - a 2D array -- matrix a[1..][1..]
add
public void add(FMatrix f)
- Adds the argument matrix to this one. Nothing happens if this matrix
has a different dimension from the argument matrix.
- Parameters:
- f - matrix
add
public void add(float lambda)
- Adds a constant to the diagonal elements of this matrix.
If this matrix is not square, nothing happens.
- Parameters:
- lambda - the constant to be added to the diagonal
sub
public static float[][] sub(float a[][],
float b[][])
- Returns subtraction of the second argument from the first.
- Parameters:
- a[][] - 2D array of floating numbers
- b[][] - 2D array of floating numbers
- Returns:
- the subtraction of the second argument from the first, or null if not the same dimension.
sub
public static float[][] sub(float a[][],
float lambda)
- Returns subtraction of the second argument from the first, or a null
if not a square matrix
- Parameters:
- a[][] - 2D array of floating numbers
- lambda - constant to be subtracted from the diagonal
- Returns:
- the subtraction of a const (2nd arg) from a matrix (1st arg).
sub
public static float[][] sub(float lambda,
float a[][])
- Returns subtraction of the second argument from the first, or a null
if not a square matrix
- Parameters:
- a[][] - 2D array of floating numbers
- lambda - constant to be subtracted from the diagonal
- Returns:
- the subtraction of a matrix (2nd arg) from a const(1st arg).
sub
public static FMatrix sub(FMatrix a,
FMatrix b)
- Returns subtraction of the second argument from the first.
- Parameters:
- a - a matrix of floating numbers (32 bit)
- b - a matrix of floating numbers
- Returns:
- the subtraction of the second argument from the first, or null if not the same dimension.
sub
public static FMatrix sub(FMatrix f,
float lambda)
- Returns subtraction of the second argument from the first, or a null
if not a square matrix
- Parameters:
- f - a matrix of floating numbers
- lambda - constant to be subtracted from the diagonal
- Returns:
- the subtraction of a const (2nd arg) from a matrix (1st arg).
sub
public static FMatrix sub(float lambda,
FMatrix f)
- Returns subtraction of the second argument from the first, or a null
if not a square matrix
- Parameters:
- f - a matrix of floating numbers
- lambda - constant to be subtracted from the diagonal
- Returns:
- the subtraction of a matrix (2nd arg) from a constant(1st arg).
sub
public void sub(float a[][])
- Subtracts the argument matrix from this one. Operation changes this
object. Nothing happens if this matrix has a different dimension from
the argument matrix.
- Parameters:
- a[][] - a 2D array
sub
public void sub(FMatrix f)
- Subtracts the argument matrix from this one. Operation changes this
object. Nothing happens if this matrix has a different dimension from
the argument matrix.
- Parameters:
- f - matrix
sub
public void sub(float lambda)
- Subtracts a constant from the diagonal element of this matrix.
Nothing happens if this is not a square matrix.
- Parameters:
- lambda - the eigenvalue
mul
public static float[][] mul(float a[][],
float b[][])
- Returns the result of multiplying the first 2D
float array to the second argument. Returns null if the number of columns
of the first argument is NOT equal to the number of rows of the
second argument.
- Parameters:
- a[][] - a 2D float array. Zeroth elements are ignored.
- b[][] - the second 2D float array.
- Returns:
- the floating number matrix product of the arguments or null.
mul
public static FMatrix mul(FMatrix a,
FMatrix b)
- Multiplies a FMatrix object to another and returns the result.
Returns null if the number of columns of the first FMatrix
is NOT equal to the number of rows of the second.
- Parameters:
- a - the first FMatrix
- b - the second FMatrix
- Returns:
- the product of the arguments or null.
mul
public static float[][] mul(float a[][],
float k)
- Multiplies a constant to every element, returns the result.
- Parameters:
- a[][] - a 2D array.
- k - constant to multiply
- Returns:
- the product
mul
public static float[][] mul(float k,
float a[][])
- Multiplies a constant to every element, returns the result.
- Parameters:
- a[][] - a 2D array.
- k - constant to multiply
- Returns:
- the product
mul
public static FMatrix mul(FMatrix f,
float k)
- Multiplies a constant to every element, returns the result.
- Parameters:
- f - a matrix.
- k - constant to multiply
- Returns:
- the product
mul
public static FMatrix mul(float k,
FMatrix f)
- Multiplies a constant to every element, returns the result.
- Parameters:
- f - a matrix.
- k - constant to multiply
- Returns:
- the product
mul
public void mul(float k)
- Multiplies a constant to every element of this matrix.
- Parameters:
- k - constant to multiply
mul
public void mul(FMatrix f)
- Multiplies a FMatrix object from the RHS to this one and replace
this by the product. Nothing happens if the number of columns of
this matrix is not equal to the number of rows of the argument matrix.
Operation changes this object.
- Parameters:
- f - the RHS FMatrix
mul
public void mul(float a[][])
- Multiplies a 2D float array from the RHS to this one and replace
this object by the product. Nothing happens if the number of columns of
this matrix is not equal to the number of rows of the argument matrix.
Operation changes this object.
- Parameters:
- a[][] - the 2D float array
trans
public void trans()
- Turns this FMatrix into its own transpose.
inverse
public void inverse()
- Turns this square matrix into its own inverse matrix. If this matirx
is not square, nothing happens. If singular matrix, nothing happens.
inverse
public static FMatrix inverse(FMatrix f)
- Returns the inverse matrix of a FMatrix object. Unlike the inverse
method which takes a 2D array as argument, this one does not
destroy the original FMatrix.
- Parameters:
- the - original FMatrix
- Returns:
- the inverse matrix or null (if not a square matrix)
det
public static double det(FMatrix f)
- Returns the determinant value. The determinant is calculated
after performing the LU Decomposition to the original matrix.
- Parameters:
- f - the FMatrix object
- Returns:
- the determinant of the argument or 0.0f if singular or not square
det
public double det()
- Return the determinant of this FMatrix object. The determinant is calculated
after performing the LU Decomposition to the original matrix.
- Returns:
- the determinant or 0.0f if singular or not square
det
public static double det(float a[][])
- Returns the determinant value. The original matrix is
not destroyed. The determinant is calculated
after performing the LU Decomposition to the original matrix.
- Parameters:
- a[][] - the original matrix
- Returns:
- the determinant value or 0.0 if singular or not square
inverse
public static float[][] inverse(float a[][])
- Returns the inverse matrix found with the LU Decomposition method.
Method destroys the original matrix.
Original matrix a[][] should not hold data in a[0][i] and a[i][0].
Method uses unit-offset arrays.
This method was tested upto 3x3 matrix, agrees with gaussj() method.
- Parameters:
- a[][] - the original matrix, is destroyed by method
- indx[] - vector of length a.length, used by LUDCMP to hold row-permutation info
- d[] - vector of length 1, +1 if even number of row interchanges, -1 if odd
- Returns:
- the inverse matrix, or null if the original matrix is singular.
ludcmp
protected static int ludcmp(float a[][],
int indx[],
float d[])
- Given an (n-1) x (n-1) matrix a[1..n-1][1..n-1], this routine replaces it by the LU
decomposition of a rowwise permutation of itself. a is input.
a is output, arranged as in eq.(2.3.14), p.41 of the NUMERICAL RECIPES
IN C, 1st ed; indx[1..n-1] is an output vector which records the row
permutation effected by the partial pivoting; d is output as +-1
depending on whether the number of row interchanges was even or odd,
respectively. This routine is used in combination with lubksb to
solve linear equations or invert a matrix.
- Parameters:
- a[][] - the input and output matrix
- indx[] - records the row permutation
- d[] - array of float of size 1, is +1 if even, -1 if odd number of permutations.
- Returns:
- 0 if singular matrix, 1 otherwise
lubksb
protected static void lubksb(float a[][],
int indx[],
float b[])
- Solves the set of n linear equations A.X = B. Here a[1..n-1][1..n-1]
is input, not as the matrix A but rather as its LU decomposition,
determined by the routine ludcmp(). indx[1..n-1] is input as the
permutation vector returned by ludcmp(). b[1..n-1] is input as the
right-hand side vector B, and returns with the solution vector X.
a, n, and indx are not modified by this routine and can be left in
place for successive calls with different right-hand sides b. This
routine takes into account the possibility that b will begin with
many zero elements, so it is efficient for use in matrix inversion.
- Parameters:
- a[][] - the input matrix of dim (n-1) x (n-1). Data in 1..n-1
- indx[] - the permutation vectors returned by ludcmp(). 1..n-1
- b[] - a right-hand side vector
gaussj
public static void gaussj(float a[][],
float b[][])
- Linear equation solution by Gauss-Jordan elimination, eq.(2.1.1)
on p.33 of NUMERICAL RECIPES IN C. a[1..n-1][1..n-1] is an input
matrix of n-1 by n-1 elements. b[1..n-1][1..m-1] is an input matrix of
size n-1 by m-1 containing the m-1 right-hand side vectors. On output,
a is replaced by its matrix inverse, and b is replaced by the
corresponding set of solution vectors. The first rows and first
colums of a and b: a[0][0..n], a[0..n][0], b[0][0..m], and
b[0..n][0] are wasted (i.e., not used) due to the zero-offset
nature of Java whereas the algorithm is in unit-offset.
- Parameters:
- a[][] - the n-1 by n-1 input matrix with the row=0 and col=0
- b[][] - the m-1 column vectors of dim n-1.
print
public void print()
- Prints out the matrix to standard out. Useful for debugging.
All Packages Class Hierarchy This Package Previous Next Index