All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jeometry.math.Matrix Maven / Gradle / Ivy

package org.jeometry.math;

import java.awt.Dimension;

import org.jeometry.Geometry;
import org.jeometry.math.decomposition.EigenDecomposition;
import org.jeometry.math.decomposition.LUDecomposition;
import org.jeometry.math.decomposition.SVDDecomposition;

/**
 * This interface describe a general two dimensional matrix. A matrix A is a two-dimensional array of double values that is defined such as: 
 * $$
 * A = \begin{bmatrix} 
 *        a_{00} & \dots  & a_{0i} & \dots  & a_{0m} \\
 *        \vdots & \ddots & \vdots & \ddots & \vdots \\
 *        a_{i0} & \dots  & a_{ij} & \dots  & a_{im} \\
 *        \vdots & \ddots & \vdots & \ddots & \vdots \\     
 *        a_{n0} & \dots  & a_{nj} & \dots  & a_{nm}
 *     \end{bmatrix}
 * $$
 * where:
 * 
    *
  • n is the number of rows. *
  • m is the number of columns. *
  • aij is the value located at row i and column j *
* @author Julien Seinturier - COMEX S.A. - [email protected] - https://github.com/jorigin/jeometry * @version {@value Geometry#version} b{@value Geometry#BUILD} * @since 1.0.0 */ public interface Matrix { /** * Indicates that the export of a matrix data to a linear array is row-major (made row by row from the first to the last). * @see #COLUMN_MAJOR */ public static final int ROW_MAJOR = 1; /** * Indicates that the the export of a matrix data to a linear array is column-major (made column by column from the first to the last). * @see #ROW_MAJOR */ public static final int COLUMN_MAJOR = 2; /** * Get the matrix values as a linear array according to the given ordering. * If the ordering is {@link #ROW_MAJOR}, the output array contains the sequence of all rows from the first to the last. * On the other hand, if the ordering is {@link #COLUMN_MAJOR}, the output array contains the sequence of all columns from the first to the last. * @param ordering the ordering to use ({@link #ROW_MAJOR} or {@link #COLUMN_MAJOR}). * @return the matrix values as a linear array. * @see #setDataArray(int, double[]) */ public double[] getDataArray(int ordering); /** * Get the matrix values as a linear array according to the given ordering. * If the ordering is {@link #ROW_MAJOR}, the output array contains the sequence of all rows from the first to the last. * On the other hand, if the ordering is {@link #COLUMN_MAJOR}, the output array contains the sequence of all columns from the first to the last. * @param ordering the ordering to use ({@link #ROW_MAJOR} or {@link #COLUMN_MAJOR}). * @param output the array where the value are stored. * @return the matrix values as a linear array. * @see #setDataArray(int, double[]) * @throws IllegalArgumentException if the output array does not fit the matrix capabilities. */ public double[] getDataArray(int ordering, double[] output) throws IllegalArgumentException; /** * Set the matrix values from a linear array according to the given ordering. * If the ordering is {@link #ROW_MAJOR}, the output array contains the sequence of all rows from the first to the last. * On the other hand, if the ordering is {@link #COLUMN_MAJOR}, the output array contains the sequence of all columns from the first to the last. * @param ordering the ordering of the linear array ({@link #ROW_MAJOR} or {@link #COLUMN_MAJOR}). * @param data the matrix values. * @throws IllegalArgumentException if the given data does not fit the matrix capabilities. */ public void setDataArray(int ordering, double[] data) throws IllegalArgumentException; /** * Get the matrix values as a two-dimensionnal array. * The output array has the same number of rows and columns as the matrix. * @return the matrix values as a two-dimensionnal array. * @see #setDataArray2D(double[][]) */ public double[][] getDataArray2D(); /** * Get the matrix values as a two-dimensionnal array. * The output array has the same number of rows and columns as the matrix. * @param output the two-dimensional array where the value are stored. * @return the matrix values as a two-dimensionnal array. * @see #setDataArray2D(double[][]) */ public double[][] getDataArray2D(double[][] output); /** * Set the matrix values from a two-dimensionnal array. * The input array has to have the same number of rows and columns as the matrix. * @param data the matrix values * @throws IllegalArgumentException if the given data does not fir the matrix capabilities. */ public void setDataArray2D(double[][] data) throws IllegalArgumentException; /** * Get the value that is stored at the given (row, column). * @param row the row that holds the value. * @param col the column that holds the value. * @return the value that is stored at the given (row, column). * @throws IllegalArgumentException if the row or col does not fit the matrix size. * @see #setValue(int, int, double) */ public double getValue(int row, int col) throws IllegalArgumentException; /** * Set the value that is stored at the given (row, column). * @param row the row that holds the value. * @param col the column that holds the value. * @param value value to store at the given (row, column). * @throws IllegalArgumentException if the row or col does not fit the matrix size. * @see #getValue(int, int) */ public void setValue(int row, int col, double value) throws IllegalArgumentException; /** * Get the number of rows that this matrix contains. * @return the number of rows that this matrix contains. * @see #getColumnsCount() * @see #getDimension() */ public int getRowsCount(); /** * Get the number of columns that this matrix contains. * @return the number of columns that this matrix contains. * @see #getRowsCount() * @see #getDimension() */ public int getColumnsCount(); /** * Get the dimension (the number of rows and columns) of this matrix. * @return the dimension (the number of rows and columns) of this matrix. * @see #getRowsCount() * @see #getColumnsCount() */ public Dimension getDimension(); /** * Compute the matrix determinant. Let A be a general n×m sized matrix such that: * $$ * A = \begin{bmatrix} * a_{00} & \dots & a_{0i} & \dots & a_{0m} \\ * \vdots & \ddots & \vdots & \ddots & \vdots \\ * a_{i0} & \dots & a_{ij} & \dots & a_{im} \\ * \vdots & \ddots & \vdots & \ddots & \vdots \\ * a_{n0} & \dots & a_{nj} & \dots & a_{nm} * \end{bmatrix} * $$ * where: *
    *
  • n is the number of rows. *
  • m is the number of columns. *
  • aij is the value located at row i and column j *
* Its determinant, denoted |A| is such that: * $$ * |A|\ =\ \sum_{k=1}^{k}a_{ij}C_{ij} * $$ * where Cij is the cofactor of aij defined by: * $$ * C_{ij}\ =\ (-1)^{i+j}M_{ij} * $$ * with Mij the minor of matrix A formed by eliminating row i and column j from A.

* Many implementation of the determinant can be provided, this description is purely formal. * @return the matrix determinant. */ public double determinant(); /** * Compute the transpose of the current matrix and return it. * Let A be a matrix, the transpose of A, denoted AT * is the matrix that is obtained by exchanging A rows and columns. A matrix and its transpose satisfy:

* (AT)-1 = (A-1)T *

* Note that the transpose of an A, B matrices product is such as: * (A×B)T = AT×BT * @return the transpose of the current matrix. */ public Matrix transpose(); /** * Compute the transpose of the current matrix and store it within the given result. * Let A be a matrix, the transpose of A, denoted AT * is the matrix that is obtained by exchanging A rows and columns. A matrix and its transpose satisfy:

* (AT)-1 = (A-1)T *

* Note that the transpose of an A, B matrices product is such as: * (A×B)T = AT×BT * @param result the matrix that has to store the result of the transpose. * @return the same reference as result * @throws IllegalArgumentException is the given result does not fit the transpose matrix. */ public Matrix transpose(Matrix result) throws IllegalArgumentException; /** * Modify this matrix by its transpose. * Let A be a matrix, the transpose of A, denoted AT * is the matrix that is obtained by exchanging A rows and columns. A matrix and its transpose satisfy:

* (AT)-1 = (A-1)T *

* Note that the transpose of an A, B matrices product is such as: * (A×B)T = AT×BT * @return a reference on this matrix. */ public Matrix transposeAffect(); /** * Multiply the current matrix by the given one (regarding to matrix product). Formally, this methods compute:

* M = A×B

* where: *
    *
  • M is the returned result. *
  • A is this matrix. *
  • B is the matrix given by b. *
* @param b the matrix to multiply. * @return the product of this matrix by the given one. * @throws IllegalArgumentException if the matrix are incompatible for multiplication. */ public Matrix multiply(Matrix b) throws IllegalArgumentException; /** * Multiply the current matrix by the given one (regarding to matrix product). Formally, this methods compute:

* M = A×B

* where: *
    *
  • M is the returned result. *
  • A is this matrix. *
  • B is the matrix given by b. *
* @param b the matrix to multiply. * @param result the matrix that has to store the result of the multiplication. * @return the same reference as result. * @throws IllegalArgumentException if the matrix are incompatible for multiplication. */ public Matrix multiply(Matrix b, Matrix result) throws IllegalArgumentException; /** * Modify this matrix to be the result of the multiplication of this matrix with the given one (regarding to matrix product). * Formally, this methods compute:

* M = A×B

* where: *
    *
  • M is the returned result. *
  • A is this matrix. *
  • B is the matrix given by b. *
* @param b the matrix to multiply. * @return a reference on this matrix. * @throws IllegalArgumentException if the matrix are incompatible for multiplication. */ public Matrix multiplyAffect(Matrix b) throws IllegalArgumentException; /** * Return the {@link Vector vector} resulting of the multiplication of this matrix with the given one. * (regarding to matrix product).

* Formally, this methods compute:

* u = A×v

* where: *
    *
  • u is the returned result. *
  • A is this matrix. *
  • v is the input vector. *
* @param v the vector to multiply. * @return the {@link Vector vector} resulting of the multiplication of this matrix with the given one. */ public Vector multiply(Vector v); /** * Affect the result {@link Vector vector} with the result of the multiplication of this matrix with the given vector v. * (regarding to matrix product)

* Formally, this methods compute:

* u = A×v

* where: *
    *
  • u is the returned result. *
  • A is this matrix. *
  • v is the input vector. *
* @param v the vector to multiply. * @param result the vector that store the result. * @return the same reference as result. */ public Vector multiply(Vector v, Vector result); /** * Return the matrix resulting of the multiplication of this matrix with a scalar. * Formally, let A a matrix such that: * $$ * A = \begin{bmatrix} * a_{00} & \dots & a_{0i} & \dots & a_{0m} \\ * \vdots & \ddots & \vdots & \ddots & \vdots \\ * a_{i0} & \dots & a_{ij} & \dots & a_{im} \\ * \vdots & \ddots & \vdots & \ddots & \vdots \\ * a_{n0} & \dots & a_{nj} & \dots & a_{nm} * \end{bmatrix} * $$ * The result of the multiplcation of A by a scalar s is the matrix As that verifies: * $$ * A_{s} = \begin{bmatrix} * sa_{00} & \dots & sa_{0i} & \dots & sa_{0m} \\ * \vdots & \ddots & \vdots & \ddots & \vdots \\ * sa_{i0} & \dots & sa_{ij} & \dots & sa_{im} \\ * \vdots & \ddots & \vdots & \ddots & \vdots \\ * sa_{n0} & \dots & sa_{nj} & \dots & sa_{nm} * \end{bmatrix} * $$ * @param scalar the scalar to multiply. * @return the matrix resulting of the multiplication of this matrix with a scalar. */ public Matrix multiply(double scalar); /** * Store the result of the multiplication of this matrix with a scalar within the given result. * Formally, let M a matrix such that: * $$ * A = \begin{bmatrix} * a_{00} & \dots & a_{0i} & \dots & a_{0m} \\ * \vdots & \ddots & \vdots & \ddots & \vdots \\ * a_{i0} & \dots & a_{ij} & \dots & a_{im} \\ * \vdots & \ddots & \vdots & \ddots & \vdots \\ * a_{n0} & \dots & a_{nj} & \dots & a_{nm} * \end{bmatrix} * $$ * The result of the multiplcation of A by a scalar s is the matrix As that verifies: * $$ * A_{s} = \begin{bmatrix} * sa_{00} & \dots & sa_{0i} & \dots & sa_{0m} \\ * \vdots & \ddots & \vdots & \ddots & \vdots \\ * sa_{i0} & \dots & sa_{ij} & \dots & sa_{im} \\ * \vdots & \ddots & \vdots & \ddots & \vdots \\ * sa_{n0} & \dots & sa_{nj} & \dots & sa_{nm} * \end{bmatrix} * $$ * @param scalar the scalar to multiply. * @param result the matrix that have to store the result of the multiplication of this matrix with the scalar. * @return the same reference as result * @throws IllegalArgumentException if the result matrix does not fit the multiplication. */ public Matrix multiply(double scalar, Matrix result) throws IllegalArgumentException; /** * Modify this matrix with the result of the multiplication of this matrix with a scalar. * Formally, let A a matrix such that: * $$ * A = \begin{bmatrix} * a_{00} & \dots & a_{0i} & \dots & a_{0m} \\ * \vdots & \ddots & \vdots & \ddots & \vdots \\ * a_{i0} & \dots & a_{ij} & \dots & a_{im} \\ * \vdots & \ddots & \vdots & \ddots & \vdots \\ * a_{n0} & \dots & a_{nj} & \dots & a_{nm} * \end{bmatrix} * $$ * The result of the multiplcation of A by a scalar s is the matrix As that verifies: * $$ * A_{s} = \begin{bmatrix} * sa_{00} & \dots & sa_{0i} & \dots & sa_{0m} \\ * \vdots & \ddots & \vdots & \ddots & \vdots \\ * sa_{i0} & \dots & sa_{ij} & \dots & sa_{im} \\ * \vdots & \ddots & \vdots & \ddots & \vdots \\ * sa_{n0} & \dots & sa_{nj} & \dots & sa_{nm} * \end{bmatrix} * $$ * @param scalar the scalar to multiply. * @return a reference on this matrix. */ public Matrix multiplyAffect(double scalar); /** * Compute and return the addition of this matrix with the given one. * Formally, let A and B two matrices such that: * $$ * A\ =\ \begin{bmatrix} * a_{00} & \dots & a_{0i} & \dots & a_{0m} \\ * \vdots & \ddots & \vdots & \ddots & \vdots \\ * a_{i0} & \dots & a_{ij} & \dots & a_{im} \\ * \vdots & \ddots & \vdots & \ddots & \vdots \\ * a_{n0} & \dots & a_{nj} & \dots & a_{nm} * \end{bmatrix} * and\ B\ =\ \begin{bmatrix} * b_{00} & \dots & b_{0i} & \dots & b_{0m} \\ * \vdots & \ddots & \vdots & \ddots & \vdots \\ * b_{i0} & \dots & b_{ij} & \dots & b_{im} \\ * \vdots & \ddots & \vdots & \ddots & \vdots \\ * b_{n0} & \dots & b_{nj} & \dots & b_{nm} * \end{bmatrix} * $$ * The addition of A and B, denoted A + B is such that: * $$ * A+B\ =\ \begin{bmatrix} * b_{00}+a_{00} & \dots & b_{0i}+a_{0i} & \dots & b_{0m}+a_{0m} \\ * \vdots & \ddots & \vdots & \ddots & \vdots \\ * b_{i0}+a_{i0} & \dots & b_{ij}+a_{ij} & \dots & b_{im}+a_{im} \\ * \vdots & \ddots & \vdots & \ddots & \vdots \\ * b_{n0}+a_{n0} & \dots & b_{nj}+a_{nj} & \dots & b_{nm}+a_{nm} * \end{bmatrix} * $$ * @param b the matrix to add. This matrix has to be same sized as this matrix. * @return the addition of this matrix with the given one. If the input matrix is null then null is returned. * @throws IllegalArgumentException if the input matrix size differs from this one. */ public Matrix add(Matrix b) throws IllegalArgumentException; /** * Compute the addition of this matrix with the given one and store it within the result matrix. * Formally, let A and B two matrices such that: * $$ * A\ =\ \begin{bmatrix} * a_{00} & \dots & a_{0i} & \dots & a_{0m} \\ * \vdots & \ddots & \vdots & \ddots & \vdots \\ * a_{i0} & \dots & a_{ij} & \dots & a_{im} \\ * \vdots & \ddots & \vdots & \ddots & \vdots \\ * a_{n0} & \dots & a_{nj} & \dots & a_{nm} * \end{bmatrix} * and\ B\ =\ \begin{bmatrix} * b_{00} & \dots & b_{0i} & \dots & b_{0m} \\ * \vdots & \ddots & \vdots & \ddots & \vdots \\ * b_{i0} & \dots & b_{ij} & \dots & b_{im} \\ * \vdots & \ddots & \vdots & \ddots & \vdots \\ * b_{n0} & \dots & b_{nj} & \dots & b_{nm} * \end{bmatrix} * $$ * The addition of A and B, denoted A + B is such that: * $$ * A+B\ =\ \begin{bmatrix} * b_{00}+a_{00} & \dots & b_{0i}+a_{0i} & \dots & b_{0m}+a_{0m} \\ * \vdots & \ddots & \vdots & \ddots & \vdots \\ * b_{i0}+a_{i0} & \dots & b_{ij}+a_{ij} & \dots & b_{im}+a_{im} \\ * \vdots & \ddots & \vdots & \ddots & \vdots \\ * b_{n0}+a_{n0} & \dots & b_{nj}+a_{nj} & \dots & b_{nm}+a_{nm} * \end{bmatrix} * $$ * @param b the matrix to add. This matrix has to be same sized as this matrix. * @param result the matrix that store the result. This matrix has to be same sized as this matrix. * @return the same reference as result. * @throws IllegalArgumentException if the input or result matrices size differs from this one. */ public Matrix add(Matrix b, Matrix result) throws IllegalArgumentException; /** * Affect this matrix with the result of its addition with the given one. * Formally, let A and B two matrices such that: * $$ * A\ =\ \begin{bmatrix} * a_{00} & \dots & a_{0i} & \dots & a_{0m} \\ * \vdots & \ddots & \vdots & \ddots & \vdots \\ * a_{i0} & \dots & a_{ij} & \dots & a_{im} \\ * \vdots & \ddots & \vdots & \ddots & \vdots \\ * a_{n0} & \dots & a_{nj} & \dots & a_{nm} * \end{bmatrix} * and\ B\ =\ \begin{bmatrix} * b_{00} & \dots & b_{0i} & \dots & b_{0m} \\ * \vdots & \ddots & \vdots & \ddots & \vdots \\ * b_{i0} & \dots & b_{ij} & \dots & b_{im} \\ * \vdots & \ddots & \vdots & \ddots & \vdots \\ * b_{n0} & \dots & b_{nj} & \dots & b_{nm} * \end{bmatrix} * $$ * The addition of A and B, denoted A + B is such that: * $$ * A+B\ =\ \begin{bmatrix} * b_{00}+a_{00} & \dots & b_{0i}+a_{0i} & \dots & b_{0m}+a_{0m} \\ * \vdots & \ddots & \vdots & \ddots & \vdots \\ * b_{i0}+a_{i0} & \dots & b_{ij}+a_{ij} & \dots & b_{im}+a_{im} \\ * \vdots & \ddots & \vdots & \ddots & \vdots \\ * b_{n0}+a_{n0} & \dots & b_{nj}+a_{nj} & \dots & b_{nm}+a_{nm} * \end{bmatrix} * $$ * @param b the matrix to add. This matrix has to be same sized as this matrix. * @return a reference on this matrix. * @throws IllegalArgumentException if the input matrix size differs from this one. */ public Matrix addAffect(Matrix b) throws IllegalArgumentException; /** * Compute and return the addition of this matrix with the given scalar. * Formally, let s be a scalar and A a matrix such that: * $$ * A\ =\ \begin{bmatrix} * a_{00} & \dots & a_{0i} & \dots & a_{0m} \\ * \vdots & \ddots & \vdots & \ddots & \vdots \\ * a_{i0} & \dots & a_{ij} & \dots & a_{im} \\ * \vdots & \ddots & \vdots & \ddots & \vdots \\ * a_{n0} & \dots & a_{nj} & \dots & a_{nm} * \end{bmatrix} * $$ * The addition of A and s, denoted As is such that: * $$ * A_{s}\ =\ \begin{bmatrix} * s+a_{00} & \dots & s+a_{0i} & \dots & s+a_{0m} \\ * \vdots & \ddots & \vdots & \ddots & \vdots \\ * s+a_{i0} & \dots & s+a_{ij} & \dots & s+a_{im} \\ * \vdots & \ddots & \vdots & \ddots & \vdots \\ * s+a_{n0} & \dots & s+a_{nj} & \dots & s+a_{nm} * \end{bmatrix} * $$ * @param s the scalar to add. * @return the addition of this matrix with the given scalar. */ public Matrix add(double s); /** * Compute the addition of this matrix with the given scalar and store it within the given result matrix. * Formally, let s be a scalar and A a matrix such that: * $$ * A\ =\ \begin{bmatrix} * a_{00} & \dots & a_{0i} & \dots & a_{0m} \\ * \vdots & \ddots & \vdots & \ddots & \vdots \\ * a_{i0} & \dots & a_{ij} & \dots & a_{im} \\ * \vdots & \ddots & \vdots & \ddots & \vdots \\ * a_{n0} & \dots & a_{nj} & \dots & a_{nm} * \end{bmatrix} * $$ * The addition of A and s, denoted As is such that: * $$ * A_{s}\ =\ \begin{bmatrix} * s+a_{00} & \dots & s+a_{0i} & \dots & s+a_{0m} \\ * \vdots & \ddots & \vdots & \ddots & \vdots \\ * s+a_{i0} & \dots & s+a_{ij} & \dots & s+a_{im} \\ * \vdots & \ddots & \vdots & \ddots & \vdots \\ * s+a_{n0} & \dots & s+a_{nj} & \dots & s+a_{nm} * \end{bmatrix} * $$ * @param s the scalar to add. * @param result the matrix that store the result. This matrix has to be same sized as this matrix. * @return the addition of this matrix with the given scalar. If the result matrix is null then null is returned. * @throws IllegalArgumentException if the result matrix size differs from this one. */ public Matrix add(double s, Matrix result) throws IllegalArgumentException; /** * Affect this matrix with the result of the addition of this matrix with the given scalar. * Formally, let s be a scalar and A a matrix such that: * $$ * A\ =\ \begin{bmatrix} * a_{00} & \dots & a_{0i} & \dots & a_{0m} \\ * \vdots & \ddots & \vdots & \ddots & \vdots \\ * a_{i0} & \dots & a_{ij} & \dots & a_{im} \\ * \vdots & \ddots & \vdots & \ddots & \vdots \\ * a_{n0} & \dots & a_{nj} & \dots & a_{nm} * \end{bmatrix} * $$ * The addition of A and s, denoted As is such that: * $$ * A_{s}\ =\ \begin{bmatrix} * s+a_{00} & \dots & s+a_{0i} & \dots & s+a_{0m} \\ * \vdots & \ddots & \vdots & \ddots & \vdots \\ * s+a_{i0} & \dots & s+a_{ij} & \dots & s+a_{im} \\ * \vdots & \ddots & \vdots & \ddots & \vdots \\ * s+a_{n0} & \dots & s+a_{nj} & \dots & s+a_{nm} * \end{bmatrix} * $$ * @param s the scalar to add. * @return a reference on this matrix. */ public Matrix addAffect(double s); /** * Compute and return the subtraction of this matrix with the given one. * Formally, let A and B two matrices such that: * $$ * A\ =\ \begin{bmatrix} * a_{00} & \dots & a_{0i} & \dots & a_{0m} \\ * \vdots & \ddots & \vdots & \ddots & \vdots \\ * a_{i0} & \dots & a_{ij} & \dots & a_{im} \\ * \vdots & \ddots & \vdots & \ddots & \vdots \\ * a_{n0} & \dots & a_{nj} & \dots & a_{nm} * \end{bmatrix} * and\ B\ =\ \begin{bmatrix} * b_{00} & \dots & b_{0i} & \dots & b_{0m} \\ * \vdots & \ddots & \vdots & \ddots & \vdots \\ * b_{i0} & \dots & b_{ij} & \dots & b_{im} \\ * \vdots & \ddots & \vdots & \ddots & \vdots \\ * b_{n0} & \dots & b_{nj} & \dots & b_{nm} * \end{bmatrix} * $$ * The subtraction of A and B, denoted A - B is such that: * $$ * A+B\ =\ \begin{bmatrix} * b_{00}-a_{00} & \dots & b_{0i}-a_{0i} & \dots & b_{0m}-a_{0m} \\ * \vdots & \ddots & \vdots & \ddots & \vdots \\ * b_{i0}-a_{i0} & \dots & b_{ij}-a_{ij} & \dots & b_{im}-a_{im} \\ * \vdots & \ddots & \vdots & \ddots & \vdots \\ * b_{n0}-a_{n0} & \dots & b_{nj}-a_{nj} & \dots & b_{nm}-a_{nm} * \end{bmatrix} * $$ * @param b the matrix to subtract. This matrix has to be same sized as this matrix. * @return the subtraction of this matrix with the given one. If the input matrix is null then null is returned. * @throws IllegalArgumentException if the input matrix size differs from this one. */ public Matrix subtract(Matrix b) throws IllegalArgumentException; /** * Compute the subtraction of this matrix with the given one and store it within the result matrix. * Formally, let A and B two matrices such that: * $$ * A\ =\ \begin{bmatrix} * a_{00} & \dots & a_{0i} & \dots & a_{0m} \\ * \vdots & \ddots & \vdots & \ddots & \vdots \\ * a_{i0} & \dots & a_{ij} & \dots & a_{im} \\ * \vdots & \ddots & \vdots & \ddots & \vdots \\ * a_{n0} & \dots & a_{nj} & \dots & a_{nm} * \end{bmatrix} * and\ B\ =\ \begin{bmatrix} * b_{00} & \dots & b_{0i} & \dots & b_{0m} \\ * \vdots & \ddots & \vdots & \ddots & \vdots \\ * b_{i0} & \dots & b_{ij} & \dots & b_{im} \\ * \vdots & \ddots & \vdots & \ddots & \vdots \\ * b_{n0} & \dots & b_{nj} & \dots & b_{nm} * \end{bmatrix} * $$ * The subtraction of A and B, denoted A - B is such that: * $$ * A+B\ =\ \begin{bmatrix} * b_{00}-a_{00} & \dots & b_{0i}-a_{0i} & \dots & b_{0m}-a_{0m} \\ * \vdots & \ddots & \vdots & \ddots & \vdots \\ * b_{i0}-a_{i0} & \dots & b_{ij}-a_{ij} & \dots & b_{im}-a_{im} \\ * \vdots & \ddots & \vdots & \ddots & \vdots \\ * b_{n0}-a_{n0} & \dots & b_{nj}-a_{nj} & \dots & b_{nm}-a_{nm} * \end{bmatrix} * $$ * @param b the matrix to subtract. This matrix has to be same sized as this matrix. * @param result the matrix that store the result. This matrix has to be same sized as this matrix. * @return the same reference as result. * @throws IllegalArgumentException if the input or result matrices size differs from this one. */ public Matrix subtract(Matrix b, Matrix result) throws IllegalArgumentException; /** * Affect this matrix with the result of its subtraction with the given one. * Formally, let A and B two matrices such that: * $$ * A\ =\ \begin{bmatrix} * a_{00} & \dots & a_{0i} & \dots & a_{0m} \\ * \vdots & \ddots & \vdots & \ddots & \vdots \\ * a_{i0} & \dots & a_{ij} & \dots & a_{im} \\ * \vdots & \ddots & \vdots & \ddots & \vdots \\ * a_{n0} & \dots & a_{nj} & \dots & a_{nm} * \end{bmatrix} * and\ B\ =\ \begin{bmatrix} * b_{00} & \dots & b_{0i} & \dots & b_{0m} \\ * \vdots & \ddots & \vdots & \ddots & \vdots \\ * b_{i0} & \dots & b_{ij} & \dots & b_{im} \\ * \vdots & \ddots & \vdots & \ddots & \vdots \\ * b_{n0} & \dots & b_{nj} & \dots & b_{nm} * \end{bmatrix} * $$ * The subtraction of A and B, denoted A - B is such that: * $$ * A+B\ =\ \begin{bmatrix} * b_{00}-a_{00} & \dots & b_{0i}-a_{0i} & \dots & b_{0m}-a_{0m} \\ * \vdots & \ddots & \vdots & \ddots & \vdots \\ * b_{i0}-a_{i0} & \dots & b_{ij}-a_{ij} & \dots & b_{im}-a_{im} \\ * \vdots & \ddots & \vdots & \ddots & \vdots \\ * b_{n0}-a_{n0} & \dots & b_{nj}-a_{nj} & \dots & b_{nm}-a_{nm} * \end{bmatrix} * $$ * @param b the matrix to subtract. This matrix has to be same sized as this matrix. * @return a reference on this matrix. * @throws IllegalArgumentException if the input matrix size differs from this one. */ public Matrix subtractAffect(Matrix b) throws IllegalArgumentException; /** * Compute and return the subtraction of this matrix with the given scalar. * Formally, let s be a scalar and A a matrix such that: * $$ * A\ =\ \begin{bmatrix} * a_{00} & \dots & a_{0i} & \dots & a_{0m} \\ * \vdots & \ddots & \vdots & \ddots & \vdots \\ * a_{i0} & \dots & a_{ij} & \dots & a_{im} \\ * \vdots & \ddots & \vdots & \ddots & \vdots \\ * a_{n0} & \dots & a_{nj} & \dots & a_{nm} * \end{bmatrix} * $$ * The subtraction of A and s, denoted As is such that: * $$ * A_{s}\ =\ \begin{bmatrix} * a_{00}-s & \dots & a_{0i}-s & \dots & a_{0m}-s \\ * \vdots & \ddots & \vdots & \ddots & \vdots \\ * a_{i0}-s & \dots & a_{ij}-s & \dots & a_{im}-s \\ * \vdots & \ddots & \vdots & \ddots & \vdots \\ * a_{n0}-s & \dots & a_{nj}-s & \dots & a_{nm}-s * \end{bmatrix} * $$ * @param s the scalar to subtract. * @return the subtraction of this matrix with the given scalar. */ public Matrix subtract(double s); /** * Compute the subtraction of this matrix with the given scalar and store it within the given result matrix. * Formally, let s be a scalar and A a matrix such that: * $$ * A\ =\ \begin{bmatrix} * a_{00} & \dots & a_{0i} & \dots & a_{0m} \\ * \vdots & \ddots & \vdots & \ddots & \vdots \\ * a_{i0} & \dots & a_{ij} & \dots & a_{im} \\ * \vdots & \ddots & \vdots & \ddots & \vdots \\ * a_{n0} & \dots & a_{nj} & \dots & a_{nm} * \end{bmatrix} * $$ * The subtraction of A and s, denoted As is such that: * $$ * A_{s}\ =\ \begin{bmatrix} * a_{00}-s & \dots & a_{0i}-s & \dots & a_{0m}-s \\ * \vdots & \ddots & \vdots & \ddots & \vdots \\ * a_{i0}-s & \dots & a_{ij}-s & \dots & a_{im}-s \\ * \vdots & \ddots & \vdots & \ddots & \vdots \\ * a_{n0}-s & \dots & a_{nj}-s & \dots & a_{nm}-s * \end{bmatrix} * $$ * @param s the scalar to subtract. * @param result the matrix that store the result. This matrix has to be same sized as this matrix. * @return the subtraction of this matrix with the given scalar. If the result matrix is null then null is returned. * @throws IllegalArgumentException if the result matrix size differs from this one. */ public Matrix subtract(double s, Matrix result) throws IllegalArgumentException; /** * Affect this matrix with the result of the subtraction of this matrix with the given scalar. * Formally, let s be a scalar and A a matrix such that: * $$ * A\ =\ \begin{bmatrix} * a_{00} & \dots & a_{0i} & \dots & a_{0m} \\ * \vdots & \ddots & \vdots & \ddots & \vdots \\ * a_{i0} & \dots & a_{ij} & \dots & a_{im} \\ * \vdots & \ddots & \vdots & \ddots & \vdots \\ * a_{n0} & \dots & a_{nj} & \dots & a_{nm} * \end{bmatrix} * $$ * The subtraction of A and s, denoted As is such that: * $$ * A_{s}\ =\ \begin{bmatrix} * a_{00}-s & \dots & a_{0i}-s & \dots & a_{0m}-s \\ * \vdots & \ddots & \vdots & \ddots & \vdots \\ * a_{i0}-s & \dots & a_{ij}-s & \dots & a_{im}-s \\ * \vdots & \ddots & \vdots & \ddots & \vdots \\ * a_{n0}-s & \dots & a_{nj}-s & \dots & a_{nm}-s * \end{bmatrix} * $$ * @param s the scalar to subtract. * @return a reference on this matrix. */ public Matrix subtractAffect(double s); /** * Return the inverse of the current matrix. Let A be a square matrix, its inverse, denoted A-1 is such that:
* A×A-1 = I
* where I is the identity matrix and × is the standard matrix product. * @return the inverse of the current matrix. * @throws IllegalStateException if the matrix is not invertible. */ public Matrix invert() throws IllegalStateException; /** * Compute the inverse of the current matrix and store it within the result matrix. * Let A be a square matrix, its inverse, denoted A-1 is such that:
* A×A-1 = I
* where I is the identity matrix and × is the standard matrix product. * @param result the matrix that has to store the inverse of the current matrix. * @return the same reference as result * @throws IllegalStateException if the result is not same sized as this matrix. * @throws IllegalArgumentException if the matrix is not invertible. */ public Matrix invert(Matrix result) throws IllegalStateException, IllegalArgumentException; /** * Compute the cofactor matrix. Formally, let A a square matrix defined such that: * $$ * A\ =\ \begin{bmatrix} * a_{00} & \dots & a_{0i} & \dots & a_{0n} \\ * \vdots & \ddots & \vdots & \ddots & \vdots \\ * a_{i0} & \dots & a_{ij} & \dots & a_{in} \\ * \vdots & \ddots & \vdots & \ddots & \vdots \\ * a_{n0} & \dots & a_{nj} & \dots & a_{nn} * \end{bmatrix} * $$ * The cofactor matrix of A, denoted C, is such that:
* $$ * C\ =\ \begin{bmatrix} * c_{00} & \dots & c_{0i} & \dots & c_{0n} \\ * \vdots & \ddots & \vdots & \ddots & \vdots \\ * c_{i0} & \dots & c_{ij} & \dots & c_{in} \\ * \vdots & \ddots & \vdots & \ddots & \vdots \\ * c_{n0} & \dots & c_{nj} & \dots & c_{nn} * \end{bmatrix} * $$ *
where cij = (-1)(i+j)|M(ij)|
* with Mij is the minor matrix from A obtained by ignoring row i and column j from A *
* @return the cofactor matrix. * @throws IllegalStateException if the matrix is not square. */ public Matrix cofactor() throws IllegalStateException; /** * Compute the cofactor matrix and store it within the given result. Formally, let A a square matrix defined such that: * $$ * A\ =\ \begin{bmatrix} * a_{00} & \dots & a_{0i} & \dots & a_{0n} \\ * \vdots & \ddots & \vdots & \ddots & \vdots \\ * a_{i0} & \dots & a_{ij} & \dots & a_{in} \\ * \vdots & \ddots & \vdots & \ddots & \vdots \\ * a_{n0} & \dots & a_{nj} & \dots & a_{nn} * \end{bmatrix} * $$ * The cofactor matrix of A, denoted C, is such that:
* $$ * C\ =\ \begin{bmatrix} * c_{00} & \dots & c_{0i} & \dots & c_{0n} \\ * \vdots & \ddots & \vdots & \ddots & \vdots \\ * c_{i0} & \dots & c_{ij} & \dots & c_{in} \\ * \vdots & \ddots & \vdots & \ddots & \vdots \\ * c_{n0} & \dots & c_{nj} & \dots & c_{nn} * \end{bmatrix} * $$ *
where cij = (-1)(i+j)|M(ij)|
* with Mij is the minor matrix from A obtained by ignoring row i and column j from A *
* @param result the matrix that have to store the result. * @return the same reference as result * @throws IllegalStateException if the matrix is not square. * @throws IllegalArgumentException if the result has not the same size as this matrix. */ public Matrix cofactor(Matrix result) throws IllegalStateException, IllegalArgumentException; /** * Compute the SVD decomposition of the matrix. *
* Let A be a real matrix that has a matrix of {@link EigenDecomposition Eigen vectors} P that is not invertible * (no {@link EigenDecomposition Eigen decomposition} can be computed). *

* If A is an m × n real matrix with m > n, then A can be written using a so-called singular value decomposition of the form * A = UDVT
*
* where:
*
    *
  • U is a m × m matrix with orthogonal columns (UTU = I) *
  • D is a m × n diagonal matrix *
  • V is a n × n matrix with orthogonal columns (VTV = I) *
*
*
* source: Wolfram math * @return the {@link SVDDecomposition SVD decomposition} of the matrix * @throws UnsupportedOperationException if the matrix cannot be decomposed */ public SVDDecomposition decomposeSVD(); /** * Compute the LU decomposition of the matrix. *
* Let A be a square matrix, the LU decomposition compute a lower triangular matrix L and an upper triangular matrix U such that:
*
* L×U = A
*
* where × is the standard matrix product. * @return the {@link LUDecomposition LU decomposition} of the matrix. * @throws UnsupportedOperationException if the matrix cannot be decomposed */ public LUDecomposition decomposeLU(); }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy