public class MatrixNd extends DenseMatrixBase implements java.io.Serializable, LinearTransformNd, Clonable, VectorObject<MatrixNd>
Normally, these matrices can be resized, either explicitly through a call to
setSize
, or implicitly through operations that require the
matrix size to be modified. The exception is when this matrix is either a
submatrix, or is being referenced by a submatrix (see SubMatrixNd
).
Matrix.Partition, Matrix.WriteFormat
INDEFINITE, POSITIVE_DEFINITE, SPD, SYMMETRIC
Constructor and Description |
---|
MatrixNd()
Creates a matrix will initial row and column sizes of zero.
|
MatrixNd(double[][] values)
Creates a matrix from a two dimensional array of doubles.
|
MatrixNd(int numRows,
int numCols)
Creates a matrix of a specific size, and initializes its elements to 0.
|
MatrixNd(int numRows,
int numCols,
double[] values)
Creates a matrix of specific size and initializes its elements from an
array of values.
|
MatrixNd(Matrix M)
Creates a matrix whose size and elements are the same as an existing
Matrix.
|
MatrixNd(MatrixNd M)
Creates a matrix which is a copy of an existing one.
|
MatrixNd(Vector v)
Creates a matrix whose size and elements correspond to a Vector.
|
Modifier and Type | Method and Description |
---|---|
void |
absolute()
Sets the elements of this matrix to their absolute values.
|
void |
add(int i,
int j,
double value)
Adds a value to the indicated entry.
|
void |
add(MatrixNd M)
Adds this matrix to M and places the result in this matrix.
|
void |
add(MatrixNd M1,
MatrixNd M2)
Adds matrix M1 to M2 and places the result in this matrix.
|
void |
addDiagonal(double d)
Adds
d to the diagonal of this matrix. |
void |
addDiagonal(double[] diag)
Adds a diagonal term to this matrix whose elements are specified by the
leading elements of an array of doubles
|
void |
addDiagonal(VectorNd diag)
Adds a diagonal term to this matrix whose elements are specified by an
array.
|
void |
addObj(MatrixNd M1)
Adds
v1 to this vector. |
void |
addScaledSubMatrix(int baseRow,
int baseCol,
double s,
MatrixNd Msrc)
Adds a scaled submatrix to this matrix.
|
void |
addSubMatrix(int baseRow,
int baseCol,
MatrixNd Msrc)
Adds a submatrix to this matrix.
|
void |
checkConsistency()
Check that the internal structures of this matrix are consistent.
|
MatrixNd |
clone() |
int |
colSize()
Number of columns in the matrix associated with this transformation.
|
void |
copySubMatrix(int baseRowSrc,
int baseColSrc,
int numRows,
int numCols,
Matrix Msrc,
int baseRowDest,
int baseColDest)
Copies a sub matrix from a specified source matrix
Msrc to
a region of this matrix. |
boolean |
epsilonEquals(MatrixNd M1,
double epsilon)
Returns true if the elements of this matrix equal those of matrix
M1 within a prescribed tolerance epsilon . |
boolean |
equals(MatrixNd M1)
Returns true if the elements of this matrix exactly equal those of matrix
M1 . |
double |
frobeniusNorm()
Returns the Frobenius norm of this matrix.
|
void |
get(double[] values)
Copies the elements of this matrix into an array of doubles.
|
void |
get(double[] values,
int w) |
double |
get(int i,
int j)
Gets a single element of this matrix.
|
double[] |
getBuffer()
Returns the internal buffer used to store the elements in this matrix.
|
int |
getBufferBase()
Returns the internal buffer base index of this matrix, used for computing
the index necessary to reference a particular element.
|
int |
getBufferWidth()
Returns the internal buffer width of this matrix, used for computing the
index necessary to reference a particular element.
|
void |
getColumn(int j,
double[] values)
Copies a column of this matrix into an array of doubles.
|
void |
getColumn(int j,
double[] values,
int off)
Copies a column of this matrix into an array of doubles, starting at a
specified offset.
|
void |
getColumn(int j,
Vector v)
Copies a column of this matrix into a
Vector . |
void |
getRow(int i,
double[] values)
Copies a row of this matrix into an array of doubles.
|
void |
getRow(int i,
double[] values,
int off)
Copies a row of this matrix into an array of doubles, starting at a
specified offset.
|
void |
getRow(int i,
Vector v)
Copies a row of this matrix into a
Vector . |
void |
getSubMatrix(int[] rows,
int[] cols,
MatrixNd Mdest)
Gets a submatrix of this matrix.
|
void |
getSubMatrix(int baseRow,
int baseCol,
MatrixNd Mdest)
Gets a submatrix of this matrix.
|
double |
infinityNorm()
Returns the infinity norm of this matrix.
|
boolean |
invert()
Inverts this matrix in place, returning false if the matrix is detected to
be singular.
|
boolean |
invert(MatrixNd M1)
Inverts the matrix M1 and places the result in this matrix, returning
false if the matrix is detected to be singular.
|
boolean |
isFixedSize()
Returns true if this matrix is of fixed size.
|
boolean |
isSubMatrix()
Returns true if the this matrix is a submatrix; i.e., is a member of the
subclass
SubMatrixNd . |
static void |
main(java.lang.String[] args) |
double |
maxElement()
Returns the maximum element value of this matrix.
|
double |
minElement()
Returns the minimum element value of this matrix.
|
void |
mul(DenseMatrixBase M1,
DenseMatrixBase M2)
Multiplies matrix M1 by M2 and places the result in this matrix.
|
void |
mul(MatrixNd M1)
Multiplies this matrix by M1 and places the result in this matrix.
|
void |
mul(MatrixNd M1,
MatrixNd M2)
Multiplies matrix M1 by M2 and places the result in this matrix.
|
void |
mulAdd(Matrix M1,
Matrix M2) |
void |
mulDiagonalLeft(double[] diag)
Pre-multiplies, in place, this matrix by a diagonal matrix whose
(diagonal) elements are specified by the leading elements of an array of
doubles.
|
void |
mulDiagonalLeft(VectorNd diag)
Pre-multiplies, in place, this matrix by a diagonal matrix whose
(diagonal) elements are specified by a vector.
|
void |
mulDiagonalRight(double[] diag)
Post-multiplies, in place, this matrix by a diagonal matrix whose
(diagonal) elements are specified by the leading elements of an array of
doubles.
|
void |
mulDiagonalRight(VectorNd diag)
Post-multiplies, in place, this matrix by a diagonal matrix whose
(diagonal) elements are specified by a vector.
|
void |
mulTranspose(MatrixNd M1)
Multiplies this matrix by the transpose of M1 and places the result in
this matrix.
|
void |
mulTransposeBoth(MatrixNd M1,
MatrixNd M2)
Multiplies the transpose of matrix M1 by the transpose of M2 and places
the result in this matrix.
|
void |
mulTransposeLeft(MatrixNd M1,
MatrixNd M2)
Multiplies the transpose of matrix M1 by M2 and places the result in this
matrix.
|
void |
mulTransposeLeftAdd(Matrix M1,
Matrix M2) |
void |
mulTransposeRight(MatrixNd M1,
MatrixNd M2)
Multiplies matrix M1 by the transpose of M2 and places the result in this
matrix.
|
void |
mulTransposeRightAdd(Matrix M1,
Matrix M2) |
void |
negate()
Negates this matrix in place.
|
void |
negate(MatrixNd M1)
Sets this matrix to the negative of M1.
|
double |
oneNorm()
Returns the 1 norm of this matrix.
|
void |
permuteColumns(int[] permutation)
Rearrange the columns of this matrix according to the specified
permutation, such that each column j is replaced by column permutation[j].
|
void |
permuteRows(int[] permutation)
Rearrange the rows of this matrix according to the specified permutation,
such that each row i is replaced by row permutation[i].
|
int |
rowSize()
Number of rows in the matrix associated with this transformation.
|
void |
scale(double s)
Scales the elements of this matrix by
s . |
void |
scale(double s,
MatrixNd M1)
Scales the elements of matrix M1 by
s and places the
results in this matrix. |
void |
scaledAdd(double s,
MatrixNd M)
Scales the matrix M and add the result to this matrix.
|
void |
scaledAdd(double s,
MatrixNd M1,
MatrixNd M2)
Computes s M1 + M2 and places the result in this matrix.
|
void |
scaledAddObj(double s,
MatrixNd M1)
Scales
v1 by s and adds it to this vector. |
void |
scaleObj(double s)
Scales this vector by
s . |
void |
set(double[] values)
Sets the elements of this matrix from an array of doubles.
|
void |
set(int i,
int j,
double value)
Sets a single element of this matrix.
|
void |
set(Matrix M)
Sets the size and values of this matrix to those of another matrix.
|
void |
set(MatrixNd M)
Sets the size and values of this matrix to those of matrix M.
|
void |
setBuffer(int numRows,
int numCols,
double[] buffer,
int bufWidth)
Explicitly sets the size and internal buffer associated with this matrix.
|
void |
setColumn(int j,
double[] values)
Sets a column of this matrix from an array of doubles.
|
void |
setColumn(int j,
Vector v)
Sets a column of this matrix from a
Vector . |
void |
setDiagonal(double[] diag)
Sets this matrix to a diagonal matrix whose diagonal elements are
specified by the leading elements of an array of doubles
|
void |
setDiagonal(VectorNd diag)
Sets this matrix to a diagonal matrix whose diagonal elements are
specified by an array.
|
void |
setIdentity()
Sets this matrix to the identity matrix.
|
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 |
setRandomOrthogonal()
Sets this matrix to a random orthogonal matrix.
|
void |
setRandomOrthogonal(java.util.Random generator)
Sets this matrix to a random orthogonal matrix, using a supplied random
number generator.
|
void |
setRandomSvd(double[] singularValues)
Sets this matrix to a random matrix with specified singular values.
|
void |
setRandomSvd(double[] singularValues,
java.util.Random generator)
Sets this matrix to a random matrix with specified singular values, using
a supplied random number generator.
|
void |
setRow(int i,
double[] values)
Set a row of this matrix from an array of doubles.
|
void |
setRow(int i,
Vector v)
Sets a row of this matrix from a
Vector . |
void |
setSize(int numRows,
int numCols)
Sets the size of this matrix.
|
void |
setSubMatrix(int[] rows,
int[] cols,
MatrixNd Msrc)
Sets a submatrix of this matrix.
|
void |
setSubMatrix(int baseRow,
int baseCol,
Matrix Msrc)
Sets a submatrix of this matrix.
|
void |
setZero()
Sets the elements of this matrix to zero.
|
void |
sub(MatrixNd M1)
Subtracts this matrix from M1 and places the result in this matrix.
|
void |
sub(MatrixNd M1,
MatrixNd M2)
Subtracts matrix M1 from M2 and places the result in this matrix.
|
void |
transpose()
Replaces this matrix by its tranpose.
|
void |
transpose(MatrixNd M1)
Takes the transpose of matrix M1 and places the result in this matrix.
|
void |
unsetBuffer()
Removes an explicit buffer provided for this matrix and replaces it with a
default implicit buffer.
|
add, set, set, set, setCCSValues, setCRSValues
containsNaN, determinant, epsilonEquals, equals, frobeniusNormSquared, get, getCCSIndices, getCCSIndices, getCCSIndices, getCCSValues, getCCSValues, getCCSValues, getCRSIndices, getCRSIndices, getCRSIndices, getCRSValues, getCRSValues, getCRSValues, getDefaultFormat, getSize, getSubMatrix, hasNaN, idString, isSymmetric, isWritable, maxNorm, mul, mul, mul, mulAdd, mulAdd, mulAdd, mulTranspose, mulTranspose, mulTranspose, mulTransposeAdd, mulTransposeAdd, mulTransposeAdd, numNonZeroVals, numNonZeroVals, scan, scan, setCRSValues, setDefaultFormat, toString, toString, toString, trace, write, write, write, write, write, write, write, writeToFile
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
mul
getThreeVectorValue
isWritable, scan, write
determinant, epsilonEquals, equals, frobeniusNormSquared, getCCSIndices, getCCSIndices, getCCSIndices, getCCSValues, getCCSValues, getCCSValues, getCRSIndices, getCRSIndices, getCRSIndices, getCRSValues, getCRSValues, getCRSValues, getSize, getSubMatrix, isSymmetric, maxNorm, mul, mul, mul, mulAdd, mulAdd, mulAdd, mulTranspose, mulTranspose, mulTranspose, mulTransposeAdd, mulTransposeAdd, mulTransposeAdd, numNonZeroVals, numNonZeroVals, scan, toString, toString, trace, write, write, write
public MatrixNd()
public MatrixNd(int numRows, int numCols)
numRows
- number of rowsnumCols
- number of columnsImproperSizeException
- if numRows or numCols are negativepublic MatrixNd(Matrix M)
M
- matrix object to be copied.public MatrixNd(Vector v)
v
- vector object to be copied.public MatrixNd(MatrixNd M)
M
- matrix to be copied.public MatrixNd(double[][] values)
values
- element values for the new matrixpublic MatrixNd(int numRows, int numCols, double[] values)
numRows
- number of rowsnumCols
- number of columnsvalues
- element values for the matrix, with element (i,j) stored at location
i*numCols+j
public final int rowSize()
mul
.rowSize
in interface LinearTransformNd
rowSize
in interface Matrix
rowSize
in class MatrixBase
public final int colSize()
mul
.colSize
in interface LinearTransformNd
colSize
in interface Matrix
colSize
in class MatrixBase
public boolean isFixedSize()
SubMatrixNd
). If the matrix is not of
fixed size, then it can be resized dynamically, either explicitly using
setSize
, or implicitly when being used as a result for
various matrix operations.isFixedSize
in interface Matrix
isFixedSize
in class MatrixBase
setSize(int, int)
public void setSize(int numRows, int numCols)
isFixedSize
returns false. If necessary, this
operation will enlarge the internal buffer associated with this matrix,
invalidating buffers previously returned by getBuffer
.
If a matrix is resized, then any previous element values which are still within the new matrix dimensions are preserved. Other (new) element values are undefined.
setSize
in interface Matrix
setSize
in class MatrixBase
numRows
- new row sizenumCols
- new column sizeImproperSizeException
- if this matrix has an explicit internal buffer and that buffer is too
small to support the requested sizejava.lang.UnsupportedOperationException
- if this matrix has fixed sizeisFixedSize()
public boolean isSubMatrix()
SubMatrixNd
.public double[] getBuffer()
Roughly speaking, elements are stored in the buffer in row-column order.
However, the buffer may be larger than the matrix, and there may be extra
space at the beginning of the buffer. The buffer index which access the
element (i,j) is computed as i*w + j + b
, where
w
and b
are the width and base values
returned by getBufferWidth
and
getBufferBase
, respectively.
Note also that if this matrix is a submatrix, the buffer will actually belong to the root matrix, and so modifying values in the buffer (including those outside the nominal range of this matrix) will change the root matrix as well.
If this matrix is resized, then the internal buffer may change and the buffer previously returned by this routine may no longer be valid.
getBufferWidth()
,
getBufferBase()
,
setBuffer(int, int, double[], int)
public int getBufferWidth()
getBuffer()
public int getBufferBase()
getBuffer()
public void setBuffer(int numRows, int numCols, double[] buffer, int bufWidth)
[i*bufWidth+j]
. In particular, bufWidth
must
satisfy bufWidth >= numCols
, and the length of
buffer
must satisfy
buffer.length >= numRows*bufWidth
.
The matrix can continue to be resized as long as
requested sizes stay do not violate these bounds. The value of
bufWidth
will become the value returned by getBufferWidth
, while the value returned by getBufferBase
will be 0.numRows
- new row sizenumCols
- new column sizebuffer
- explicit buffer for this matrixbufWidth
- width for the explicit bufferjava.lang.IllegalStateException
- if this matrix has referring submatrices or is itself a submatrixImproperSizeException
- if the specified buffer and/or width is too small for the requested sizegetBufferWidth()
,
getBufferBase()
,
unsetBuffer()
public void unsetBuffer()
java.lang.IllegalStateException
- if this matrix does not have an explicit buffer given by
setBuffer
java.lang.IllegalStateException
- if this matrix has referring submatricessetBuffer(int, int, double[], int)
public void copySubMatrix(int baseRowSrc, int baseColSrc, int numRows, int numCols, Matrix Msrc, int baseRowDest, int baseColDest) throws ImproperSizeException
Msrc
to
a region of this matrix. The base row and column of the source and
destination may be different.baseRowSrc
- starting submatrix row in the source matrixbaseColSrc
- starting submatrix column in the source matrixnumRows
- number of rows in the submatrixnumCols
- number of columns in the submatrixMsrc
- source matrixbaseRowDest
- starting submatrix row in this matrixbaseColDest
- starting submatrix column in this matrixImproperSizeException
- if the specified submatrix dimensions are infeasiblegetSubMatrix(int,int,MatrixNd)
,
setSubMatrix(int,int,Matrix)
public final double get(int i, int j)
get
in interface Matrix
get
in class MatrixBase
i
- element row indexj
- element column indexpublic final void get(double[] values)
(i,j)
is
stored at location i*colSize()+j
.get
in interface Matrix
get
in class MatrixBase
values
- array into which values are copiedpublic final void get(double[] values, int w)
public final void getColumn(int j, double[] values)
getColumn
in interface Matrix
getColumn
in class MatrixBase
j
- column indexvalues
- array into which the column is copiedpublic final void getColumn(int j, double[] values, int off)
getColumn
in interface Matrix
getColumn
in class MatrixBase
j
- column indexvalues
- array into which the column is copiedoff
- offset in values where copying should beginpublic final void getRow(int i, double[] values)
getRow
in interface Matrix
getRow
in class MatrixBase
i
- row indexvalues
- array into which the row is copiedpublic final void getRow(int i, double[] values, int off)
getRow
in interface Matrix
getRow
in class MatrixBase
i
- row indexvalues
- array into which the row is copiedoff
- offset in values where copying should beginpublic final void getColumn(int j, Vector v)
Vector
.getColumn
in interface Matrix
getColumn
in class MatrixBase
j
- column indexv
- vector into which the column is copiedpublic final void getRow(int i, Vector v)
Vector
.getRow
in interface Matrix
getRow
in class MatrixBase
i
- row indexv
- vector into which the row is copiedpublic void getSubMatrix(int baseRow, int baseCol, MatrixNd Mdest) throws ImproperSizeException
baseRow
and baseCol
, and the
values are written into the matrix Mdest
. The size of the
submatrix is determined by the dimensions of Mdest
.baseRow
- first row of the submatrixbaseCol
- first column of the submatrixMdest
- destination for submatrix valuesImproperSizeException
- if baseRow
or baseCol
are negative, or if
the submatrix exceeds the current matrix bounds.copySubMatrix(int, int, int, int, maspack.matrix.Matrix, int, int)
public void getSubMatrix(int[] rows, int[] cols, MatrixNd Mdest) throws ImproperSizeException
rows
and the cols
,
respectively, and the values are written into the matrix
Mdest
. The size of the submatrix is determined by the
existing dimensions of Mdest
.rows
- row indices of the submatrixcols
- column indices of the submatrixMdest
- destination for submatrix valuesImproperSizeException
- if the number of rows or columns exceed the dimensions of
Mdest
, or if any of the specified indices lie outside the
bounds of this matrix.public final void set(int i, int j, double value)
set
in interface DenseMatrix
set
in class DenseMatrixBase
i
- element row indexj
- element column indexvalue
- element valuepublic final void add(int i, int j, double value)
public final void set(double[] values)
(i,j)
is stored at location i*colSize()+j
.set
in interface DenseMatrix
set
in class DenseMatrixBase
values
- array from which values are copiedpublic final void setColumn(int j, double[] values)
setColumn
in interface DenseMatrix
setColumn
in class DenseMatrixBase
j
- column indexvalues
- array from which column values are copiedpublic final void setRow(int i, double[] values)
setRow
in interface DenseMatrix
setRow
in class DenseMatrixBase
i
- row indexvalues
- array from which the row is copiedpublic void setColumn(int j, Vector v)
Vector
.setColumn
in interface DenseMatrix
setColumn
in class DenseMatrixBase
j
- column indexv
- vector from which the column is copiedpublic void setRow(int i, Vector v)
Vector
.setRow
in interface DenseMatrix
setRow
in class DenseMatrixBase
i
- row indexv
- vector from which the row is copiedpublic void setSubMatrix(int baseRow, int baseCol, Matrix Msrc) throws ImproperSizeException
baseRow
and baseCol
, and the
new values are given by the matrix Msrc
. The size of the
submatrix is determined by the dimensions of Msrc
.setSubMatrix
in interface DenseMatrix
setSubMatrix
in class DenseMatrixBase
baseRow
- index of the first row of the submatrixbaseCol
- index of the first column of the submatrixMsrc
- new values for the submatrix.ImproperSizeException
- if baseRow
or baseCol
are negative, or if
the submatrix exceeds the current matrix boundscopySubMatrix(int, int, int, int, maspack.matrix.Matrix, int, int)
public void setSubMatrix(int[] rows, int[] cols, MatrixNd Msrc) throws ImproperSizeException
rows
and the cols
,
respectively, and the new values are given by the matrix Msrc
.
The size of the submatrix is determined by the existing dimensions of
Msrc
.rows
- row indices of the submatrixcols
- column indices of the submatrixMsrc
- new values for the submatrixImproperSizeException
- if the number of rows or columns exceed the dimensions of
Msrc
, or if any of the specified indices lie outside the
bounds of this matrix.public void addSubMatrix(int baseRow, int baseCol, MatrixNd Msrc) throws ImproperSizeException
baseRow
and
baseCol
, respectively, and the values to add are given by
the matrix Msrc
. The size of the submatrix is determined by
the existing dimensions of Msrc
.baseRow
- index of the first row of the submatrixbaseCol
- index of the first column of the submatrixMsrc
- values to add to the submatrix.ImproperSizeException
- if baseRow
or baseCol
are negative, or if
the submatrix exceeds the current matrix boundsjava.lang.IllegalArgumentException
- if Msrc
equals this
this matrix.public void addScaledSubMatrix(int baseRow, int baseCol, double s, MatrixNd Msrc) throws ImproperSizeException
baseRow
and
baseCol
, respectively, and the values to add are given by
the matrix Msrc
. The size of the submatrix is determined by
the existing dimensions of Msrc
.baseRow
- index of the first row of the submatrixbaseCol
- index of the first column of the submatrixs
- scale factor for the added submatrixMsrc
- values to add to the submatrix.ImproperSizeException
- if baseRow
or baseCol
are negative, or if
the submatrix exceeds the current matrix boundsjava.lang.IllegalArgumentException
- if Msrc
equals this
this matrix.public void set(Matrix M)
set
in interface Matrix
set
in class DenseMatrixBase
M
- matrix whose size and values are copiedpublic void set(MatrixNd M) throws ImproperSizeException
set
in interface VectorObject<MatrixNd>
M
- matrix to be copiedImproperSizeException
- if matrices have different sizes and this matrix cannot be resized
accordinglypublic void setIdentity()
public void setZero()
setZero
in interface VectorObject<MatrixNd>
public void setDiagonal(VectorNd diag)
diag
- diagonal elements for this matrixImproperSizeException
- if the size of diag
does not equal the minimum matrix
dimensionpublic void setDiagonal(double[] diag)
diag
- diagonal elements for this matrixImproperSizeException
- if the length of diag
is less than the minimum matrix
dimensionpublic void addDiagonal(VectorNd diag)
diag
- diagonal elements to add to this matrixImproperSizeException
- if the size of diag
does not equal the minimum matrix
dimensionpublic void addDiagonal(double[] diag)
diag
- diagonal elements to add to this matrixImproperSizeException
- if the length of diag
is less than the minimum matrix
dimensionpublic void addDiagonal(double d)
d
to the diagonal of this matrix.d
- value to add to the diagonalpublic void setRandom()
setRandom
in class DenseMatrixBase
public void setRandom(double lower, double upper)
lower
- lower random value (inclusive)upper
- upper random value (exclusive)public void setRandom(double lower, double upper, java.util.Random generator)
lower
- lower random value (inclusive)upper
- upper random value (exclusive)generator
- random number generatorpublic void setRandomOrthogonal()
public void setRandomOrthogonal(java.util.Random generator)
generator
- random number generatorsetRandomOrthogonal()
public void setRandomSvd(double[] singularValues)
singularValues
- singular values for this matrixImproperSizeException
- if the length of singularValues
is less than the minimum
matrix dimensionpublic void setRandomSvd(double[] singularValues, java.util.Random generator)
singularValues
- singular values for this matrixgenerator
- random number generatorImproperSizeException
- if the length of singularValues
is less than the minimum
matrix dimensionsetRandomSvd(double[])
public void mul(MatrixNd M1)
M1
- right-hand matrixImproperSizeException
- if this matrix and M1 do not conform, or if this matrix needs resizing but
is of fixed sizepublic void mul(MatrixNd M1, MatrixNd M2) throws ImproperSizeException
M1
- left-hand matrixM2
- right-hand matrixImproperSizeException
- if matrices M1 and M2 do not comform, or if this matrix needs resizing but
is of fixed sizepublic void mul(DenseMatrixBase M1, DenseMatrixBase M2) throws ImproperSizeException
M1
- left-hand matrixM2
- right-hand matrixImproperSizeException
- if matrices M1 and M2 do not comform, or if this matrix needs resizing but
is of fixed sizepublic void mulTranspose(MatrixNd M1)
M1
- right-hand matrixImproperSizeException
- if this matrix and the transpose of M1 do not conform, or if this matrix
needs resizing but is of fixed sizepublic void mulTransposeRight(MatrixNd M1, MatrixNd M2) throws ImproperSizeException
M1
- left-hand matrixM2
- right-hand matrixImproperSizeException
- if M1 and the transpose of M2 do not comform, or if this matrix needs
resizing but is of fixed sizepublic void mulTransposeLeft(MatrixNd M1, MatrixNd M2) throws ImproperSizeException
M1
- left-hand matrixM2
- right-hand matrixImproperSizeException
- if the transpose of M1 and M2 do not comform, or if this matrix needs
resizing but is of fixed sizepublic void mulTransposeBoth(MatrixNd M1, MatrixNd M2) throws ImproperSizeException
M1
- left-hand matrixM2
- right-hand matrixImproperSizeException
- if the transpose of M1 and the transpose of M2 do not comform, or if this
matrix needs resizing but is of fixed sizepublic void mulDiagonalLeft(VectorNd diag)
diag
- specifies the diagonal elements of the implied left-hand matrixImproperSizeException
- if the size of diag
does not equal the row size of this
matrixpublic void mulDiagonalLeft(double[] diag)
diag
- specifies the diagonal elements of the implied left-hand matrixImproperSizeException
- if the length of diag
is less than the row size of this
matrixpublic void mulDiagonalRight(VectorNd diag)
diag
- specifies the diagonal elements of the implied right-hand matrixImproperSizeException
- if the size of diag
does not equal the column size of this
matrixpublic void mulDiagonalRight(double[] diag)
diag
- specifies the diagonal elements of the implied right-hand matrixImproperSizeException
- if the length of diag
is less than the column size of this
matrixpublic void absolute()
public double maxElement()
public double minElement()
public void add(MatrixNd M) throws ImproperSizeException
M
- right-hand matrixImproperSizeException
- if this matrix and M have different sizespublic void scaledAdd(double s, MatrixNd M) throws ImproperSizeException
s
- scaling factorM
- matrix to be scaled and addedImproperSizeException
- if this matrix and M have different sizespublic void scaledAdd(double s, MatrixNd M1, MatrixNd M2) throws ImproperSizeException
s
- scaling factorM1
- matrix to be scaledM2
- matrix to be addedImproperSizeException
- if matrices M1 and M2 have different sizes, or if this matrix needs
resizing but is of fixed sizepublic void add(MatrixNd M1, MatrixNd M2) throws ImproperSizeException
M1
- left-hand matrixM2
- right-hand matrixImproperSizeException
- if matrices M1 and M2 have different sizes, or if this matrix needs
resizing but is of fixed sizepublic void sub(MatrixNd M1) throws ImproperSizeException
M1
- right-hand matrixImproperSizeException
- if this matrix and M1 have different sizespublic void sub(MatrixNd M1, MatrixNd M2) throws ImproperSizeException
M1
- left-hand matrixM2
- right-hand matrixImproperSizeException
- if matrices M1 and M2 have different sizes, or if this matrix needs
resizing but is of fixed sizepublic void negate()
public void negate(MatrixNd M1) throws ImproperSizeException
M1
- matrix to negateImproperSizeException
- if this matrix needs resizing but is of fixed sizepublic void scale(double s, MatrixNd M1) throws ImproperSizeException
s
and places the
results in this matrix. This matrix is resized if necessary.s
- scaling factorM1
- matrix to be scaledImproperSizeException
- if this matrix needs resizing but is of fixed sizepublic void scale(double s)
s
.s
- scaling factorpublic void transpose()
ImproperSizeException
- if this matrix needs resizing but is of fixed sizepublic void transpose(MatrixNd M1) throws ImproperSizeException
M1
- matrix to take the transpose ofImproperSizeException
- if this matrix needs resizing but is of fixed sizepublic boolean epsilonEquals(MatrixNd M1, double epsilon)
M1
within a prescribed tolerance epsilon
.epsilonEquals
in interface VectorObject<MatrixNd>
M1
- matrix to compare withepsilon
- comparison tolerancepublic boolean equals(MatrixNd M1)
M1
.M1
- matrix to compare withpublic double infinityNorm()
infinityNorm
in interface Matrix
infinityNorm
in class MatrixBase
public double oneNorm()
oneNorm
in interface Matrix
oneNorm
in class MatrixBase
public double frobeniusNorm()
frobeniusNorm
in interface Matrix
frobeniusNorm
in class MatrixBase
public boolean invert() throws ImproperSizeException
ImproperSizeException
- if this matrix is not squarepublic boolean invert(MatrixNd M1) throws ImproperSizeException
M1
- matrix to take the inverse ofImproperSizeException
- if matrix M1 is not square, or if this matrix needs resizing but is of
fixed sizepublic void permuteColumns(int[] permutation)
permutation
- describes the column exchangesImproperSizeException
- if the length of permutation
is less than the column size
of this matrix.public void permuteRows(int[] permutation)
permutation
- describes the row exchangesImproperSizeException
- if the length of permutation
is less than the row size of
this matrix.public static void main(java.lang.String[] args)
public MatrixNd clone() throws java.lang.CloneNotSupportedException
public void checkConsistency()
DenseMatrixBase
checkConsistency
in interface Matrix
checkConsistency
in class DenseMatrixBase
public void scaleObj(double s)
s
.scaleObj
in interface VectorObject<MatrixNd>
public void addObj(MatrixNd M1)
v1
to this vector.addObj
in interface VectorObject<MatrixNd>
public void scaledAddObj(double s, MatrixNd M1)
v1
by s
and adds it to this vector.scaledAddObj
in interface VectorObject<MatrixNd>