matrice
Class Matrix

java.lang.Object
  extended by matrice.Matrix

public class Matrix
extends Object

Class Matrix du package JAMA "allegee" (pas d'options d'affichage notamment, pour rester compatible avec la version java 1.1)

Since:
Projet Trois Corps 2007
Version:
5 August 1998
Author:
The MathWorks, Inc. and the National Institute of Standards and Technology.

Field Summary
private  double[][] A
          Array for internal storage of elements.
private  int m
          Row and column dimensions.
private  int n
          Row and column dimensions.
 
Constructor Summary
Matrix(double[][] A)
          Construct a matrix from a 2-D array.
Matrix(double[][] A, int m, int n)
          Construct a matrix quickly without checking arguments.
Matrix(double[] vals, int m)
          Construct a matrix from a one-dimensional packed array
Matrix(int m, int n)
          Construct an m-by-n matrix of zeros.
Matrix(int m, int n, double s)
          Construct an m-by-n constant matrix.
 
Method Summary
 Object clone()
          Clone the Matrix object.
static Matrix constructWithCopy(double[][] A)
          Construct a matrix from a copy of a 2-D array.
 Matrix copy()
          Make a deep copy of a matrix
 double det()
          Matrix determinant
 double get(int i, int j)
          Get a single element.
 double[][] getArray()
          Access the internal two-dimensional array.
 double[][] getArrayCopy()
          Copy the internal two-dimensional array.
 int getColumnDimension()
          Get column dimension.
 double[] getColumnPackedCopy()
          Make a one-dimensional column packed copy of the internal array.
 Matrix getMatrix(int[] r, int[] c)
          Get a submatrix.
 Matrix getMatrix(int[] r, int j0, int j1)
          Get a submatrix.
 Matrix getMatrix(int i0, int i1, int[] c)
          Get a submatrix.
 Matrix getMatrix(int i0, int i1, int j0, int j1)
          Get a submatrix.
 int getRowDimension()
          Get row dimension.
 double[] getRowPackedCopy()
          Make a one-dimensional row packed copy of the internal array.
 LUDecomposition lu()
          LU Decomposition
 void set(int i, int j, double s)
          Set a single element.
 void setMatrix(int[] r, int[] c, Matrix X)
          Set a submatrix.
 void setMatrix(int[] r, int j0, int j1, Matrix X)
          Set a submatrix.
 void setMatrix(int i0, int i1, int[] c, Matrix X)
          Set a submatrix.
 void setMatrix(int i0, int i1, int j0, int j1, Matrix X)
          Set a submatrix.
 Matrix solve(Matrix B)
          Solve A*X = B
 Matrix times(Matrix B)
          Linear algebraic matrix multiplication, A * B
 double trace()
          Matrix trace.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

A

private double[][] A
Array for internal storage of elements.


m

private int m
Row and column dimensions.


n

private int n
Row and column dimensions.

Constructor Detail

Matrix

public Matrix(int m,
              int n)
Construct an m-by-n matrix of zeros.

Parameters:
m - Number of rows.
n - Number of colums.

Matrix

public Matrix(int m,
              int n,
              double s)
Construct an m-by-n constant matrix.

Parameters:
m - Number of rows.
n - Number of colums.
s - Fill the matrix with this scalar value.

Matrix

public Matrix(double[][] A)
Construct a matrix from a 2-D array.

Parameters:
A - Two-dimensional array of doubles.
Throws:
IllegalArgumentException - All rows must have the same length
See Also:
constructWithCopy(double[][])

Matrix

public Matrix(double[][] A,
              int m,
              int n)
Construct a matrix quickly without checking arguments.

Parameters:
A - Two-dimensional array of doubles.
m - Number of rows.
n - Number of colums.

Matrix

public Matrix(double[] vals,
              int m)
Construct a matrix from a one-dimensional packed array

Parameters:
vals - One-dimensional array of doubles, packed by columns (ala Fortran).
m - Number of rows.
Throws:
IllegalArgumentException - Array length must be a multiple of m.
Method Detail

constructWithCopy

public static Matrix constructWithCopy(double[][] A)
Construct a matrix from a copy of a 2-D array.

Parameters:
A - Two-dimensional array of doubles.
Throws:
IllegalArgumentException - All rows must have the same length

copy

public Matrix copy()
Make a deep copy of a matrix


clone

public Object clone()
Clone the Matrix object.

Overrides:
clone in class Object

getArray

public double[][] getArray()
Access the internal two-dimensional array.

Returns:
Pointer to the two-dimensional array of matrix elements.

getArrayCopy

public double[][] getArrayCopy()
Copy the internal two-dimensional array.

Returns:
Two-dimensional array copy of matrix elements.

getColumnPackedCopy

public double[] getColumnPackedCopy()
Make a one-dimensional column packed copy of the internal array.

Returns:
Matrix elements packed in a one-dimensional array by columns.

getRowPackedCopy

public double[] getRowPackedCopy()
Make a one-dimensional row packed copy of the internal array.

Returns:
Matrix elements packed in a one-dimensional array by rows.

getRowDimension

public int getRowDimension()
Get row dimension.

Returns:
m, the number of rows.

getColumnDimension

public int getColumnDimension()
Get column dimension.

Returns:
n, the number of columns.

get

public double get(int i,
                  int j)
Get a single element.

Parameters:
i - Row index.
j - Column index.
Returns:
A(i,j)
Throws:
ArrayIndexOutOfBoundsException

getMatrix

public Matrix getMatrix(int i0,
                        int i1,
                        int j0,
                        int j1)
Get a submatrix.

Parameters:
i0 - Initial row index
i1 - Final row index
j0 - Initial column index
j1 - Final column index
Returns:
A(i0:i1,j0:j1)
Throws:
ArrayIndexOutOfBoundsException - Submatrix indices

getMatrix

public Matrix getMatrix(int[] r,
                        int[] c)
Get a submatrix.

Parameters:
r - Array of row indices.
c - Array of column indices.
Returns:
A(r(:),c(:))
Throws:
ArrayIndexOutOfBoundsException - Submatrix indices

getMatrix

public Matrix getMatrix(int i0,
                        int i1,
                        int[] c)
Get a submatrix.

Parameters:
i0 - Initial row index
i1 - Final row index
c - Array of column indices.
Returns:
A(i0:i1,c(:))
Throws:
ArrayIndexOutOfBoundsException - Submatrix indices

getMatrix

public Matrix getMatrix(int[] r,
                        int j0,
                        int j1)
Get a submatrix.

Parameters:
r - Array of row indices.
j0 - Initial column index
j1 - Final column index
Returns:
A(r(:),j0:j1)
Throws:
ArrayIndexOutOfBoundsException - Submatrix indices

set

public void set(int i,
                int j,
                double s)
Set a single element.

Parameters:
i - Row index.
j - Column index.
s - A(i,j).
Throws:
ArrayIndexOutOfBoundsException

setMatrix

public void setMatrix(int i0,
                      int i1,
                      int j0,
                      int j1,
                      Matrix X)
Set a submatrix.

Parameters:
i0 - Initial row index
i1 - Final row index
j0 - Initial column index
j1 - Final column index
X - A(i0:i1,j0:j1)
Throws:
ArrayIndexOutOfBoundsException - Submatrix indices

setMatrix

public void setMatrix(int[] r,
                      int[] c,
                      Matrix X)
Set a submatrix.

Parameters:
r - Array of row indices.
c - Array of column indices.
X - A(r(:),c(:))
Throws:
ArrayIndexOutOfBoundsException - Submatrix indices

setMatrix

public void setMatrix(int[] r,
                      int j0,
                      int j1,
                      Matrix X)
Set a submatrix.

Parameters:
r - Array of row indices.
j0 - Initial column index
j1 - Final column index
X - A(r(:),j0:j1)
Throws:
ArrayIndexOutOfBoundsException - Submatrix indices

setMatrix

public void setMatrix(int i0,
                      int i1,
                      int[] c,
                      Matrix X)
Set a submatrix.

Parameters:
i0 - Initial row index
i1 - Final row index
c - Array of column indices.
X - A(i0:i1,c(:))
Throws:
ArrayIndexOutOfBoundsException - Submatrix indices

times

public Matrix times(Matrix B)
Linear algebraic matrix multiplication, A * B

Parameters:
B - another matrix
Returns:
Matrix product, A * B
Throws:
IllegalArgumentException - Matrix inner dimensions must agree.

lu

public LUDecomposition lu()
LU Decomposition

Returns:
LUDecomposition
See Also:
LUDecomposition

solve

public Matrix solve(Matrix B)
Solve A*X = B

Parameters:
B - right hand side
Returns:
solution if A is square, least squares solution otherwise

det

public double det()
Matrix determinant

Returns:
determinant

trace

public double trace()
Matrix trace.

Returns:
sum of the diagonal elements.