maspack.matrix
Class SymmetricMatrix3d

java.lang.Object
  extended bymaspack.matrix.MatrixObject
      extended bymaspack.matrix.Matrix3dObject
          extended bymaspack.matrix.SymmetricMatrix3d
All Implemented Interfaces:
java.io.Serializable

public class SymmetricMatrix3d
extends Matrix3dObject

A symmetric 3 x 3 matrix with the elements stored as explicit fields.

See Also:
Serialized Form

Field Summary
 
Fields inherited from class maspack.matrix.Matrix3dObject
m00, m01, m02, m10, m11, m12, m20, m21, m22
 
Constructor Summary
SymmetricMatrix3d()
          Creates a symmetric matrix and initializes it to zero.
SymmetricMatrix3d(double[] vals)
          Creates a symmetric matrix and initializes its elements from an array of doubles.
SymmetricMatrix3d(double m00, double m11, double m22, double m01, double m02, double m12)
          Creates a symmetric matrix and initializes its elements from the specified diagonal and uppper off-diagonal values.
SymmetricMatrix3d(Matrix3dObject M)
          Creates a symmetric matrix and initializes its elements from the diagonal and upper off-diagonal elements of M.
 
Method Summary
 void add(SymmetricMatrix3d M1)
          Adds this matrix to M1 and places the result in this matrix.
 void add(SymmetricMatrix3d M1, SymmetricMatrix3d M2)
          Adds matrix M1 to M2 and places the result in this matrix.
 void getCholesky(Matrix3d L)
          Computes the Cholesky decomposition of this matrix, which is assumed to be positive definite.
 void getEigenValues(double[] eig)
           
 void getEigenValues(Vector3d eig)
          Quickly computes the eigenvalues of this symmetric matrix.
 void getSVD(Matrix3dObject U, Vector3d sig, Matrix3dObject V)
          Quickly computes the singular value decomposition U S V' of this symmetric matrix.
 void mulLeftAndTransposeRight(Matrix3dObject M)
          Computes M T M', where T is this matrix, and M' is the transpose of M, and places the result in this matrix.
 void mulTransposeLeft(Matrix3dObject M)
          Computes M' M, where M is a supplied matrix and M' is its transpose, and places the (symmetric) result in this matrix.
 void mulTransposeLeftAndRight(Matrix3dObject M)
          Computes M' T M, where T is this matrix, and M' is the transpose of M, and places the result in this matrix.
 void negate(SymmetricMatrix3d M1)
          Sets this matrix to the negative of M1.
 void scale(double s)
          Scales the elements of this matrix by s.
 void scale(double s, SymmetricMatrix3d M1)
          Scales the elements of matrix M1 by s and places the results in this matrix.
 void set(double[] vals)
          Sets the elements of this matrix from an array of doubles.
 void set(double m00, double m11, double m22, double m01, double m02, double m12)
          Sets the values of this matrix from the specified diagonal and uppper off-diagonal values.
 void set(Matrix3dObject M)
          Sets the elements of this matrix from the the diagonal and upper off-diagonal elements of M.
 void setDiagonal(double[] vals)
          Sets this matrix to a diagonal matrix whose values are specified by the array vals.
 void setDiagonal(Vector3d diag)
          Sets this matrix to a diagonal matrix whose values are specified by diag.
 void setRandom()
          Sets the elements of this matrix to uniformly distributed random values in the range -0.5 (inclusive) to 0.5 (exclusive).
 void setRandom(double lower, double upper)
          Sets the elements of this matrix to uniformly distributed random values in a specified range.
 void setRandom(double lower, double upper, java.util.Random generator)
          Sets the elements of this matrix to uniformly distributed random values in a specified range, using a supplied random number generator.
 void setZero()
          Sets the elements of this matrix to zero.
 void sub(SymmetricMatrix3d M1)
          Subtracts this matrix from M1 and places the result in this matrix.
 void sub(SymmetricMatrix3d M1, SymmetricMatrix3d M2)
          Subtracts matrix M1 from M2 and places the result in this matrix.
 
Methods inherited from class maspack.matrix.Matrix3dObject
colSize, determinant, epsilonEquals, equals, frobeniusNorm, get, get, getColumn, getColumn, getRow, getRow, infinityNorm, invert, mul, mul, mulInverse, mulInverse, mulInverseTranspose, mulInverseTranspose, mulTranspose, mulTranspose, negate, oneNorm, rowSize, set, setColumn, setColumn, setIdentity, setRow, setRow, transpose
 
Methods inherited from class maspack.matrix.MatrixObject
epsilonEquals, equals, equals, get, getColumn, getRow, isFixedSize, scan, set, set, setColumn, setRow, setSize, toString, toString, toString
 
Methods inherited from class java.lang.Object
getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SymmetricMatrix3d

public SymmetricMatrix3d()
Creates a symmetric matrix and initializes it to zero.


SymmetricMatrix3d

public SymmetricMatrix3d(double[] vals)
Creates a symmetric matrix and initializes its elements from an array of doubles. Values in the array should be stored using row-major order, so that element (i,j) is stored at location i*colSize()+j. Only the diagonal and upper off-diagonal values are used; the lower off-diagonal elements are copied from the upper off-diagonal elements.

Parameters:
vals - array from which values are copied

SymmetricMatrix3d

public SymmetricMatrix3d(Matrix3dObject M)
Creates a symmetric matrix and initializes its elements from the diagonal and upper off-diagonal elements of M.

Parameters:
M - matrix whose values are to be copied.

SymmetricMatrix3d

public SymmetricMatrix3d(double m00,
                         double m11,
                         double m22,
                         double m01,
                         double m02,
                         double m12)
Creates a symmetric matrix and initializes its elements from the specified diagonal and uppper off-diagonal values.

Parameters:
m00 - element (0,0)
m11 - element (1,1)
m22 - element (2,2)
m01 - element (0,1)
m02 - element (0,2)
m12 - element (1,2)
Method Detail

set

public void set(Matrix3dObject M)
Sets the elements of this matrix from the the diagonal and upper off-diagonal elements of M.

Overrides:
set in class Matrix3dObject
Parameters:
M - matrix whose values are to be copied.

set

public void set(double[] vals)
Sets the elements of this matrix from an array of doubles. The elements in the array should be stored using row-major order, so that element (i,j) is stored at location i*colSize()+j. Only the diagonal and upper off-diaginal values are used; the lower off-diagonal elements are copied from the upper off-diagonal elements.

Overrides:
set in class Matrix3dObject
Parameters:
vals - array from which values are copied

set

public void set(double m00,
                double m11,
                double m22,
                double m01,
                double m02,
                double m12)
Sets the values of this matrix from the specified diagonal and uppper off-diagonal values.

Parameters:
m00 - element (0,0)
m11 - element (1,1)
m22 - element (2,2)
m01 - element (0,1)
m02 - element (0,2)
m12 - element (1,2)

mulLeftAndTransposeRight

public void mulLeftAndTransposeRight(Matrix3dObject M)
Computes M T M', where T is this matrix, and M' is the transpose of M, and places the result in this matrix.

Parameters:
M - matrix to multiply by

mulTransposeLeftAndRight

public void mulTransposeLeftAndRight(Matrix3dObject M)
Computes M' T M, where T is this matrix, and M' is the transpose of M, and places the result in this matrix.

Parameters:
M - matrix to multiply by

mulTransposeLeft

public void mulTransposeLeft(Matrix3dObject M)
Computes M' M, where M is a supplied matrix and M' is its transpose, and places the (symmetric) result in this matrix.

Parameters:
M - matrix to form product from

add

public void add(SymmetricMatrix3d M1,
                SymmetricMatrix3d M2)
Adds matrix M1 to M2 and places the result in this matrix.

Parameters:
M1 - left-hand matrix
M2 - right-hand matrix

add

public void add(SymmetricMatrix3d M1)
Adds this matrix to M1 and places the result in this matrix.

Parameters:
M1 - right-hand matrix

sub

public void sub(SymmetricMatrix3d M1,
                SymmetricMatrix3d M2)
Subtracts matrix M1 from M2 and places the result in this matrix.

Parameters:
M1 - left-hand matrix
M2 - right-hand matrix

sub

public void sub(SymmetricMatrix3d M1)
Subtracts this matrix from M1 and places the result in this matrix.

Parameters:
M1 - right-hand matrix

scale

public void scale(double s)
Scales the elements of this matrix by s.

Parameters:
s - scaling factor

scale

public void scale(double s,
                  SymmetricMatrix3d M1)
Scales the elements of matrix M1 by s and places the results in this matrix.

Parameters:
s - scaling factor
M1 - matrix to be scaled

negate

public void negate(SymmetricMatrix3d M1)
Sets this matrix to the negative of M1.

Parameters:
M1 - matrix to negate

setZero

public void setZero()
Sets the elements of this matrix to zero.


setRandom

public void setRandom()
Sets the elements of this matrix to uniformly distributed random values in the range -0.5 (inclusive) to 0.5 (exclusive). Matrix symmetry is preserved.


setRandom

public void setRandom(double lower,
                      double upper)
Sets the elements of this matrix to uniformly distributed random values in a specified range. Matrix symmetry is preserved.

Parameters:
lower - lower random value (inclusive)
upper - upper random value (exclusive)

setRandom

public void setRandom(double lower,
                      double upper,
                      java.util.Random generator)
Sets the elements of this matrix to uniformly distributed random values in a specified range, using a supplied random number generator. Matrix symmetry is preserved.

Parameters:
lower - lower random value (inclusive)
upper - upper random value (exclusive)
generator - random number generator

setDiagonal

public void setDiagonal(Vector3d diag)
Sets this matrix to a diagonal matrix whose values are specified by diag.

Parameters:
diag - diagonal values

setDiagonal

public void setDiagonal(double[] vals)
Sets this matrix to a diagonal matrix whose values are specified by the array vals.

Parameters:
vals - diagonal values

getEigenValues

public void getEigenValues(double[] eig)

getEigenValues

public void getEigenValues(Vector3d eig)
Quickly computes the eigenvalues of this symmetric matrix. These are computed from the cube roots of the characteristic polynomial, which is fast at the expense of some accuracy.

Parameters:
eig - Resulting eigenvalues

getSVD

public void getSVD(Matrix3dObject U,
                   Vector3d sig,
                   Matrix3dObject V)
Quickly computes the singular value decomposition U S V' of this symmetric matrix. This routine works by solving a cubic equation to obtain the eigenvalues, and so is around 5 times faster than the corresponding routine in javax.vecmath, though possibly at the expense of some precision.

Parameters:
U - if non-null, used to store the first orthogonal matrix in the decomposition.
sig - required parameter, used to store the 3 singular values of the matrix, sorted from largest to smallest.
V - if non-null, used to store the second orthogonal matrix in the decomposition (note that the returned value is V and not V').

getCholesky

public void getCholesky(Matrix3d L)
Computes the Cholesky decomposition of this matrix, which is assumed to be positive definite. This decomposition takes the form
M = L L'
where M is the original matrix, L is a lower-triangular matrix and L' denotes its transpose. symmetric matrix.

Parameters:
L - returns the lower triangular part of the decomposition
Throws:
java.lang.IllegalArgumentException - if the matrix is not positive definite.