maspack.matrix
Class SVDecomposition3d

java.lang.Object
  extended by maspack.matrix.SVDecomposition3d

public class SVDecomposition3d
extends java.lang.Object

Constructs the singular value decomposition (SVD) of a 3x3 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_ITERATION_LIMIT
          The iteration limit for computing the SVD.
 
Constructor Summary
SVDecomposition3d()
          Creates an uninitialized SVDecomposition with U and V internally allocated.
SVDecomposition3d(Matrix3dBase M)
          Creates an SVDecomposition with U and V internally allocated and initializes it to the SVD for the matrix M.
SVDecomposition3d(Matrix3d U, Matrix3d V)
          Creates an SVDecomposition with the matrices U and V.
SVDecomposition3d(Matrix3d U, Matrix3d V, Matrix3dBase M)
          Creates an SVDecomposition with the matrices U and V, 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 factor(Matrix3dBase M)
          Peforms an SVD on the Matrix3dBase M.
 int getIterationLimit()
          Gets the iteration limit for SVD computations.
 Vector3d[] getNullSpace()
           
 Vector3d[] getNullSpace(double eps)
           
 Vector3d[] getRangeSpace()
           
 Vector3d[] getRangeSpace(double eps)
           
 void getS(Vector3d svec)
          Gets the singular values associated with this SVD.
 Matrix3d getU()
          Returns the U matrix associated with this SVD, or null if no such matrix has been set.
 Matrix3d getV()
          Returns the V matrix associated with this SVD, or null if no such matrix has been set.
 boolean inverse(Matrix3d R)
          Computes the inverse of the original matrix M associated this SVD, and places the result in R.
 boolean isCanonical()
           
 void leftPolarDecomposition(Matrix3d P, Matrix3dBase R, Matrix3dBase F)
          Factors a 3 x 3 matrix F into a left polar decomposition
 void leftPolarDecomposition(SymmetricMatrix3d P, Matrix3dBase R, Matrix3dBase F)
          Factors a 3 x 3 matrix F into a left polar decomposition
 double norm()
          Computes the 2-norm of the original matrix M associated with this SVD.
 void polarDecomposition(Matrix3dBase R, Matrix3d P, Matrix3dBase F)
          Factors a 3 x 3 matrix F into a right polar decomposition
 void polarDecomposition(Matrix3dBase R, SymmetricMatrix3d P, Matrix3dBase F)
          Factors a 3 x 3 matrix F into a right polar decomposition
 boolean pseudoInverse(Matrix3d R)
          Computes the pseudo inverse of the original matrix M associated this SVD, and places the result in R.
 void setCanonical(boolean enable)
          Ensure that singular values are positive and sorted from largest to smallest.
 void setIterationLimit(int lim)
          Sets the iteration limit for SVD computations.
 void setU(Matrix3d U)
          Sets the U matrix associated with this SVD.
 void setV(Matrix3d V)
          Sets the V matrix associated with this SVD.
 boolean solve(Vector3d x, Vector3d 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

DEFAULT_ITERATION_LIMIT

public static final int DEFAULT_ITERATION_LIMIT
The iteration limit for computing the SVD.

See Also:
Constant Field Values
Constructor Detail

SVDecomposition3d

public SVDecomposition3d(Matrix3d U,
                         Matrix3d V,
                         Matrix3dBase M)
Creates an SVDecomposition with the matrices U and V, and initializes it to the SVD for the matrix M. Either U and V or V may be omitted if the user does not desire these values.

Parameters:
U - optional U matrix for this SVD
V - optional V matrix for this SVD
M - matrix to perform the SVD on

SVDecomposition3d

public SVDecomposition3d(Matrix3d U,
                         Matrix3d V)
Creates an SVDecomposition with the matrices U and V. Either U and V or V may be omitted if the user does not desire these values.

Parameters:
U - optional U matrix for this SVD
V - optional V matrix for this SVD

SVDecomposition3d

public SVDecomposition3d(Matrix3dBase M)
Creates an SVDecomposition with U and V internally allocated and initializes it to the SVD for the matrix M.

Parameters:
M - matrix to perform the SVD on

SVDecomposition3d

public SVDecomposition3d()
Creates an uninitialized SVDecomposition with U and V internally allocated.

Method Detail

setCanonical

public void setCanonical(boolean enable)
Ensure that singular values are positive and sorted from largest to smallest. The default value for this is true. If false, then no effort will be made to ensure that the values are positive or sorted.


isCanonical

public boolean isCanonical()

getIterationLimit

public int getIterationLimit()
Gets the iteration limit for SVD computations. The actual number of iterations allowed is this limit value times the minimum dimension of the matrix.

Returns:
iteration limit
See Also:
setIterationLimit(int)

setIterationLimit

public void setIterationLimit(int lim)
Sets the iteration limit for SVD computations. The actual number of iterations allowed is this limit value times the minimum dimension of the matrix.

Parameters:
lim - iteration limit
See Also:
getIterationLimit()

factor

public void factor(Matrix3dBase M)
Peforms an SVD on the Matrix3dBase M.

Parameters:
M - matrix to perform the SVD on

setU

public void setU(Matrix3d U)
Sets the U matrix associated with this SVD. If a previous U matrix has been set, its contents will be copied into this new matrix. Setting the matrix to null will disable the calculation of U.

Parameters:
U - new U matrix for this SVD

getU

public Matrix3d getU()
Returns the U matrix associated with this SVD, or null if no such matrix has been set.

Returns:
U matrix

setV

public void setV(Matrix3d V)
Sets the V matrix associated with this SVD. If a previous V matrix has been set, its contents will be copied into this new matrix. Setting the matrix to null will disable the calculation of V.

Parameters:
V - new V matrix for this SVD

getV

public Matrix3d getV()
Returns the V matrix associated with this SVD, or null if no such matrix has been set.

Returns:
V matrix

getS

public void getS(Vector3d svec)
Gets the singular values associated with this SVD.

Parameters:
svec - vector giving the diagonal elements of S

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(Vector3d x,
                     Vector3d 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, or if U and V are not present

inverse

public boolean inverse(Matrix3d 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, or if U and V are not present

pseudoInverse

public boolean pseudoInverse(Matrix3d R)
Computes the pseudo 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, or if U and V are not present

getNullSpace

public Vector3d[] getNullSpace(double eps)

getRangeSpace

public Vector3d[] getRangeSpace(double eps)

getNullSpace

public Vector3d[] getNullSpace()

getRangeSpace

public Vector3d[] getRangeSpace()

polarDecomposition

public void polarDecomposition(Matrix3dBase R,
                               Matrix3d P,
                               Matrix3dBase F)
Factors a 3 x 3 matrix F into a right polar decomposition
 F = R P
 
where R is a rotation matrix (with determinant 1) and P is a symmetric matrix.


polarDecomposition

public void polarDecomposition(Matrix3dBase R,
                               SymmetricMatrix3d P,
                               Matrix3dBase F)
Factors a 3 x 3 matrix F into a right polar decomposition
 F = R P
 
where R is a rotation matrix (with determinant 1) and P is a symmetric matrix.


leftPolarDecomposition

public void leftPolarDecomposition(Matrix3d P,
                                   Matrix3dBase R,
                                   Matrix3dBase F)
Factors a 3 x 3 matrix F into a left polar decomposition
 F = R P
 
where R is a rotation matrix (with determinant 1) and P is a symmetric matrix.


leftPolarDecomposition

public void leftPolarDecomposition(SymmetricMatrix3d P,
                                   Matrix3dBase R,
                                   Matrix3dBase F)
Factors a 3 x 3 matrix F into a left polar decomposition
 F = R P
 
where R is a rotation matrix (with determinant 1) and P is a symmetric matrix.