org.ode4j.ode
Class DMatrix

java.lang.Object
  extended by org.ode4j.ode.OdeConstants
      extended by org.ode4j.ode.internal.ErrorHandler
          extended by org.ode4j.ode.internal.Common
              extended by org.ode4j.ode.DMisc
                  extended by org.ode4j.ode.DMatrix
Direct Known Subclasses:
DRotation

public class DMatrix
extends DMisc

Matrix math functions. Ported from matrix.h in C-interface.

Author:
Tilmann Zaeschke

Nested Class Summary
 
Nested classes/interfaces inherited from class org.ode4j.ode.internal.Common
org.ode4j.ode.internal.Common.DMatrix4
 
Nested classes/interfaces inherited from class org.ode4j.ode.internal.ErrorHandler
org.ode4j.ode.internal.ErrorHandler.dMessageFunction
 
Field Summary
 
Fields inherited from class org.ode4j.ode.internal.Common
d_ERR_IASSERT, d_ERR_LCP, d_ERR_UASSERT, d_ERR_UNKNOWN, d_MEMORY_OK, d_MEMORY_OUT_OF_MEMORY, dATOMICS_ENABLED, DBL_EPSILON, dDOUBLE, dEpsilon, dNODEBUG, dSINGLE, dTLS_ENABLED, dTRIMESH_16BIT_INDICES, dTRIMESH_ENABLED, dTRIMESH_GIMPACT, dTRIMESH_OPCODE, dTRIMESH_OPCODE_USE_OLD_TRIMESH_TRIMESH_COLLIDER, dUSE_MALLOC_FOR_ALLOCA, M_PI, M_SQRT1_2, MAX_FLOAT
 
Fields inherited from class org.ode4j.ode.OdeConstants
CONTACTS_UNIMPORTANT, dAllocateMaskAll, dContactApprox0, dContactApprox1, dContactApprox1_1, dContactApprox1_2, dContactBounce, dContactFDir1, dContactMotion1, dContactMotion2, dContactMotionN, dContactMu2, dContactSlip1, dContactSlip2, dContactSoftCFM, dContactSoftERP, dInfinity
 
Constructor Summary
DMatrix()
           
 
Method Summary
static boolean dFactorCholesky(DMatrix3 A)
          Do an in-place cholesky decomposition on the lower triangle of the n*n symmetric matrix A (which is stored by rows).
static boolean dFactorCholesky(double[] A, int n)
          Do an in-place cholesky decomposition on the lower triangle of the n*n symmetric matrix A (which is stored by rows).
static void dFactorLDLT(double[] A, double[] d, int n, int nskip)
          Factorize a matrix A into L*D*L', where L is lower triangular with ones on the diagonal, and D is diagonal.
static boolean dInvertPDMatrix(DMatrix3C A, DMatrix3 Ainv)
          Compute the inverse of the n*n positive definite matrix A and put it in Ainv.
static boolean dInvertPDMatrix(double[] A, double[] Ainv, int n)
           
static boolean dIsPositiveDefinite(DMatrix3C A)
          Check whether an n*n matrix A is positive definite, return 1/0 (yes/no).
static boolean dIsPositiveDefinite(double[] A, int n)
           
static void dLDLTAddTL(double[] L, double[] d, double[] a, int n, int nskip)
          Given an L*D*L' factorization of an n*n matrix A, return the updated factorization L2*D2*L2' of A plus the following "top left" matrix: [ b a' ] <-- b is a[0] [ a 0 ] <-- a is a[1..n-1] - L has size n*n, its leading dimension is nskip.
static void dLDLTRemove(double[] A, int[] p, double[] L, double[] d, int n1, int n2, int r, int nskip)
          Given an L*D*L' factorization of a permuted matrix A, produce a new factorization for row and column `r' removed.
static void dMultiply0(DMatrix3 A, DMatrix3C B, DMatrix3C C)
           
static void dMultiply0(double[] A, double[] B, double[] C, int p, int q, int r)
           
static void dMultiply0(DVector3 a, DMatrix3C B, DVector3C c)
           
static void dMultiply0(DVector3 a, DVector3C b, DMatrix3C C)
          Matrix multiplication.
static void dMultiply1(DMatrix3 A, DMatrix3C B, DMatrix3C C)
           
static void dMultiply1(double[] A, double[] B, double[] C, int p, int q, int r)
           
static void dMultiply1(DVector3 a, DMatrix3C B, DVector3C c)
           
static void dMultiply2(DMatrix3 A, DMatrix3C B, DMatrix3C C)
           
static void dMultiply2(double[] A, double[] B, double[] C, int p, int q, int r)
           
static void dMultiply2(DVector3 a, DMatrix3C B, DVector3C c)
           
static void dRemoveRowCol(double[] A, int n, int nskip, int r)
          Given an n*n matrix A (with leading dimension nskip), remove the r'th row and column by moving elements.
static void dSetValue(DVector3 a, double value)
          Set a vector/matrix to a specific value.
static void dSetZero(double[] a)
          Set a vector/matrix to all zeros.
static void dSolveCholesky(DMatrix3C L, DVector3 x)
          Solve for x: L*L'*x = b, and put the result back into x.
static void dSolveCholesky(double[] L, double[] x, int n)
          Solve for x: L*L'*x = b, and put the result back into x.
static void dSolveLDLT(double[] L, double[] d, double[] b, int n, int nskip)
          Given `L', a n*n lower triangular matrix with ones on the diagonal, and `d', a n*1 vector of the reciprocal diagonal elements of an n*n matrix D, solve L*D*L'*x=b where x,b are n*1.
static void dVectorScale(DVector3 a, DVector3C d)
          In matlab syntax: a(1:n) = a(1:n) .* d(1:n)
 
Methods inherited from class org.ode4j.ode.DMisc
dClearUpperTriangle, dClearUpperTriangle, dMakeRandomMatrix, dMakeRandomMatrix, dMakeRandomVector, dMakeRandomVector, dMakeRandomVector, dMaxDifference, dMaxDifference, dMaxDifference, dMaxDifference, dMaxDifferenceLowerTriangle, dPrintMatrix, dRand, dRandGetSeed, dRandInt, dRandReal, dRandSetSeed, dTestRand
 
Methods inherited from class org.ode4j.ode.internal.Common
dAASSERT, dAASSERT, dAtan2, dCeil, dCopysign, dCopySign, dCos, dDEBUGMSG, dFabs, dFloor, dFMod, dIASSERT, dIsNan, dIVERIFY, dNextAfter, dPAD, dRecip, dRecipSqrt, dSin, dSqrt, dUASSERT
 
Methods inherited from class org.ode4j.ode.internal.ErrorHandler
dDebug, dError, dGetDebugHandler, dGetErrorHandler, dGetMessageHandler, dMessage, dSetDebugHandler, dSetErrorHandler, dSetMessageHandler
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DMatrix

public DMatrix()
Method Detail

dSetZero

public static void dSetZero(double[] a)
Set a vector/matrix to all zeros.


dSetValue

public static void dSetValue(DVector3 a,
                             double value)
Set a vector/matrix to a specific value.


dMultiply0

public static void dMultiply0(DVector3 a,
                              DVector3C b,
                              DMatrix3C C)
Matrix multiplication. all matrices are stored in standard row format. the digit refers to the argument that is transposed: 0: A = B * C (sizes: A:p*r B:p*q C:q*r) 1: A = B' * C (sizes: A:p*r B:q*p C:q*r) 2: A = B * C' (sizes: A:p*r B:p*q C:r*q) case 1,2 are equivalent to saying that the operation is A=B*C but B or C are stored in standard column format.


dMultiply0

public static void dMultiply0(DVector3 a,
                              DMatrix3C B,
                              DVector3C c)
See Also:
dMultiply0(DVector3, DVector3C, DMatrix3C)

dMultiply0

public static void dMultiply0(DMatrix3 A,
                              DMatrix3C B,
                              DMatrix3C C)
See Also:
dMultiply0(DVector3, DVector3C, DMatrix3C)

dMultiply0

public static void dMultiply0(double[] A,
                              double[] B,
                              double[] C,
                              int p,
                              int q,
                              int r)
See Also:
dMultiply0(DVector3, DVector3C, DMatrix3C)

dMultiply1

public static void dMultiply1(DVector3 a,
                              DMatrix3C B,
                              DVector3C c)
See Also:
dMultiply0(DVector3, DVector3C, DMatrix3C)

dMultiply1

public static void dMultiply1(DMatrix3 A,
                              DMatrix3C B,
                              DMatrix3C C)
See Also:
dMultiply0(DVector3, DVector3C, DMatrix3C)

dMultiply1

public static void dMultiply1(double[] A,
                              double[] B,
                              double[] C,
                              int p,
                              int q,
                              int r)
See Also:
dMultiply0(DVector3, DVector3C, DMatrix3C)

dMultiply2

public static void dMultiply2(DVector3 a,
                              DMatrix3C B,
                              DVector3C c)
See Also:
dMultiply0(DVector3, DVector3C, DMatrix3C)

dMultiply2

public static void dMultiply2(DMatrix3 A,
                              DMatrix3C B,
                              DMatrix3C C)
See Also:
dMultiply0(DVector3, DVector3C, DMatrix3C)

dMultiply2

public static void dMultiply2(double[] A,
                              double[] B,
                              double[] C,
                              int p,
                              int q,
                              int r)
See Also:
dMultiply0(DVector3, DVector3C, DMatrix3C)

dFactorCholesky

public static boolean dFactorCholesky(DMatrix3 A)
Do an in-place cholesky decomposition on the lower triangle of the n*n symmetric matrix A (which is stored by rows). the resulting lower triangle will be such that L*L'=A. return 'true' on success and 'false' on failure (on failure the matrix is not positive definite).


dFactorCholesky

public static boolean dFactorCholesky(double[] A,
                                      int n)
Do an in-place cholesky decomposition on the lower triangle of the n*n symmetric matrix A (which is stored by rows). the resulting lower triangle will be such that L*L'=A. return 'true' on success and 'false' on failure (on failure the matrix is not positive definite).


dSolveCholesky

public static void dSolveCholesky(DMatrix3C L,
                                  DVector3 x)
Solve for x: L*L'*x = b, and put the result back into x. L is size n*n, b is size n*1. only the lower triangle of L is considered.


dSolveCholesky

public static void dSolveCholesky(double[] L,
                                  double[] x,
                                  int n)
Solve for x: L*L'*x = b, and put the result back into x. L is size n*n, b is size n*1. only the lower triangle of L is considered.


dInvertPDMatrix

public static boolean dInvertPDMatrix(DMatrix3C A,
                                      DMatrix3 Ainv)
Compute the inverse of the n*n positive definite matrix A and put it in Ainv. this is not especially fast. this returns 'true' on success (A was positive definite) or 'false' on failure (not PD).


dInvertPDMatrix

public static boolean dInvertPDMatrix(double[] A,
                                      double[] Ainv,
                                      int n)

dIsPositiveDefinite

public static boolean dIsPositiveDefinite(DMatrix3C A)
Check whether an n*n matrix A is positive definite, return 1/0 (yes/no). positive definite means that x'*A*x > 0 for any x. this performs a cholesky decomposition of A. if the decomposition fails then the matrix is not positive definite. A is stored by rows. A is not altered.


dIsPositiveDefinite

public static boolean dIsPositiveDefinite(double[] A,
                                          int n)

dFactorLDLT

public static void dFactorLDLT(double[] A,
                               double[] d,
                               int n,
                               int nskip)
Factorize a matrix A into L*D*L', where L is lower triangular with ones on the diagonal, and D is diagonal. A is an n*n matrix stored by rows, with a leading dimension of n rounded up to 4. L is written into the strict lower triangle of A (the ones are not written) and the reciprocal of the diagonal elements of D are written into d.


dVectorScale

public static void dVectorScale(DVector3 a,
                                DVector3C d)
In matlab syntax: a(1:n) = a(1:n) .* d(1:n)


dSolveLDLT

public static void dSolveLDLT(double[] L,
                              double[] d,
                              double[] b,
                              int n,
                              int nskip)
Given `L', a n*n lower triangular matrix with ones on the diagonal, and `d', a n*1 vector of the reciprocal diagonal elements of an n*n matrix D, solve L*D*L'*x=b where x,b are n*1. x overwrites b. the leading dimension of L is `nskip'.


dLDLTAddTL

public static void dLDLTAddTL(double[] L,
                              double[] d,
                              double[] a,
                              int n,
                              int nskip)
Given an L*D*L' factorization of an n*n matrix A, return the updated factorization L2*D2*L2' of A plus the following "top left" matrix: [ b a' ] <-- b is a[0] [ a 0 ] <-- a is a[1..n-1] - L has size n*n, its leading dimension is nskip. L is lower triangular with ones on the diagonal. only the lower triangle of L is referenced. - d has size n. d contains the reciprocal diagonal elements of D. - a has size n. the result is written into L, except that the left column of L and d[0] are not actually modified. see ldltaddTL.m for further comments.


dLDLTRemove

public static void dLDLTRemove(double[] A,
                               int[] p,
                               double[] L,
                               double[] d,
                               int n1,
                               int n2,
                               int r,
                               int nskip)
Given an L*D*L' factorization of a permuted matrix A, produce a new factorization for row and column `r' removed. - A has size n1*n1, its leading dimension in nskip. A is symmetric and positive definite. only the lower triangle of A is referenced. A itself may actually be an array of row pointers. - L has size n2*n2, its leading dimension in nskip. L is lower triangular with ones on the diagonal. only the lower triangle of L is referenced. - d has size n2. d contains the reciprocal diagonal elements of D. - p is a permutation vector. it contains n2 indexes into A. each index must be in the range 0..n1-1. - r is the row/column of L to remove. the new L will be written within the old L, i.e. will have the same leading dimension. the last row and column of L, and the last element of d, are undefined on exit. a fast O(n^2) algorithm is used. see ldltremove.m for further comments.


dRemoveRowCol

public static void dRemoveRowCol(double[] A,
                                 int n,
                                 int nskip,
                                 int r)
Given an n*n matrix A (with leading dimension nskip), remove the r'th row and column by moving elements. the new matrix will have the same leading dimension. the last row and column of A are untouched on exit.