sim.util.mantissa.linalg
Class DiagonalMatrix

java.lang.Object
  extended by sim.util.mantissa.linalg.Matrix
      extended by sim.util.mantissa.linalg.SquareMatrix
          extended by sim.util.mantissa.linalg.DiagonalMatrix
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable

public class DiagonalMatrix
extends SquareMatrix
implements java.io.Serializable, java.lang.Cloneable

This class implements diagonal matrices of linear algebra.

This file is from the "Mantissa" Java software package found at http://www.spaceroots.org/software/mantissa/index.html. The license is included at the end of the source file.

See Also:
Serialized Form

Field Summary
 
Fields inherited from class sim.util.mantissa.linalg.Matrix
columns, data, rows
 
Constructor Summary
DiagonalMatrix(DiagonalMatrix d)
          Copy constructor.
DiagonalMatrix(int order)
          Simple constructor.
DiagonalMatrix(int order, double value)
          Simple constructor.
DiagonalMatrix(int order, double[] data)
          Simple constructor.
 
Method Summary
 Matrix duplicate()
          Polymorphic copy operator.
 double getDeterminant(double epsilon)
          Get the determinant of the matrix.
 SquareMatrix getInverse(double epsilon)
          Invert the instance.
 sim.util.mantissa.linalg.NonNullRange getRangeForColumn(int j)
          Set a range to the non null part covered by a column.
 sim.util.mantissa.linalg.NonNullRange getRangeForRow(int i)
          Set a range to the non null part covered by a row.
 void setElement(int i, int j, double value)
          Set a matrix element.
 Matrix solve(Matrix b, double epsilon)
          Solve the A.X = B equation.
 
Methods inherited from class sim.util.mantissa.linalg.SquareMatrix
solve
 
Methods inherited from class sim.util.mantissa.linalg.Matrix
add, getColumns, getElement, getRows, getTranspose, mul, mul, selfMul, sub, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DiagonalMatrix

public DiagonalMatrix(int order)
Simple constructor. This constructor builds a diagonal matrix of specified order, all elements on the diagonal being ones (so this is an identity matrix).

Parameters:
order - order of the matrix

DiagonalMatrix

public DiagonalMatrix(int order,
                      double value)
Simple constructor. This constructor builds a diagonal matrix of specified order and set all diagonal elements to the same value.

Parameters:
order - order of the matrix
value - value for the diagonal elements

DiagonalMatrix

public DiagonalMatrix(int order,
                      double[] data)
Simple constructor. Build a matrix with specified elements.

Parameters:
order - order of the matrix
data - table of the matrix elements (stored row after row)

DiagonalMatrix

public DiagonalMatrix(DiagonalMatrix d)
Copy constructor.

Parameters:
d - diagonal matrix to copy
Method Detail

duplicate

public Matrix duplicate()
Description copied from class: Matrix
Polymorphic copy operator. This method build a new object of the same type of the instance. It is somewhat similar to the Object.clone() method, except that it has public access, it doesn't throw any specific exception and it returns a Matrix.

Specified by:
duplicate in class Matrix
See Also:
Object.clone()

setElement

public void setElement(int i,
                       int j,
                       double value)
Description copied from class: Matrix
Set a matrix element.

Overrides:
setElement in class Matrix
Parameters:
i - row index, from 0 to rows - 1
j - column index, from 0 to cols - 1
value - value of the element
See Also:
Matrix.getElement(int, int)

getDeterminant

public double getDeterminant(double epsilon)
Description copied from class: SquareMatrix
Get the determinant of the matrix.

Specified by:
getDeterminant in class SquareMatrix
Parameters:
epsilon - threshold on matrix elements below which the matrix is considered singular (this is used by the derived classes that use a factorization to compute the determinant)
Returns:
the determinant of the matrix

getInverse

public SquareMatrix getInverse(double epsilon)
                        throws SingularMatrixException
Description copied from class: SquareMatrix
Invert the instance.

Overrides:
getInverse in class SquareMatrix
Parameters:
epsilon - threshold on matrix elements below which the matrix is considered singular
Returns:
the inverse matrix of the instance
Throws:
SingularMatrixException - if the matrix is singular

solve

public Matrix solve(Matrix b,
                    double epsilon)
             throws SingularMatrixException
Description copied from class: SquareMatrix
Solve the A.X = B equation.

Specified by:
solve in class SquareMatrix
Parameters:
b - second term of the equation
epsilon - threshold on matrix elements below which the matrix is considered singular
Returns:
a matrix X such that A.X = B, where A is the instance
Throws:
SingularMatrixException - if the matrix is singular

getRangeForRow

public sim.util.mantissa.linalg.NonNullRange getRangeForRow(int i)
Description copied from class: Matrix
Set a range to the non null part covered by a row.

Specified by:
getRangeForRow in class Matrix
Parameters:
i - index of the row
Returns:
range of non nul elements in the specified row
See Also:
Matrix.getRangeForColumn(int)

getRangeForColumn

public sim.util.mantissa.linalg.NonNullRange getRangeForColumn(int j)
Description copied from class: Matrix
Set a range to the non null part covered by a column.

Specified by:
getRangeForColumn in class Matrix
Parameters:
j - index of the column
Returns:
range of non nul elements in the specified column
See Also:
Matrix.getRangeForRow(int)