Top Description Fields Constructors Methods
org.apache.commons.math3.linear

public Class DiagonalMatrix

extends AbstractRealMatrix
implements Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable
Imports
java.io.Serializable, org.apache.commons.math3.exception.DimensionMismatchException, .NotStrictlyPositiveException, .NullArgumentException, .NumberIsTooLargeException, .OutOfRangeException, org.apache.commons.math3.util.FastMath, .MathUtils, .Precision

Implementation of a diagonal matrix.
Since
3.1.1

Field Summary

Modifier and TypeField and Description
private final double[]
data

Entries of the diagonal.

private static final long
serialVersionUID

Serializable version identifier.

Constructor Summary

AccessConstructor and Description
public
DiagonalMatrix(final int
Number of rows and columns in the new matrix.
dimension
)

Creates a matrix with the supplied dimension.

public
DiagonalMatrix(final double[]
Data for the new matrix.
d
)

Creates a matrix using the input array as the underlying data.

public
DiagonalMatrix(final double[]
Data for new matrix.
d
,
final boolean
if true, the input array will be copied, otherwise it will be referenced.
copyArray
)

Creates a matrix using the input array as the underlying data.

Method Summary

Modifier and TypeMethod and Description
public DiagonalMatrix

Returns:

this + m.
add
(final DiagonalMatrix
Matrix to be added.
m
)

Compute the sum of this and m.

public void
addToEntry(final int
Row index of the entry to be modified.
row
,
final int
Column index of the entry to be modified.
column
,
final double
value to add to the matrix entry.
increment
)

Overrides org.apache.commons.math3.linear.AbstractRealMatrix.addToEntry.

Implements org.apache.commons.math3.linear.RealMatrix.addToEntry.

Adds (in place) the specified value to the specified entry of this matrix.

public RealMatrix
public RealMatrix
createMatrix(final int
the number of rows in the new matrix
rowDimension
,
final int
the number of columns in the new matrix
columnDimension
)

Implements abstract org.apache.commons.math3.linear.AbstractRealMatrix.createMatrix.

Implements org.apache.commons.math3.linear.RealMatrix.createMatrix.

Create a new RealMatrix of the same type as the instance with the supplied row and column dimensions.

private void
ensureZero(final double
value to check
value
)

Ensure a value is zero.

public int
public double[][]
getData()

Overrides org.apache.commons.math3.linear.AbstractRealMatrix.getData.

Implements org.apache.commons.math3.linear.RealMatrix.getData.

Returns matrix entries as a two-dimensional array.

public double[]

Returns:

1-dimensional array of entries.
getDataRef
()

Gets a reference to the underlying data array.

public double
getEntry(final int
Row index of entry to be fetched.
row
,
final int
Column index of entry to be fetched.
column
)

Implements abstract org.apache.commons.math3.linear.AbstractRealMatrix.getEntry.

Implements org.apache.commons.math3.linear.RealMatrix.getEntry.

Get the entry in the specified row and column.

public int
public DiagonalMatrix

Returns:

the inverse of m
inverse
()

Computes the inverse of this diagonal matrix.

public DiagonalMatrix

Returns:

the inverse of m
inverse
(double
Singularity threshold.
threshold
)

Computes the inverse of this diagonal matrix.

public boolean

Returns:

true if the matrix is singular, false otherwise
isSingular
(double
Singularity threshold.
threshold
)

Returns whether this diagonal matrix is singular, i.e. any diagonal entry is equal to 0 within the given threshold.

public DiagonalMatrix

Returns:

this * m
multiply
(final DiagonalMatrix
matrix to postmultiply by
m
)

Returns the result of postmultiplying this by m.

public RealMatrix

Returns:

this * m
multiply
(final RealMatrix
matrix to postmultiply by
m
)

Overrides org.apache.commons.math3.linear.AbstractRealMatrix.multiply.

Implements org.apache.commons.math3.linear.RealMatrix.multiply.

Returns the result of postmultiplying this by m.

public void
multiplyEntry(final int
Row index of the entry to be modified.
row
,
final int
Column index of the entry to be modified.
column
,
final double
Multiplication factor for the matrix entry.
factor
)

Overrides org.apache.commons.math3.linear.AbstractRealMatrix.multiplyEntry.

Implements org.apache.commons.math3.linear.RealMatrix.multiplyEntry.

Multiplies (in place) the specified entry of this matrix by the specified value.

public double[]
operate(final double[]
the vector to operate on
v
)

Overrides org.apache.commons.math3.linear.AbstractRealMatrix.operate.

Implements org.apache.commons.math3.linear.RealMatrix.operate.

Returns the result of multiplying this by the vector v.

public double[]
preMultiply(final double[]
the row vector to premultiply by
v
)

Overrides org.apache.commons.math3.linear.AbstractRealMatrix.preMultiply.

Implements org.apache.commons.math3.linear.RealMatrix.preMultiply.

Returns the (row) vector result of premultiplying this by the vector v.

public RealVector
preMultiply(final RealVector
the row vector to premultiply by
v
)

Overrides org.apache.commons.math3.linear.AbstractRealMatrix.preMultiply.

Implements org.apache.commons.math3.linear.RealMatrix.preMultiply.

Returns the (row) vector result of premultiplying this by the vector v.

public void
setEntry(final int
Row index of entry to be set.
row
,
final int
Column index of entry to be set.
column
,
final double
the new value of the entry.
value
)

Implements abstract org.apache.commons.math3.linear.AbstractRealMatrix.setEntry.

Implements org.apache.commons.math3.linear.RealMatrix.setEntry.

Set the entry in the specified row and column.

public DiagonalMatrix

Returns:

this - m
subtract
(final DiagonalMatrix
Matrix to be subtracted.
m
)

Returns this minus m.

Inherited from org.apache.commons.math3.linear.AbstractRealMatrix:
addcopySubMatrixcopySubMatrixequalsgetColumngetColumnMatrixgetColumnVectorgetFrobeniusNormgetNormgetRowgetRowMatrixgetRowVectorgetSubMatrixgetSubMatrixgetTracehashCodeisSquareoperatepowerpreMultiplyscalarAddscalarMultiplysetColumnsetColumnMatrixsetColumnVectorsetRowsetRowMatrixsetRowVectorsetSubMatrixsubtracttoStringtransposewalkInColumnOrderwalkInColumnOrderwalkInColumnOrderwalkInColumnOrderwalkInOptimizedOrderwalkInOptimizedOrderwalkInOptimizedOrderwalkInOptimizedOrderwalkInRowOrderwalkInRowOrderwalkInRowOrderwalkInRowOrder

Field Detail

databack to summary
private final double[] data

Entries of the diagonal.

serialVersionUIDback to summary
private static final long serialVersionUID

Serializable version identifier.

Constructor Detail

DiagonalMatrixback to summary
public DiagonalMatrix(final int dimension) throws NotStrictlyPositiveException

Creates a matrix with the supplied dimension.

Parameters
dimension:int

Number of rows and columns in the new matrix.

Exceptions
NotStrictlyPositiveException:
if the dimension is not positive.
DiagonalMatrixback to summary
public DiagonalMatrix(final double[] d)

Creates a matrix using the input array as the underlying data.
The input array is copied, not referenced.

Parameters
d:double[]

Data for the new matrix.

DiagonalMatrixback to summary
public DiagonalMatrix(final double[] d, final boolean copyArray) throws NullArgumentException

Creates a matrix using the input array as the underlying data.
If an array is created specially in order to be embedded in a this instance and not used directly, the copyArray may be set to false. This will prevent the copying and improve performance as no new array will be built and no data will be copied.

Parameters
d:double[]

Data for new matrix.

copyArray:boolean

if true, the input array will be copied, otherwise it will be referenced.

Exceptions
NullArgumentException:
if d is null

Method Detail

addback to summary
public DiagonalMatrix add(final DiagonalMatrix m) throws MatrixDimensionMismatchException

Compute the sum of this and m.

Parameters
m:DiagonalMatrix

Matrix to be added.

Returns:DiagonalMatrix

this + m.

Exceptions
MatrixDimensionMismatchException:
if m is not the same size as this.
addToEntryback to summary
public void addToEntry(final int row, final int column, final double increment) throws OutOfRangeException, NumberIsTooLargeException

Overrides org.apache.commons.math3.linear.AbstractRealMatrix.addToEntry.

Implements org.apache.commons.math3.linear.RealMatrix.addToEntry.

Doc from org.apache.commons.math3.linear.AbstractRealMatrix.addToEntry.

Adds (in place) the specified value to the specified entry of this matrix. Row and column indices start at 0.

Parameters
row:int

Doc from org.apache.commons.math3.linear.RealMatrix.addToEntry.

Row index of the entry to be modified.

column:int

Doc from org.apache.commons.math3.linear.RealMatrix.addToEntry.

Column index of the entry to be modified.

increment:double

Doc from org.apache.commons.math3.linear.RealMatrix.addToEntry.

value to add to the matrix entry.

Annotations
@Override
Exceptions
OutOfRangeException:

Doc from org.apache.commons.math3.linear.RealMatrix.addToEntry.

if the row or column index is not valid.

NumberIsTooLargeException:
if row != column and increment is non-zero.
copyback to summary
public RealMatrix copy()

Implements abstract org.apache.commons.math3.linear.AbstractRealMatrix.copy.

Implements org.apache.commons.math3.linear.RealMatrix.copy.

Doc from org.apache.commons.math3.linear.AbstractRealMatrix.copy.

Returns a (deep) copy of this.

Returns:RealMatrix

Doc from org.apache.commons.math3.linear.RealMatrix.copy.

matrix copy

Annotations
@Override
createMatrixback to summary
public RealMatrix createMatrix(final int rowDimension, final int columnDimension) throws NotStrictlyPositiveException, DimensionMismatchException

Implements abstract org.apache.commons.math3.linear.AbstractRealMatrix.createMatrix.

Implements org.apache.commons.math3.linear.RealMatrix.createMatrix.

Doc from org.apache.commons.math3.linear.AbstractRealMatrix.createMatrix.

Create a new RealMatrix of the same type as the instance with the supplied row and column dimensions.

Parameters
rowDimension:int

Doc from org.apache.commons.math3.linear.RealMatrix.createMatrix.

the number of rows in the new matrix

columnDimension:int

Doc from org.apache.commons.math3.linear.RealMatrix.createMatrix.

the number of columns in the new matrix

Returns:RealMatrix

Doc from org.apache.commons.math3.linear.RealMatrix.createMatrix.

a new matrix of the same type as the instance

Annotations
@Override
Exceptions
NotStrictlyPositiveException:

Doc from org.apache.commons.math3.linear.RealMatrix.createMatrix.

if row or column dimension is not positive.

DimensionMismatchException:
if the requested dimensions are not equal.
ensureZeroback to summary
private void ensureZero(final double value) throws NumberIsTooLargeException

Ensure a value is zero.

Parameters
value:double

value to check

Exceptions
NumberIsTooLargeException:
if value is not zero
getColumnDimensionback to summary
public int getColumnDimension()

Implements abstract org.apache.commons.math3.linear.AbstractRealMatrix.getColumnDimension.

Implements org.apache.commons.math3.linear.AnyMatrix.getColumnDimension.

Doc from org.apache.commons.math3.linear.AbstractRealMatrix.getColumnDimension.

Returns the number of columns of this matrix.

Returns:int

the number of columns.

Annotations
@Override
getDataback to summary
public double[][] getData()

Overrides org.apache.commons.math3.linear.AbstractRealMatrix.getData.

Implements org.apache.commons.math3.linear.RealMatrix.getData.

Doc from org.apache.commons.math3.linear.AbstractRealMatrix.getData.

Returns matrix entries as a two-dimensional array.

Returns:double[][]

Doc from org.apache.commons.math3.linear.RealMatrix.getData.

2-dimensional array of entries

Annotations
@Override
getDataRefback to summary
public double[] getDataRef()

Gets a reference to the underlying data array.

Returns:double[]

1-dimensional array of entries.

getEntryback to summary
public double getEntry(final int row, final int column) throws OutOfRangeException

Implements abstract org.apache.commons.math3.linear.AbstractRealMatrix.getEntry.

Implements org.apache.commons.math3.linear.RealMatrix.getEntry.

Doc from org.apache.commons.math3.linear.AbstractRealMatrix.getEntry.

Get the entry in the specified row and column. Row and column indices start at 0.

Parameters
row:int

Doc from org.apache.commons.math3.linear.RealMatrix.getEntry.

Row index of entry to be fetched.

column:int

Doc from org.apache.commons.math3.linear.RealMatrix.getEntry.

Column index of entry to be fetched.

Returns:double

Doc from org.apache.commons.math3.linear.RealMatrix.getEntry.

the matrix entry at (row, column).

Annotations
@Override
Exceptions
OutOfRangeException:

Doc from org.apache.commons.math3.linear.RealMatrix.getEntry.

if the row or column index is not valid.

getRowDimensionback to summary
public int getRowDimension()

Implements abstract org.apache.commons.math3.linear.AbstractRealMatrix.getRowDimension.

Implements org.apache.commons.math3.linear.AnyMatrix.getRowDimension.

Doc from org.apache.commons.math3.linear.AbstractRealMatrix.getRowDimension.

Returns the number of rows of this matrix.

Returns:int

the number of rows.

Annotations
@Override
inverseback to summary
public DiagonalMatrix inverse() throws SingularMatrixException

Computes the inverse of this diagonal matrix.

Note

this method will use a singularity threshold of 0, use inverse(double) if a different threshold is needed.

Returns:DiagonalMatrix

the inverse of m

Exceptions
SingularMatrixException:
if the matrix is singular
Since
3.3
inverseback to summary
public DiagonalMatrix inverse(double threshold) throws SingularMatrixException

Computes the inverse of this diagonal matrix.

Parameters
threshold:double

Singularity threshold.

Returns:DiagonalMatrix

the inverse of m

Exceptions
SingularMatrixException:
if the matrix is singular
Since
3.3
isSingularback to summary
public boolean isSingular(double threshold)

Returns whether this diagonal matrix is singular, i.e. any diagonal entry is equal to 0 within the given threshold.

Parameters
threshold:double

Singularity threshold.

Returns:boolean

true if the matrix is singular, false otherwise

Since
3.3
multiplyback to summary
public DiagonalMatrix multiply(final DiagonalMatrix m) throws DimensionMismatchException

Returns the result of postmultiplying this by m.

Parameters
m:DiagonalMatrix

matrix to postmultiply by

Returns:DiagonalMatrix

this * m

Exceptions
DimensionMismatchException:
if columnDimension(this) != rowDimension(m)
multiplyback to summary
public RealMatrix multiply(final RealMatrix m) throws DimensionMismatchException

Overrides org.apache.commons.math3.linear.AbstractRealMatrix.multiply.

Implements org.apache.commons.math3.linear.RealMatrix.multiply.

Returns the result of postmultiplying this by m.

Parameters
m:RealMatrix

matrix to postmultiply by

Returns:RealMatrix

this * m

Annotations
@Override
Exceptions
DimensionMismatchException:
if columnDimension(this) != rowDimension(m)
multiplyEntryback to summary
public void multiplyEntry(final int row, final int column, final double factor) throws OutOfRangeException

Overrides org.apache.commons.math3.linear.AbstractRealMatrix.multiplyEntry.

Implements org.apache.commons.math3.linear.RealMatrix.multiplyEntry.

Doc from org.apache.commons.math3.linear.AbstractRealMatrix.multiplyEntry.

Multiplies (in place) the specified entry of this matrix by the specified value. Row and column indices start at 0.

Parameters
row:int

Doc from org.apache.commons.math3.linear.RealMatrix.multiplyEntry.

Row index of the entry to be modified.

column:int

Doc from org.apache.commons.math3.linear.RealMatrix.multiplyEntry.

Column index of the entry to be modified.

factor:double

Doc from org.apache.commons.math3.linear.RealMatrix.multiplyEntry.

Multiplication factor for the matrix entry.

Annotations
@Override
Exceptions
OutOfRangeException:

Doc from org.apache.commons.math3.linear.RealMatrix.multiplyEntry.

if the row or column index is not valid.

operateback to summary
public double[] operate(final double[] v) throws DimensionMismatchException

Overrides org.apache.commons.math3.linear.AbstractRealMatrix.operate.

Implements org.apache.commons.math3.linear.RealMatrix.operate.

Doc from org.apache.commons.math3.linear.AbstractRealMatrix.operate.

Returns the result of multiplying this by the vector v.

Parameters
v:double[]

Doc from org.apache.commons.math3.linear.RealMatrix.operate.

the vector to operate on

Returns:double[]

Doc from org.apache.commons.math3.linear.RealMatrix.operate.

this * v

Annotations
@Override
Exceptions
DimensionMismatchException:

Doc from org.apache.commons.math3.linear.RealMatrix.operate.

if the length of v does not match the column dimension of this.

preMultiplyback to summary
public double[] preMultiply(final double[] v) throws DimensionMismatchException

Overrides org.apache.commons.math3.linear.AbstractRealMatrix.preMultiply.

Implements org.apache.commons.math3.linear.RealMatrix.preMultiply.

Doc from org.apache.commons.math3.linear.AbstractRealMatrix.preMultiply.

Returns the (row) vector result of premultiplying this by the vector v.

Parameters
v:double[]

Doc from org.apache.commons.math3.linear.RealMatrix.preMultiply.

the row vector to premultiply by

Returns:double[]

Doc from org.apache.commons.math3.linear.RealMatrix.preMultiply.

v * this

Annotations
@Override
Exceptions
DimensionMismatchException:

Doc from org.apache.commons.math3.linear.RealMatrix.preMultiply.

if the length of v does not match the row dimension of this.

preMultiplyback to summary
public RealVector preMultiply(final RealVector v) throws DimensionMismatchException

Overrides org.apache.commons.math3.linear.AbstractRealMatrix.preMultiply.

Implements org.apache.commons.math3.linear.RealMatrix.preMultiply.

Doc from org.apache.commons.math3.linear.AbstractRealMatrix.preMultiply.

Returns the (row) vector result of premultiplying this by the vector v.

Parameters
v:RealVector

Doc from org.apache.commons.math3.linear.RealMatrix.preMultiply.

the row vector to premultiply by

Returns:RealVector

Doc from org.apache.commons.math3.linear.RealMatrix.preMultiply.

v * this

Annotations
@Override
Exceptions
DimensionMismatchException:

Doc from org.apache.commons.math3.linear.RealMatrix.preMultiply.

if the dimension of v does not match the row dimension of this.

setEntryback to summary
public void setEntry(final int row, final int column, final double value) throws OutOfRangeException, NumberIsTooLargeException

Implements abstract org.apache.commons.math3.linear.AbstractRealMatrix.setEntry.

Implements org.apache.commons.math3.linear.RealMatrix.setEntry.

Doc from org.apache.commons.math3.linear.AbstractRealMatrix.setEntry.

Set the entry in the specified row and column. Row and column indices start at 0.

Parameters
row:int

Doc from org.apache.commons.math3.linear.RealMatrix.setEntry.

Row index of entry to be set.

column:int

Doc from org.apache.commons.math3.linear.RealMatrix.setEntry.

Column index of entry to be set.

value:double

Doc from org.apache.commons.math3.linear.RealMatrix.setEntry.

the new value of the entry.

Annotations
@Override
Exceptions
OutOfRangeException:

Doc from org.apache.commons.math3.linear.RealMatrix.setEntry.

if the row or column index is not valid

NumberIsTooLargeException:
if row != column and value is non-zero.
subtractback to summary
public DiagonalMatrix subtract(final DiagonalMatrix m) throws MatrixDimensionMismatchException

Returns this minus m.

Parameters
m:DiagonalMatrix

Matrix to be subtracted.

Returns:DiagonalMatrix

this - m

Exceptions
MatrixDimensionMismatchException:
if m is not the same size as this.