Package jahuwaldt.js.param
Class Matrix3D<Q extends javax.measure.quantity.Quantity>
- java.lang.Object
-
- org.jscience.mathematics.vector.Matrix<Parameter<Q>>
-
- jahuwaldt.js.param.Matrix3D<Q>
-
- All Implemented Interfaces:
java.io.Serializable
,javolution.lang.Immutable
,javolution.lang.Realtime
,javolution.lang.ValueType
,javolution.xml.XMLSerializable
,GroupAdditive<Matrix<Parameter<Q>>>
,Ring<Matrix<Parameter<Q>>>
,Structure<Matrix<Parameter<Q>>>
,VectorSpace<Matrix<Parameter<Q>>,Parameter<Q>>
public final class Matrix3D<Q extends javax.measure.quantity.Quantity> extends Matrix<Parameter<Q>> implements javolution.lang.Realtime, javolution.lang.ValueType, javolution.xml.XMLSerializable
This class represents a 3x3
matrix
implementation forparameter
elements.Instances of this class can be created from
Vector3D
, either as rows or columns if the matrix is transposed. For example:Vector3D
column0 = Vector3D.valueOf(...); Vector3D column1 = Vector3D.valueOf(...); Vector3D column2 = Vector3D.valueOf(...); Matrix3D M = Matrix3D.valueOf(column0, column1, column2).transpose(); Modified by: Joseph A. Huwaldt
- Version:
- October 23, 2015
- Author:
- Joseph A. Huwaldt, Date: November 26, 2008
- See Also:
- Serialized Form
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Matrix3D
adjoint()
Returns the adjoint of this matrix.<T extends javax.measure.quantity.Quantity>
Matrix3D<T>asType(java.lang.Class<T> type)
Casts this Matrix3D to a parameterized unit of specified nature or throw aClassCastException
if the specified quantity and this matrix unit dimension do not match.Parameter
cofactor(int i, int j)
Returns the cofactor of an element in this matrix.Matrix3D<Q>
copy()
Returns a copy of this matrix allocated by the calling thread (possibly on the stack).Parameter
determinant()
Returns the determinant of this matrix.Parameter<Q>
get(int i, int j)
Returns a single element from this matrix.Vector3D<Q>
getColumn(int j)
Returns the column identified by the specified index in this matrix.Vector3D<Q>
getDiagonal()
Returns the diagonal vector.int
getNumberOfColumns()
Returns the number of columns n for this matrix.int
getNumberOfRows()
Returns the number of rows m for this matrix.Vector3D<Q>
getRow(int i)
Returns the row identified by the specified index in this matrix.javax.measure.unit.Unit<Q>
getUnit()
Returns the unit in which thevalues
in this vector are stated.double
getValue(int i, int j)
Returns a single element from this matrix as adouble
.Matrix3D
inverse()
Returns the inverse of this matrix.boolean
isApproxZero()
Compares this Matrix3D for approximate equality to zero (all the values are within the numerical roundoff error of zero).static void
main(java.lang.String[] args)
Tests the methods in this class.Matrix3D<Q>
minus(Matrix<Parameter<Q>> that)
Returns the difference between this matrix and the one specified.Matrix3D<Q>
opposite()
Returns the negation of this matrix.Matrix3D<Q>
plus(Matrix<Parameter<Q>> that)
Returns the sum of this matrix with the one specified.Matrix
tensor(Matrix that)
Returns the linear algebraic matrix tensor product of this matrix and another (Kronecker product).Matrix3D<Q>
times(double k)
Returns the product of this matrix by the specified factor.Matrix3D
times(Parameter k)
Returns the product of this matrix by the specified factor.Matrix3D
times(Matrix that)
Returns the product of this matrix with the one specified.Vector3D
times(Vector v)
Returns the product of this matrix by the specified vector.<R extends javax.measure.quantity.Quantity>
Matrix3D<R>to(javax.measure.unit.Unit<R> unit)
Returns the equivalent to this matrix but stated in the specified unit.Float64Matrix
toFloat64Matrix()
Returns a Float64Matrix containing the data in this matrix in the current units of this matrix.Matrix3D<Q>
transpose()
Returns the transpose of this matrix.static <Q extends javax.measure.quantity.Quantity>
Matrix3D<Q>valueOf(double[][] matrix, javax.measure.unit.Unit<Q> unit)
Returns aMatrix3D
instance containing the specified matrix of double values stated in the specified units.static <Q extends javax.measure.quantity.Quantity>
Matrix3D<Q>valueOf(double a, double b, double c, double d, double e, double f, double g, double h, double i, javax.measure.unit.Unit<Q> unit)
Returns 3D matrix from a sequence of 9double
values.static <Q extends javax.measure.quantity.Quantity>
Matrix3D<Q>valueOf(Vector3D<Q> row0, Vector3D<Q> row1, Vector3D<Q> row2)
Returns a 3D matrix holding the specified row vectors (column vectors iftransposed
).static <Q extends javax.measure.quantity.Quantity>
Matrix3D<Q>valueOf(java.util.List<Vector3D<Q>> rows)
Returns a 3D matrix holding the rowvectors
from the specified collection (column vectors iftransposed
).static <Q extends javax.measure.quantity.Quantity>
Matrix3D<Q>valueOf(Float64Vector row0, Float64Vector row1, Float64Vector row2, javax.measure.unit.Unit<Q> unit)
Returns a 3D matrix holding the specified row vectors in the stated units (column vectors iftransposed
).static <Q extends javax.measure.quantity.Quantity>
Matrix3D<Q>valueOf(Matrix<Parameter<Q>> that)
Returns a 3D matrix equivalent to the specified matrix.static <Q extends javax.measure.quantity.Quantity>
Matrix3D<Q>valueOf(Matrix<Float64> matrix, javax.measure.unit.Unit<Q> unit)
Returns aMatrix3D
instance containing the specified matrix of Float64 values stated in the specified units.Vector<Parameter<Q>>
vectorization()
Returns the vectorization of this matrix.
-
-
-
Method Detail
-
valueOf
public static <Q extends javax.measure.quantity.Quantity> Matrix3D<Q> valueOf(double a, double b, double c, double d, double e, double f, double g, double h, double i, javax.measure.unit.Unit<Q> unit)
Returns 3D matrix from a sequence of 9double
values.Values are ordered as follows:
| a b c | | d e f | | g h i |
- Parameters:
a
- matrix element 0,0b
- matrix element 0,1c
- matrix element 0,2d
- matrix element 1,0e
- matrix element 1,1f
- matrix element 1,2g
- matrix element 2,0h
- matrix element 2,1i
- matrix element 2,2unit
- the unit in which the elements are stated.- Returns:
- the 3D matrix having the specified elements stated in the specified units.
-
valueOf
public static <Q extends javax.measure.quantity.Quantity> Matrix3D<Q> valueOf(Float64Vector row0, Float64Vector row1, Float64Vector row2, javax.measure.unit.Unit<Q> unit)
Returns a 3D matrix holding the specified row vectors in the stated units (column vectors iftransposed
).- Parameters:
row0
- the 1st row vector.row1
- the 2nd row vector.row2
- the 3rd row vector.unit
- the unit in which the elements are stated.- Returns:
- the 3D matrix having the specified elements stated in the specified units.
-
valueOf
public static <Q extends javax.measure.quantity.Quantity> Matrix3D<Q> valueOf(Vector3D<Q> row0, Vector3D<Q> row1, Vector3D<Q> row2)
Returns a 3D matrix holding the specified row vectors (column vectors iftransposed
). All the values are converted to the same units as the 1st row (row0).- Parameters:
row0
- the 1st row vector.row1
- the 2nd row vector.row2
- the 3rd row vector.- Returns:
- the 3D matrix having the specified rows.
-
valueOf
public static <Q extends javax.measure.quantity.Quantity> Matrix3D<Q> valueOf(java.util.List<Vector3D<Q>> rows)
Returns a 3D matrix holding the rowvectors
from the specified collection (column vectors iftransposed
). All the values are converted to the same units as the 1st row (row0).- Parameters:
rows
- The list of row vectors. If there are more than 3 elements, an exception is thrown.- Returns:
- the 3D matrix having the specified rows.
- Throws:
DimensionException
- if the rows do not have a dimension of 3.
-
valueOf
public static <Q extends javax.measure.quantity.Quantity> Matrix3D<Q> valueOf(Matrix<Float64> matrix, javax.measure.unit.Unit<Q> unit)
Returns aMatrix3D
instance containing the specified matrix of Float64 values stated in the specified units. The input matrix must have dimensions of 3x3.- Parameters:
matrix
- the matrix of Float64 values stated in the specified unit (must have dimension of 3x3).unit
- the unit in which the elements are stated.- Returns:
- the matrix having the specified values.
-
valueOf
public static <Q extends javax.measure.quantity.Quantity> Matrix3D<Q> valueOf(double[][] matrix, javax.measure.unit.Unit<Q> unit)
Returns aMatrix3D
instance containing the specified matrix of double values stated in the specified units. The input matrix must have dimensions of 3x3.- Parameters:
matrix
- the matrix of double values stated in the specified unit (must have dimension of 3x3).unit
- the unit in which the elements are stated.- Returns:
- the matrix having the specified values.
-
valueOf
public static <Q extends javax.measure.quantity.Quantity> Matrix3D<Q> valueOf(Matrix<Parameter<Q>> that)
Returns a 3D matrix equivalent to the specified matrix. All the values are converted to the same units as the 1st element (row=0,column=0).- Parameters:
that
- the matrix to convert.- Returns:
that
or a 3D matrix holding the same elements as the specified matrix.
-
getNumberOfRows
public int getNumberOfRows()
Returns the number of rows m for this matrix. This implementation always returns 3.- Specified by:
getNumberOfRows
in classMatrix<Parameter<Q extends javax.measure.quantity.Quantity>>
- Returns:
- m, the number of rows.
-
getNumberOfColumns
public int getNumberOfColumns()
Returns the number of columns n for this matrix. This implementation always returns 3.- Specified by:
getNumberOfColumns
in classMatrix<Parameter<Q extends javax.measure.quantity.Quantity>>
- Returns:
- n, the number of columns.
-
getUnit
public javax.measure.unit.Unit<Q> getUnit()
Returns the unit in which thevalues
in this vector are stated.
-
to
public <R extends javax.measure.quantity.Quantity> Matrix3D<R> to(javax.measure.unit.Unit<R> unit)
Returns the equivalent to this matrix but stated in the specified unit.- Parameters:
unit
- the unit of the matrix to be returned.- Returns:
- a matrix equivalent to this vector but stated in the specified unit.
- Throws:
ConversionException
- if the current model does not allows for conversion to the specified unit.
-
asType
public <T extends javax.measure.quantity.Quantity> Matrix3D<T> asType(java.lang.Class<T> type) throws java.lang.ClassCastException
Casts this Matrix3D to a parameterized unit of specified nature or throw aClassCastException
if the specified quantity and this matrix unit dimension do not match.- Parameters:
type
- the quantity class identifying the nature of the unit.- Returns:
- this matrix parameterized with the specified type.
- Throws:
java.lang.ClassCastException
- if the dimension of this parameter's unit is different from the specified quantity dimension.java.lang.UnsupportedOperationException
- if the specified quantity class does not have a public static field named "UNIT" holding the standard unit for the quantity.
-
getValue
public double getValue(int i, int j)
Returns a single element from this matrix as adouble
.- Parameters:
i
- the row index (range [0..3[).j
- the column index (range [0..3[).- Returns:
- the element read at [i,j].
-
getRow
public Vector3D<Q> getRow(int i)
Returns the row identified by the specified index in this matrix.
-
getColumn
public Vector3D<Q> getColumn(int j)
Returns the column identified by the specified index in this matrix.
-
getDiagonal
public Vector3D<Q> getDiagonal()
Returns the diagonal vector.- Specified by:
getDiagonal
in classMatrix<Parameter<Q extends javax.measure.quantity.Quantity>>
- Returns:
- the vector holding the diagonal elements.
-
plus
public Matrix3D<Q> plus(Matrix<Parameter<Q>> that)
Returns the sum of this matrix with the one specified.- Specified by:
plus
in interfaceGroupAdditive<Q extends javax.measure.quantity.Quantity>
- Specified by:
plus
in classMatrix<Parameter<Q extends javax.measure.quantity.Quantity>>
- Parameters:
that
- the matrix to be added.- Returns:
this + that
- Throws:
DimensionException
- if the matrix dimensions are different.
-
minus
public Matrix3D<Q> minus(Matrix<Parameter<Q>> that)
Returns the difference between this matrix and the one specified.- Overrides:
minus
in classMatrix<Parameter<Q extends javax.measure.quantity.Quantity>>
- Parameters:
that
- the matrix to be subtracted from this one.- Returns:
this - that
- Throws:
DimensionException
- if the matrix dimensions are different.
-
times
public Matrix3D times(Parameter k)
Returns the product of this matrix by the specified factor.- Specified by:
times
in interfaceVectorSpace<Matrix<Parameter<Q extends javax.measure.quantity.Quantity>>,Parameter<Q extends javax.measure.quantity.Quantity>>
- Specified by:
times
in classMatrix<Parameter<Q extends javax.measure.quantity.Quantity>>
- Parameters:
k
- the coefficient multiplier- Returns:
this · k
-
times
public Matrix3D<Q> times(double k)
Returns the product of this matrix by the specified factor.- Parameters:
k
- the coefficient multiplier- Returns:
this · k
-
times
public Vector3D times(Vector v)
Returns the product of this matrix by the specified vector.- Specified by:
times
in classMatrix<Parameter<Q extends javax.measure.quantity.Quantity>>
- Parameters:
v
- the vector.- Returns:
this · v
- Throws:
DimensionException
- - if v.getDimension() != this.getNumberOfColumns()
-
times
public Matrix3D times(Matrix that)
Returns the product of this matrix with the one specified.- Specified by:
times
in interfaceRing<Q extends javax.measure.quantity.Quantity>
- Specified by:
times
in classMatrix<Parameter<Q extends javax.measure.quantity.Quantity>>
- Parameters:
that
- the matrix multiplier.- Returns:
this · that
- Throws:
DimensionException
- - if this.getNumberOfColumns() != that.getNumberOfRows().
-
inverse
public Matrix3D inverse()
Returns the inverse of this matrix. If the matrix is singular, thedeterminant()
will be zero (or nearly zero).
-
determinant
public Parameter determinant()
Returns the determinant of this matrix.- Specified by:
determinant
in classMatrix<Parameter<Q extends javax.measure.quantity.Quantity>>
- Returns:
- this matrix determinant.
-
cofactor
public Parameter cofactor(int i, int j)
Returns the cofactor of an element in this matrix. It is the value obtained by evaluating the determinant formed by the elements not in that particular row or column.
-
adjoint
public Matrix3D adjoint()
Returns the adjoint of this matrix. It is obtained by replacing each element in this matrix with its cofactor and applying a + or - sign according to (-1)**(i+j), and then finding the transpose of the resulting matrix.
-
tensor
public Matrix tensor(Matrix that)
Returns the linear algebraic matrix tensor product of this matrix and another (Kronecker product).- Specified by:
tensor
in classMatrix<Parameter<Q extends javax.measure.quantity.Quantity>>
- Parameters:
that
- the second matrix- Returns:
this times that
- See Also:
- Wikipedia: Kronecker Product
-
isApproxZero
public boolean isApproxZero()
Compares this Matrix3D for approximate equality to zero (all the values are within the numerical roundoff error of zero).- Returns:
true
if this Matrix3D is approximately equal to zero;false
otherwise.
-
vectorization
public Vector<Parameter<Q>> vectorization()
Returns the vectorization of this matrix. The vectorization of a matrix is the column vector obtained by stacking the columns of the matrix on top of one another. The default implementation returns aDenseVector
.> - Specified by:
vectorization
in classMatrix<Parameter<Q extends javax.measure.quantity.Quantity>>
- Returns:
- the vectorization of this matrix.
- See Also:
- Wikipedia: Vectorization.
-
copy
public Matrix3D<Q> copy()
Returns a copy of this matrix allocated by the calling thread (possibly on the stack).
-
toFloat64Matrix
public Float64Matrix toFloat64Matrix()
Returns a Float64Matrix containing the data in this matrix in the current units of this matrix.
-
main
public static void main(java.lang.String[] args)
Tests the methods in this class.
-
-