jv.vecmath

## Class PdMatrix

• java.lang.Object
• jv.vecmath.PdMatrix
• ### Field Summary

Fields
Modifier and Type Field and Description
`double[][]` `m_data`
Data array containing the components of the vector.
• ### Constructor Summary

Constructors
Constructor and Description
`PdMatrix()`
Create a new matrix of zero size.
`PdMatrix(double[][] x)`
Constructs a matrix having same size and given initial data as given array.
`PdMatrix(int aSize)`
Create a square matrix with given dimension.
```PdMatrix(int iSize, int jSize)```
Create a non-square matrix with given dimensions.
• ### Method Summary

Methods
Modifier and Type Method and Description
`void` `add(PdMatrix m)`
Add given matrix to this, this = this+m.
`void` ```add(PdMatrix m1, PdMatrix m2)```
Add two matrices and assign to this, this = m1+m2.
`void` ```addEntry(int i, int j, double value)```
Add value to component of matrix, and possibly enlarge matrix if too small.
`boolean` `adjoint(PdVector v)`
Compute `this = v * v^t` unsing adjoint(v, v).
`boolean` ```adjoint(PdVector v, PdVector w)```
Compute this = v * w^t.
`void` ```blend(double a, PdMatrix u, double b, PdMatrix v, double c, PdMatrix w)```
Interpolate between three matrices with given weights, i.e.
`void` ```blend(PdBary bary, PdMatrix u, PdMatrix v, PdMatrix w)```
Interpolate between three matrices with given barycentric weights.
`void` `clear()`
Set all entries to zero.
`java.lang.Object` `clone()`
Duplicate matrix and data array.
`void` `copy(PdMatrix m)`
Copy given matrix to this, this = m.
`static boolean` ```copy(PdMatrix[] dataDest, int destInd, PdMatrix[] dataSrc, int srcInd, int size)```
`static PdMatrix` `copyNew(PdMatrix mat)`
Create a new matrix as clone of argument matrix.
`static PdMatrix[]` `copyNew(PdMatrix[] data)`
`static PdMatrix[]` ```copyNew(PdMatrix[] data, int size)```
`double` `det()`
Compute determinant square matrix with dimensions less or equal four.
`double` `det33()`
Compute determinant of (3*3) left upper block of matrix.
`static PdMatrix` ```expandComponents(PdMatrix mat, int dim)```
Create a bigger matrix such that each original entry expands to a (dim, dim)-diagonal matrix.
`PdVector` `getColumn(int aColumn)`
Get column vector of matrix.
`double[][]` `getEntries()`
Return a copy of content of matrix as array of arrays of doubles.
`double` ```getEntry(int i, int j)```
Get the component of matrix at (i-th row, j-th column).
`int` `getISize()`
Get number of rows of matrix.
`int` `getJSize()`
Get number of columns of matrix.
`int` `getNumCols()`
Get number of columns of matrix.
`int` `getNumRows()`
Get number of rows of matrix.
`PdVector` `getRow(int aRow)`
Get row vector of matrix.
`int` `getSize()`
Get dimension of square matrix, return -1 for non-square matrices.
`boolean` `invert()`
Invert a square matrix of dimension less than five by `this = inverse(this)`.
`boolean` `invert(PdMatrix m)`
Invert a square matrix of dimension less than five by `this = inverse(m)`.
`boolean` `invert34(PdMatrix m)`
Invert the top-left 3x4 square of a matrix44 in place.
`boolean` ```invertTopLeft(PdMatrix m, int aSubSize)```
Invert the top-left subSize x subSize square of a matrix m in place and assign full matrix m to this matrix.
`boolean` `isSquare()`
Check if matrix is square.
`void` `leftMult(PdMatrix m)`
Multiply with square matrix from left of same sizes using `this = m*this`.
`void` ```leftMult(PdMatrix m, int size)```
Multiply a submatrix of this matrix with a submatrix of the parameter matrix.
`PdVector` ```leftMultMatrix(PdVector out, PdVector in)```
Multiply this matrix with vector and fill output vector, `out = this*in.`
``` ```
`void` ```mult(PdMatrix mat1, PdMatrix mat2)```
Multiply two matrices of possibly different sizes using `this = mat1*mat2`.
`double` ```multQuadratic(PdVector left, PdVector right)```
Compute `left^T*this*right`.
`void` `multScalar(double scalar)`
Multiply all matrix components with scalar.
`void` ```multScalar(PdMatrix m, double scalar)```
Multiply all matrix components of m with scalar s, this = m*s.
`static PdMatrix[]` ```realloc(PdMatrix[] data, int arraySize)```
`static PdMatrix[]` ```realloc(PdMatrix[] data, int arraySize, int iSize, int jSize)```
`void` `rightMult(PdMatrix m)`
Multiply with square matrix from right of same sizes using `this = this*m`.
`void` ```rightMult(PdMatrix m, int size)```
Multiply a submatrix of this matrix with a submatrix of the parameter matrix.
`PdVector` ```rightMultMatrix(PdVector out, PdVector in)```
Multiply this matrix with vector and fill output vector, `out = in*this.`
``` ```
`void` `set(double[][] x)`
Assign values of array, and adjust length of matrix if different from length of array.
`void` ```setColumn(int aColumn, PdVector aVector)```
Set column vector of matrix.
`void` `setColumns(PdVector[] aVector)`
Fill matrix with array of column vectors.
`void` `setConstant(double aValue)`
Set all matrix entries to a constant value.
`void` `setDiagonal(PdVector diag)`
Set diagonal entries of a square matrix to components of a given vector.
`void` ```setEntry(int i, int j, double value)```
Assign value to component of matrix, and possibly enlarge matrix if too small.
`void` `setIdentity()`
Initialize square matrix to be identity matrix.
`void` ```setRow(int aRow, PdVector aVector)```
Set row vector of matrix.
`void` `setRows(PdVector[] aVector)`
Fill matrix with array of row vectors.
`void` `setSize(int size)`
Resize square matrix with new dimension (size, size).
`void` ```setSize(int iSize, int jSize)```
Resize matrix to new dimension (iSize, jSize) with iSize rows and jSize columns.
`void` `sub(PdMatrix m)`
Subtract given matrix from this, this = this-m.
`void` ```sub(PdMatrix m1, PdMatrix m2)```
Subtract two matrices and assign to this, this = m1-m2.
`java.lang.String` `toShortString()`
Create a short string representation of matrix with all instance variables.
`java.lang.String` `toString()`
Create a multi-line string representation with detailed information about all instance variables.
`void` `transpose()`
Transpose a square matrix by `this = transpose(this)`.
`void` `transpose(PdMatrix m)`
Transpose a matrix by `this = transpose(m)`.
• ### Methods inherited from class java.lang.Object

`equals, getClass, hashCode, notify, notifyAll, wait, wait, wait`
• ### Field Detail

• #### m_data

`public double[][] m_data`
Data array containing the components of the vector. Array has public access for efficiency reasons in numerical computations, although method access should be preferred. Do not modify length of array directly.
• ### Constructor Detail

• #### PdMatrix

`public PdMatrix()`
Create a new matrix of zero size.
• #### PdMatrix

`public PdMatrix(int aSize)`
Create a square matrix with given dimension.
• #### PdMatrix

```public PdMatrix(int iSize,
int jSize)```
Create a non-square matrix with given dimensions.
• #### PdMatrix

`public PdMatrix(double[][] x)`
Constructs a matrix having same size and given initial data as given array.
• ### Method Detail

• #### realloc

```public static PdMatrix[] realloc(PdMatrix[] data,
int arraySize,
int iSize,
int jSize)```
• #### realloc

```public static PdMatrix[] realloc(PdMatrix[] data,
int arraySize)```
• #### copyNew

`public static PdMatrix[] copyNew(PdMatrix[] data)`
• #### copyNew

```public static PdMatrix[] copyNew(PdMatrix[] data,
int size)```
• #### copyNew

`public static PdMatrix copyNew(PdMatrix mat)`
Create a new matrix as clone of argument matrix.
• #### copy

```public static boolean copy(PdMatrix[] dataDest,
int destInd,
PdMatrix[] dataSrc,
int srcInd,
int size)```
• #### set

`public void set(double[][] x)`
Assign values of array, and adjust length of matrix if different from length of array.
• #### getNumRows

`public int getNumRows()`
Get number of rows of matrix.
Specified by:
`getNumRows` in interface `PdMatrixIf`
• #### getNumCols

`public int getNumCols()`
Get number of columns of matrix.
Specified by:
`getNumCols` in interface `PdMatrixIf`
• #### getISize

`public int getISize()`
Get number of rows of matrix.
• #### getJSize

`public int getJSize()`
Get number of columns of matrix.
• #### getSize

`public int getSize()`
Get dimension of square matrix, return -1 for non-square matrices.
• #### setSize

`public void setSize(int size)`
Resize square matrix with new dimension (size, size). Existing content of matrix is kept as much as possible.
• #### setSize

```public void setSize(int iSize,
int jSize)```
Resize matrix to new dimension (iSize, jSize) with iSize rows and jSize columns. Existing content of matrix is kept as much as possible.
• #### getEntries

`public double[][] getEntries()`
Return a copy of content of matrix as array of arrays of doubles.
• #### getEntry

```public double getEntry(int i,
int j)```
Get the component of matrix at (i-th row, j-th column).
Specified by:
`getEntry` in interface `PdMatrixIf`
• #### setEntry

```public void setEntry(int i,
int j,
double value)```
Assign value to component of matrix, and possibly enlarge matrix if too small.
Specified by:
`setEntry` in interface `PdMatrixIf`

```public void addEntry(int i,
int j,
double value)```
Add value to component of matrix, and possibly enlarge matrix if too small.
Specified by:
`addEntry` in interface `PdMatrixIf`
• #### isSquare

`public boolean isSquare()`
Check if matrix is square.
Specified by:
`isSquare` in interface `PdMatrixIf`
• #### setIdentity

`public void setIdentity()`
Initialize square matrix to be identity matrix.
• #### setConstant

`public void setConstant(double aValue)`
Set all matrix entries to a constant value.
• #### clear

`public void clear()`
Set all entries to zero.
Specified by:
`clear` in interface `PdMatrixIf`
• #### setDiagonal

`public void setDiagonal(PdVector diag)`
Set diagonal entries of a square matrix to components of a given vector. No other values of matrix are modified. Size of vector must be equal or larger than size of square matrix.
Parameters:
`diag` - Vector with diagonal components
• #### getRow

`public PdVector getRow(int aRow)`
Get row vector of matrix. Method returns null if row index out of bounds.
• #### setRow

```public void setRow(int aRow,
PdVector aVector)```
Set row vector of matrix. Length of vector must be equal or greater than number of columns. Dimension of matrix is not modified.
• #### getColumn

`public PdVector getColumn(int aColumn)`
Get column vector of matrix. Method returns null if column index out of bounds.
• #### setColumn

```public void setColumn(int aColumn,
PdVector aVector)```
Set column vector of matrix. Length of vector must be equal or greater than number of rows. Dimension of matrix is not modified.
• #### setRows

`public void setRows(PdVector[] aVector)`
Fill matrix with array of row vectors. Number of vectors and length of each vector must be equal or greater than corresponding sizes of matrix. Dimension of matrix is not modified.
• #### setColumns

`public void setColumns(PdVector[] aVector)`
Fill matrix with array of column vectors. Number of vectors and length of each vector must be equal or greater than corresponding sizes of matrix. Dimension of matrix is not modified.

`public void add(PdMatrix m)`
Add given matrix to this, this = this+m. Dimensions of argument matrix must be equal or larger than of this.

```public void add(PdMatrix m1,
PdMatrix m2)```
Add two matrices and assign to this, this = m1+m2. Dimensions of argument matrices must be equal or larger than of this.
• #### sub

`public void sub(PdMatrix m)`
Subtract given matrix from this, this = this-m. Dimensions of argument matrix must be equal or larger than of this.
• #### sub

```public void sub(PdMatrix m1,
PdMatrix m2)```
Subtract two matrices and assign to this, this = m1-m2. Dimensions of argument matrices must be equal or larger than of this.
• #### copy

`public void copy(PdMatrix m)`
Copy given matrix to this, this = m. Dimensions of argument matrix must be equal or larger than of this.
• #### multScalar

`public void multScalar(double scalar)`
Multiply all matrix components with scalar.
Specified by:
`multScalar` in interface `PdMatrixIf`
• #### multScalar

```public void multScalar(PdMatrix m,
double scalar)```
Multiply all matrix components of m with scalar s, this = m*s. Dimensions of argument matrix must be equal or larger than of this.
• #### det

`public double det()`
Compute determinant square matrix with dimensions less or equal four.
• #### det33

`public double det33()`
Compute determinant of (3*3) left upper block of matrix.
• #### leftMult

```public void leftMult(PdMatrix m,
int size)```
Multiply a submatrix of this matrix with a submatrix of the parameter matrix.. Size of 'this' does not change. Matrices must be larger than size of submatrix.
Parameters:
`m` - parameter matrix
`size` - size of square sub matrix affected within this.
• #### leftMult

`public void leftMult(PdMatrix m)`
Multiply with square matrix from left of same sizes using `this = m*this`. Size of 'this' does not change.
• #### rightMult

```public void rightMult(PdMatrix m,
int size)```
Multiply a submatrix of this matrix with a submatrix of the parameter matrix.. Size of 'this' does not change. Matrices must be larger than size of submatrix.
Parameters:
`m` - parameter matrix
`size` - size of square sub matrix affected within this.
• #### rightMult

`public void rightMult(PdMatrix m)`
Multiply with square matrix from right of same sizes using `this = this*m`. Size of 'this' does not change.
• #### mult

```public void mult(PdMatrix mat1,
PdMatrix mat2)```
Multiply two matrices of possibly different sizes using `this = mat1*mat2`. Size of 'this' is adjusted to have number of rows equal to first factor and number of columns equal to second factor.

• #### leftMultMatrix

```public PdVector leftMultMatrix(PdVector out,
PdVector in)```
Multiply this matrix with vector and fill output vector, `out = this*in.`. Matrix need not be square. Input vector must have same size as number of columns of this matrix. Method modifies size of output vector to number of rows of this matrix. If output vector is null then it is created.

Specified by:
`leftMultMatrix` in interface `PdMatrixIf`
• #### rightMultMatrix

```public PdVector rightMultMatrix(PdVector out,
PdVector in)```
Multiply this matrix with vector and fill output vector, `out = in*this.`. Matrix need not be square. Input vector must have same size as number of rows of this matrix. Method modifies size of output vector to number of columns of this matrix. If output vector is null then it is created.

Specified by:
`rightMultMatrix` in interface `PdMatrixIf`
• #### transpose

`public void transpose()`
Transpose a square matrix by `this = transpose(this)`.
Specified by:
`transpose` in interface `PdMatrixIf`
• #### transpose

`public void transpose(PdMatrix m)`
Transpose a matrix by `this = transpose(m)`.
• #### invert

`public boolean invert()`
Invert a square matrix of dimension less than five by `this = inverse(this)`.
• #### invert

`public boolean invert(PdMatrix m)`
Invert a square matrix of dimension less than five by `this = inverse(m)`.
Returns:
`false` if error occurred, and if arg is singular call this.setIdentity().
• #### invertTopLeft

```public boolean invertTopLeft(PdMatrix m,
int aSubSize)```
Invert the top-left subSize x subSize square of a matrix m in place and assign full matrix m to this matrix.
• #### invert34

`public boolean invert34(PdMatrix m)`
Invert the top-left 3x4 square of a matrix44 in place.

`public boolean adjoint(PdVector v)`
Compute `this = v * v^t` unsing adjoint(v, v).

```public boolean adjoint(PdVector v,
PdVector w)```
Compute this = v * w^t.
• #### toString

`public java.lang.String toString()`
Create a multi-line string representation with detailed information about all instance variables.
Overrides:
`toString` in class `java.lang.Object`
• #### toShortString

`public java.lang.String toShortString()`
Create a short string representation of matrix with all instance variables.
• #### expandComponents

```public static PdMatrix expandComponents(PdMatrix mat,
int dim)```
Create a bigger matrix such that each original entry expands to a (dim, dim)-diagonal matrix.
• #### blend

```public void blend(double a,
PdMatrix u,
double b,
PdMatrix v,
double c,
PdMatrix w)```
Interpolate between three matrices with given weights, i.e. `this = u*a + v*b + w*c`. If the matrix 'this' is empty, the size of this is adjusted equal to the size of the matrix u. Otherwise interpolation is done up to length of result vector.
Parameters:
`a` - weight of first matrix
`u` - first matrix
`b` - weight of second matrix
`v` - second matrix
`c` - weight of third matrix
`w` - third matrix
• #### blend

```public void blend(PdBary bary,
PdMatrix u,
PdMatrix v,
PdMatrix w)```
Interpolate between three matrices with given barycentric weights. Uses `this = u*bary.getEntry(0) + v*bary.getEntry(1) + w*bary.getEntry(2)`. If the matrix 'this' is empty, the size of this is adjusted equal to the size of the matrix u. Otherwise interpolation is done up to length of result vector.
Parameters:
`bary` - barycentric weights of three matrices
`u` - first matrix
`v` - second matrix
`w` - third matrix

```public double multQuadratic(PdVector left,
PdVector right)```
Compute `left^T*this*right`. The matrix is interpreted as a quadratic form.
Specified by:
`multQuadratic` in interface `PdMatrixIf`
Parameters:
`left` - The left argument.
`right` - The right argument.
Returns:
`left^T*this*right`.