maspack.matrix
Class SVDecomposition

java.lang.Object
  extended bymaspack.matrix.SVDecomposition

public class SVDecomposition
extends java.lang.Object

Constructs the singular value decomposition (SVD) of a matrix. This takes the form
M = U S V'
where M is the original matrix, U and V are orthogonal matrices, V' indicates the transpose of V, and S is a diagonal matrix. Once an SVD has been constructed, it can be used to perform various computations related to M, such as solving equations, computing the determinant, or estimating the condition number.

Providing a separate class for the SVD allows an application to perform such decompositions repeatedly without having to reallocate temporary storage space.


Field Summary
static int DEFAULT_MAX_ITERATIONS
          The default maximum iteration count for computing the SVD.
static int OMIT_U
          Specifies that the matrix U should not be computed.
static int OMIT_V
          Specifies that the matrix V should not be computed.
 
Constructor Summary
SVDecomposition(int flags)
          Creates an uninitialized SVDecomposition with the specified computation flags.
SVDecomposition(MatrixObject M)
          Creates an SVDecomposition and initializes it to the SVD for the matrix M.
SVDecomposition(MatrixObject M, int flags)
          Creates an SVDecomposition, sets the computation flags, and initializes it to the SVD for the matrix M.
 
Method Summary
 double condition()
          Computes the condition number of the original matrix M associated with this SVD.
 double determinant()
          Computes the determinant of the original matrix M associated with this SVD.
 void get(MatrixObject U, VectorObject svec, MatrixObject V)
          Gets the matrices associated with the SVD.
 int getFlags()
          Gets the flags associated with SVD computation.
 int getMaxIterations()
          Gets the maximum number of iterations allowed for SVD computations.
 boolean inverse(MatrixNd R)
          Computes the inverse of the original matrix M associated this SVD, and places the result in R.
 double norm()
          Computes the 2-norm of the original matrix M associated with this SVD.
 void set(MatrixObject M)
          Peforms an SVD on the MatrixObject M.
 void setFlags(int flags)
          Sets the flags associated with SVD computation.
 void setMaxIterations(int max)
          Sets the maximum number of iterations allowed for SVD computations.
 boolean solve(MatrixNd X, MatrixNd B)
          Solves the linear equation
M X = B
where M is the original matrix associated with this SVD, and X and B are matrices.
 boolean solve(VectorNd x, VectorNd b)
          Solves the linear equation
M x = b
where M is the original matrix associated with this SVD, and x and b are vectors.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

OMIT_U

public static final int OMIT_U
Specifies that the matrix U should not be computed.

See Also:
Constant Field Values

OMIT_V

public static final int OMIT_V
Specifies that the matrix V should not be computed.

See Also:
Constant Field Values

DEFAULT_MAX_ITERATIONS

public static final int DEFAULT_MAX_ITERATIONS
The default maximum iteration count for computing the SVD.

See Also:
Constant Field Values
Constructor Detail

SVDecomposition

public SVDecomposition(MatrixObject M)
Creates an SVDecomposition and initializes it to the SVD for the matrix M.

Parameters:
M - matrix to perform the SVD on

SVDecomposition

public SVDecomposition(MatrixObject M,
                       int flags)
Creates an SVDecomposition, sets the computation flags, and initializes it to the SVD for the matrix M.

Parameters:
M - matrix to perform the SVD on
flags - flags associated with SVD computation
See Also:
setFlags(int)

SVDecomposition

public SVDecomposition(int flags)
Creates an uninitialized SVDecomposition with the specified computation flags.

Parameters:
flags - flags associated with SVD computation
See Also:
setFlags(int)
Method Detail

setFlags

public void setFlags(int flags)
Sets the flags associated with SVD computation. The flags presently supported include OMIT_V and OMIT_U.

Parameters:
flags - an or-ed combination of flags.
See Also:
getFlags()

getFlags

public int getFlags()
Gets the flags associated with SVD computation.

Returns:
flags
See Also:
setFlags(int)

getMaxIterations

public int getMaxIterations()
Gets the maximum number of iterations allowed for SVD computations.

Returns:
maximum number of iterations
See Also:
setMaxIterations(int)

setMaxIterations

public void setMaxIterations(int max)
Sets the maximum number of iterations allowed for SVD computations.

Parameters:
max - maximum number of iterations
See Also:
getMaxIterations()

set

public void set(MatrixObject M)
Peforms an SVD on the MatrixObject M.

Parameters:
M - matrix to perform the SVD on

get

public void get(MatrixObject U,
                VectorObject svec,
                MatrixObject V)
Gets the matrices associated with the SVD.

Parameters:
U - left-hand orthogonal matrix
svec - vector giving the diagonal elements of S
V - right-hand orthogonal matrix (note that this is V, and not it's transpose V').
Throws:
ImproperStateException - if this SVDecomposition is uninitialized
ImproperSizeException - if U, svec, or V are not of the proper dimension and cannot be resized.

condition

public double condition()
Computes the condition number of the original matrix M associated with this SVD. This is simply the absolute value of the ratio of the maximum and minimum singular values.

Returns:
condition number
Throws:
ImproperStateException - if this SVDecomposition is uninitialized

norm

public double norm()
Computes the 2-norm of the original matrix M associated with this SVD. This is simply the absolute value of the maximum singular value.

Returns:
2-norm
Throws:
ImproperStateException - if this SVDecomposition is uninitialized

determinant

public double determinant()
Computes the determinant of the original matrix M associated with this SVD.

Returns:
determinant
Throws:
ImproperStateException - if this SVDecomposition is uninitialized

solve

public boolean solve(VectorNd x,
                     VectorNd b)
Solves the linear equation
M x = b
where M is the original matrix associated with this SVD, and x and b are vectors.

Parameters:
x - unknown vector to solve for
b - constant vector
Returns:
false if M is singular (within working precision)
Throws:
ImproperStateException - if this decomposition is uninitialized
ImproperSizeException - if b does not have a size compatible with M, or if x does not have a size compatible with M and cannot be resized.

solve

public boolean solve(MatrixNd X,
                     MatrixNd B)
Solves the linear equation
M X = B
where M is the original matrix associated with this SVD, and X and B are matrices.

Parameters:
X - unknown matrix to solve for
B - constant matrix
Returns:
false if M is singular (within working precision) and true otherwise.
Throws:
ImproperStateException - if this decomposition is uninitialized
ImproperSizeException - if B has a different number of rows than M, or if X has a different number of rows than M or a different number of columns than B and cannot be resized.

inverse

public boolean inverse(MatrixNd R)
Computes the inverse of the original matrix M associated this SVD, and places the result in R.

Parameters:
R - matrix in which the inverse is stored
Returns:
false if M is singular (within working precision)
Throws:
ImproperStateException - if this decomposition is uninitialized
ImproperSizeException - if M is not square, or if R does not have the same size as M and cannot be resized.