jat.matvec.data
Class Matrix

java.lang.Object
  extended by jat.matvec.data.Matrix
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable
Direct Known Subclasses:
RandomMatrix, RotationMatrix

public class Matrix
extends java.lang.Object
implements java.lang.Cloneable, java.io.Serializable

The Matrix Class provides the fundamental operations of numerical linear algebra (from the package JAMA), basic manipulations, and visualization tools. All the operations in this version of the Matrix Class involve only real matrices. This Matrix Class is an extension of JMAT's Matrix Class, which was an extension of JAMA's Matrix Class.

Version:
1.0
Author:
Dave Gaylor
See Also:
Serialized Form

Field Summary
 double[][] A
          Array for internal storage of elements.
 int m
          Row and column dimensions.
 int n
          Row and column dimensions.
 
Constructor Summary
Matrix(double[][] B)
          Construct a matrix from a 2D-array.
Matrix(double[][] B, int m, int n)
          Construct a matrix from a 2D-array.
Matrix(double[] vals, int m)
          Construct a matrix from a one-dimensional packed array
Matrix(int n)
          Construct an n-by-n identity matrix.
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.
Matrix(Matrix in)
          Construct a matrix from a Matrix.
Matrix(VectorN X)
          Construct a square matrix from a vector.
 
Method Summary
 void checkColumnDimension(int column)
          Check if number of Columns(A) == column.
 void checkColumnDimension(Matrix B)
          Check if number of Columns(A) == number of Columns(B).
static void checkIndicesDimensions(int[][] i, int[][] j)
          Check if indices have the same length.
static void checkIndicesLengths(int[] i, int[] j)
          Check if indices have the same length.
 void checkMatrixDimensions(int m2, int n2)
          Check if size(A) == m2*n2.
 void checkMatrixDimensions(Matrix B)
          Check if size(A) == size(B).
 void checkRowDimension(int row)
          Check if number of Rows(A) == row.
 void checkRowDimension(Matrix B)
          Check if number of Rows(A) == number of Rows(B).
 CholeskyDecomposition chol()
          Cholesky Decomposition
 java.lang.Object clone()
          Clone the Matrix object.
 double cond()
          Matrix condition (2 norm)
 Matrix copy()
          Make a deep copy of a matrix
 double det()
          Matrix determinant
 Matrix diag()
          Matrix diagonal extraction.
 Matrix diag(int num)
          Matrix diagonal extraction.
 VectorN diagonal()
          Return the diagonals of a square matrix in a VectorN
 Matrix dist(Matrix B)
          Generate a matrix, each column contents the Euclidian distance between the columns.
 Matrix distColumns(Matrix B)
          Generate a matrix, each line contents the Euclidian distance between the lines.
 Matrix distRows(Matrix B)
          Generate a matrix, each column contents the Euclidian distance between the columns.
 Matrix divide(double s)
          Divide a matrix by a scalar, C = A/s
 Matrix divide(Matrix B)
          Linear algebraic matrix division, A / B
 Matrix ebeAbs()
          Element-by-element inverse
 Matrix ebeCos()
          Element-by-element cosinus
 Matrix ebeDivide(double s)
          Divide a matrix by a scalar, C = A/s
 Matrix ebeDivide(Matrix B)
          Element-by-element right division, C = A./B
 Matrix ebeExp()
          Element-by-element exponential
 Matrix ebeFun(DoubleFunction fun)
          Element-by-element function evaluation
 Matrix ebeIndFun(DoubleFunction fun)
          Element-by-element indicial function evaluation
 Matrix ebeInv()
          Element-by-element inverse
 Matrix ebeLog()
          Element-by-element neperian logarithm
 Matrix ebeMinus(double s)
          Sub a scalar to each element of a matrix, C = A .- B
 Matrix ebePlus(double s)
          Add a scalar to each element of a matrix, C = A .+ s
 Matrix ebePow(double p)
          Element-by-element power
 Matrix ebePow(Matrix B)
          Element-by-element power
 Matrix ebeSin()
          Element-by-element sinus
 Matrix ebeSqrt()
          Element-by-element inverse
 Matrix ebeTimes(double s)
          Multiply a matrix by a scalar, C = s*A
 Matrix ebeTimes(Matrix B)
          Element-by-element multiplication, C = A.*B
 EigenvalueDecomposition eig()
          Eigenvalue Decomposition
 int[][] find(double e)
          Find an element
 int[][] find(java.lang.String test, double e)
          Find elements verifying a boolean test
 Matrix findMatrix(double e)
          Find an element
 Matrix findMatrix(java.lang.String test, double e)
          Find elements verifying a boolean test
static Matrix fromFile(java.io.File file)
          Load the Matrix from a file
static Matrix fromFile(java.lang.String fileName)
          Load the Matrix from a file.
static Matrix fromString(java.lang.String s)
          Load the Matrix from a String
 Matrix get(int[][] I, int[][] J)
          Get a several elements.
 Matrix get(int[] I, int[] J)
          Get a several elements in Column.
 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.
 Matrix getColumn(int c)
          Copy an internal one-dimensional array from a column.
 double[] getColumnArrayCopy(int c)
          Copy an internal one-dimensional array from a column.
 int getColumnDimension()
          Get column dimension.
 double[] getColumnPackedCopy()
          Make a one-dimensional column packed copy of the internal array.
 VectorN getColumnPackedVector()
          Make a one-dimensional column packed copy of the internal array.
 Matrix getColumns(int[] c)
          Copy an internal one-dimensional array from a column.
 VectorN getColumnVector(int c)
          Copy a column into a VectorN.
 Matrix getMatrix(int i0, int i1, int j0, int j1)
          Get a submatrix.
 Matrix getRow(int l)
          Copy an internal one-dimensional array from a row.
 double[] getRowArrayCopy(int l)
          Copy an internal one-dimensional array from a row.
 int getRowDimension()
          Get row dimension.
 double[] getRowPackedCopy()
          Make a one-dimensional row packed copy of the internal array.
 VectorN getRowPackedVector()
          Make a one-dimensional row packed copy of the internal array.
 Matrix getRows(int[] l)
          Copy an internal one-dimensional array from many rows.
 VectorN getRowVector(int c)
          Copy a row into a VectorN.
static Matrix identity(int m, int n)
          Generate identity matrix
static Matrix increment(int m, int n, double begin, double pitch)
          Generate a matrix with a constant pitch beetwen each row
static Matrix incrementColumns(int m, int n, double begin, double pitch)
          Generate a matrix with a constant pitch beetwen each column
static Matrix incrementRows(int m, int n, double begin, double pitch)
          Generate a matrix with a constant pitch beetwen each row
 Matrix inverse()
          Matrix inverse or pseudoinverse
 Matrix invert()
          Invert a matrix.
 LUDecomposition lu()
          LU Decomposition
 Matrix max()
          Generate a row matrix, each column contents the maximum value of the columns.
 Matrix maxColumns()
          Generate a column matrix, each line contents the maximum value of the lines.
 Matrix maxRows()
          Generate a row matrix, each column contents the maximum value of the columns.
 Matrix merge(Matrix B)
          Matrix merge.
static Matrix merge(Matrix[] Xs)
          Generate a matrix from other matrix.
 Matrix mergeColumns(Matrix B)
          Matrix merge.
static Matrix mergeColumns(Matrix[] Xs)
          Generate a matrix from other matrix.
 Matrix mergeRows(Matrix B)
          Matrix merge.
static Matrix mergeRows(Matrix[] Xs)
          Generate a matrix from other matrix.
 Matrix min()
          Generate a row matrix, each column contents the minimum value of the columns.
 Matrix minColumns()
          Generate a column matrix, each line contents the minimum value of the lines.
 Matrix minRows()
          Generate a row matrix, each column contents the minimum value of the columns.
 Matrix minus(Matrix B)
          C = A - B
 double norm1()
          One norm
 double norm2()
          Two norm
 double normF()
          Frobenius norm
 double normInf()
          Infinity norm
 Matrix plus(Matrix B)
          C = A + B
 void print()
          Print the Matrix to System.out
 void print(java.io.PrintWriter pw)
          Print the Matrix to a PrintWriter
 void print(java.lang.String title)
          Print the Matrix to System.out
 void printrows(java.lang.String title, int rows)
          Print the first n rows of Matrix to System.out
 Matrix prod()
          Generate a row matrix, each column contents the product value of the columns.
 Matrix prodColumns()
          Generate a column matrix, each line contents the product value of the lines.
 Matrix prodRows()
          Generate a row matrix, each column contents the product value of the columns.
 QRDecomposition qr()
          QR Decomposition
static Matrix random(int m, int n)
          Generate matrix with random elements
 int rank()
          Matrix rank
 Matrix reshape(int m2, int n2)
          Matrix reshape by Row.
 Matrix reshapeColumns(int m2, int n2)
          Matrix reshape by Column.
 Matrix reshapeRows(int m2, int n2)
          Matrix reshape by Row.
 Matrix resize(int m2, int n2)
          Matrix resize.
 void set(int[] I, int[] J, double s)
          Set several elements.
 void set(int i, int j, double s)
          Set a single element.
 void setColumn(int c, Matrix B)
          Set a column to an internal one-dimensional Column.
 void setColumn(int c, VectorN B)
          Set a column to an internal one-dimensional Column.
 void setColumns(int[] c, Matrix B)
          Copy an internal one-dimensional array from a column.
 void setMatrix(int[] I0, int[] J0, Matrix X)
          Set a submatrix.
 void setMatrix(int i0, int i1, int j0, int j1, double v)
          Set a submatrix.
 void setMatrix(int i0, int i1, int j0, int j1, Matrix X)
          Set a submatrix.
 void setMatrix(int i0, int j0, Matrix X)
          Set a submatrix.
 void setRow(int l, Matrix B)
          Copy an internal one-dimensional array from a row.
 void setRow(int l, VectorN B)
          Copy an internal one-dimensional array from a row.
 void setRows(int[] l, Matrix B)
          Copy an internal one-dimensional array from many rows.
 Matrix solve(Matrix B)
          Solve A*X = B
 int[] sort(int c)
          Generate a column-permuted matrix, rows are permuted in order to sort the column 'c'
 int[] sortColumns(int l)
          Generate a row-permuted matrix, columns are permuted in order to sort the row 'l'
 Matrix sortedColumnsMatrix(int l)
          Generate a row-permuted matrix, columns are permuted in order to sort the row 'l'
 Matrix sortedMatrix(int c)
          Generate a column-permuted matrix, rows are permuted in order to sort the column 'c'
 Matrix sortedRowsMatrix(int c)
          Generate a column-permuted matrix, rows are permuted in order to sort the column 'c'
 int[] sortRows(int c)
          Generate a column-permuted matrix, rows are permuted in order to sort the column 'c'
 Matrix sum()
          Generate a row matrix, each column contents the sum value of the columns.
 Matrix sumColumns()
          Generate a column matrix, each line contents the sum value of the lines.
 Matrix sumRows()
          Generate a row matrix, each column contents the sum value of the columns.
 SingularValueDecomposition svd()
          Singular Value Decomposition
 Matrix times(double s)
          Multiply a matrix by a scalar, C = s*A
 double[] times(double[] B)
          Matrix multiplied by a column array
 Matrix times(Matrix B)
          Linear algebraic matrix multiplication, A * B
 VectorN times(VectorN B)
          Matrix multiplied by a column vector
 void toCommandLine(java.lang.String title)
          Print the Matrix in the Command Line.
 void toFile(java.io.File file)
          Save the Matrix in a file.
 void toFile(java.lang.String fileName)
          Save the Matrix in a file.
 MatrixPlot2D toFramePlot2D(java.lang.String title)
          Plot the Matrix in a JFrame
 MatrixPlot2D toFramePlot2D(java.lang.String title, Matrix X)
          Plot the Matrix in a JFrame
 MatrixPlot3D toFramePlot3D(java.lang.String title)
          Plot the Matrix in a JFrame
 MatrixPlot3D toFramePlot3D(java.lang.String title, Matrix X, Matrix Y)
          Plot the Matrix in a Window in a JFrame
 void toFrameTable(java.lang.String title)
          Print the Matrix data in a Table in a JFrame
 MatrixPlot2D toPanelPlot2D()
          Plot the Matrix in a JPanel
 MatrixPlot2D toPanelPlot2D(Matrix X)
          Plot the Matrix in a JPanel
 MatrixPlot3D toPanelPlot3D()
          Plot the Matrix in a JPanel
 MatrixPlot3D toPanelPlot3D(Matrix X, Matrix Y)
          Plot the Matrix in a JFrame
 MatrixTable toPanelTable()
          Print the Matrix in a JTable
 java.lang.String toString()
          Convert the Matrix into a String
 double trace()
          Matrix trace.
 Matrix transpose()
          Matrix transpose.
 Matrix uminus()
          Unary minus
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

A

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


m

public int m
Row and column dimensions.


n

public 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 n)
Construct an n-by-n identity matrix.

Parameters:
n - Number of rows and colums.

Matrix

public Matrix(Matrix in)
Construct a matrix from a Matrix.

Parameters:
in - Matrix to create a copy of.

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(VectorN X)
Construct a square matrix from a vector.

Parameters:
X - Put the elements of x on the diagonal.

Matrix

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

Parameters:
B - Two-dimensional array of doubles.
Throws:
java.lang.IllegalArgumentException - All rows must have the same length
See Also:
#constructWithCopy

Matrix

public Matrix(double[][] B,
              int m,
              int n)
Construct a matrix from a 2D-array.

Parameters:
B - Two-dimensional array of doubles.
m - Number of rows.
n - Number of columns.
Throws:
java.lang.IllegalArgumentException - All rows must have the same length
See Also:
#constructWithCopy

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:
java.lang.IllegalArgumentException - Array length must be a multiple of m.
Method Detail

random

public static Matrix random(int m,
                            int n)
Generate matrix with random elements

Parameters:
m - Number of rows.
n - Number of colums.
Returns:
An m-by-n matrix with uniformly distributed random elements.

identity

public static Matrix identity(int m,
                              int n)
Generate identity matrix

Parameters:
m - Number of rows.
n - Number of colums.
Returns:
An m-by-n matrix with ones on the diagonal and zeros elsewhere.

increment

public static Matrix increment(int m,
                               int n,
                               double begin,
                               double pitch)
Generate a matrix with a constant pitch beetwen each row

Parameters:
m - Number of rows.
n - Number of colums.
begin - begining value to increment.
pitch - pitch to add.
Returns:
An m-by-n matrix.

incrementRows

public static Matrix incrementRows(int m,
                                   int n,
                                   double begin,
                                   double pitch)
Generate a matrix with a constant pitch beetwen each row

Parameters:
m - Number of rows.
n - Number of colums.
begin - begining value to increment.
pitch - pitch to add.
Returns:
An m-by-n matrix.

incrementColumns

public static Matrix incrementColumns(int m,
                                      int n,
                                      double begin,
                                      double pitch)
Generate a matrix with a constant pitch beetwen each column

Parameters:
m - Number of rows.
n - Number of colums.
begin - begining value to increment.
pitch - pitch to add.
Returns:
An m-by-n matrix.

merge

public static Matrix merge(Matrix[] Xs)
Generate a matrix from other matrix.

Parameters:
Xs - Matrix to merge.
Returns:
An m1+m2+...-by-n matrix.

mergeRows

public static Matrix mergeRows(Matrix[] Xs)
Generate a matrix from other matrix.

Parameters:
Xs - Matrix to merge.
Returns:
An m1+m2+...-by-n matrix.

mergeColumns

public static Matrix mergeColumns(Matrix[] Xs)
Generate a matrix from other matrix.

Parameters:
Xs - Matrix to merge.
Returns:
An m-by-n1+n2+... matrix.

copy

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

Returns:
A matrix.

clone

public java.lang.Object clone()
Clone the Matrix object.

Overrides:
clone in class java.lang.Object
Returns:
A matrix 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.

get

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

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

get

public Matrix get(int[] I,
                  int[] J)
Get a several elements in Column.

Parameters:
I - Row index.
J - Column index.
Returns:
A(I(:),J(:))
Throws:
java.lang.ArrayIndexOutOfBoundsException

get

public Matrix get(int[][] I,
                  int[][] J)
Get a several elements.

Parameters:
I - Row index.
J - Column index.
Returns:
A(I(:,:),J(:,:))
Throws:
java.lang.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:
java.lang.ArrayIndexOutOfBoundsException - Submatrix indices

getRowArrayCopy

public double[] getRowArrayCopy(int l)
Copy an internal one-dimensional array from a row.

Parameters:
l - Row index
Returns:
one-dimensional array copy of matrix elements.

getRowVector

public VectorN getRowVector(int c)
Copy a row into a VectorN.

Parameters:
c - Row index
Returns:
VectorN copy of matrix elements.

getRow

public Matrix getRow(int l)
Copy an internal one-dimensional array from a row.

Parameters:
l - Row index
Returns:
one-dimensional array copy of matrix elements.

getRows

public Matrix getRows(int[] l)
Copy an internal one-dimensional array from many rows.

Parameters:
l - Rows indexes
Returns:
one-dimensional array copy of matrix elements.

getColumnArrayCopy

public double[] getColumnArrayCopy(int c)
Copy an internal one-dimensional array from a column.

Parameters:
c - Column index
Returns:
one-dimensional array copy of matrix elements.

getColumn

public Matrix getColumn(int c)
Copy an internal one-dimensional array from a column.

Parameters:
c - Column index
Returns:
one-dimensional array copy of matrix elements.

getColumnVector

public VectorN getColumnVector(int c)
Copy a column into a VectorN.

Parameters:
c - Column index
Returns:
VectorN copy of matrix elements.

getColumns

public Matrix getColumns(int[] c)
Copy an internal one-dimensional array from a column.

Parameters:
c - Columns indexes
Returns:
one-dimensional array copy of matrix elements.

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.

getRowPackedVector

public VectorN getRowPackedVector()
Make a one-dimensional row packed copy of the internal array.

Returns:
Matrix elements packed in a vector by rows.

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.

getColumnPackedVector

public VectorN getColumnPackedVector()
Make a one-dimensional column packed copy of the internal array.

Returns:
Matrix elements packed in a vector by column.

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.

diag

public Matrix diag()
Matrix diagonal extraction.

Returns:
An d*1 Matrix of diagonal elements, d = min(m,n).

diag

public Matrix diag(int num)
Matrix diagonal extraction.

Parameters:
num - diagonal number.
Returns:
Matrix of the n-th diagonal elements.

diagonal

public VectorN diagonal()
Return the diagonals of a square matrix in a VectorN

Returns:
VectorN containing the diagonal elements

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:
java.lang.ArrayIndexOutOfBoundsException

set

public void set(int[] I,
                int[] J,
                double s)
Set several elements.

Parameters:
I - Row index.
J - Column index.
s - A(I(:),J(:)).
Throws:
java.lang.ArrayIndexOutOfBoundsException

setMatrix

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

Parameters:
i0 - Initial row index
j0 - Initial column index
X - subMatrix to set
Throws:
java.lang.ArrayIndexOutOfBoundsException - Submatrix indices

setMatrix

public void setMatrix(int[] I0,
                      int[] J0,
                      Matrix X)
Set a submatrix.

Parameters:
I0 - Initial row indexes
J0 - Initial column indexes
X - subMatrix to set
Throws:
java.lang.ArrayIndexOutOfBoundsException - Submatrix indices

setMatrix

public void setMatrix(int i0,
                      int i1,
                      int j0,
                      int j1,
                      double v)
Set a submatrix.

Parameters:
i0 - Initial row index
i1 - Final row index
j0 - Initial column index
j1 - Final column index
v - Value to set in the submatrix
Throws:
java.lang.ArrayIndexOutOfBoundsException - Submatrix indices

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:
java.lang.ArrayIndexOutOfBoundsException - Submatrix indices

setRow

public void setRow(int l,
                   Matrix B)
Copy an internal one-dimensional array from a row.

Parameters:
l - Row index
B - Row-matrix

setRow

public void setRow(int l,
                   VectorN B)
Copy an internal one-dimensional array from a row.

Parameters:
l - Row index
B - VectorN

setRows

public void setRows(int[] l,
                    Matrix B)
Copy an internal one-dimensional array from many rows.

Parameters:
l - Rows indexes
B - Rows-matrix

setColumn

public void setColumn(int c,
                      Matrix B)
Set a column to an internal one-dimensional Column.

Parameters:
c - Column index
B - Column-matrix

setColumn

public void setColumn(int c,
                      VectorN B)
Set a column to an internal one-dimensional Column.

Parameters:
c - Column index
B - VectorN

setColumns

public void setColumns(int[] c,
                       Matrix B)
Copy an internal one-dimensional array from a column.

Parameters:
c - Columns indexes
B - Columns-matrix

resize

public Matrix resize(int m2,
                     int n2)
Matrix resize.

Parameters:
m2 - number of rows
n2 - number of columns
Returns:
resized matrix

reshape

public Matrix reshape(int m2,
                      int n2)
Matrix reshape by Row.

Parameters:
m2 - number of rows
n2 - number of columns
Returns:
reshaped matrix

reshapeRows

public Matrix reshapeRows(int m2,
                          int n2)
Matrix reshape by Row.

Parameters:
m2 - number of rows
n2 - number of columns
Returns:
reshaped matrix

reshapeColumns

public Matrix reshapeColumns(int m2,
                             int n2)
Matrix reshape by Column.

Parameters:
m2 - number of rows
n2 - number of columns
Returns:
reshaped matrix

transpose

public Matrix transpose()
Matrix transpose.

Returns:
A'

merge

public Matrix merge(Matrix B)
Matrix merge.

Parameters:
B - matrix to merge
Returns:
An m.B.m-by-n matrix

mergeRows

public Matrix mergeRows(Matrix B)
Matrix merge.

Parameters:
B - matrix to merge
Returns:
An m.B+m-by-n matrix

mergeColumns

public Matrix mergeColumns(Matrix B)
Matrix merge.

Parameters:
B - matrix to merge
Returns:
An m-by-n+B.n matrix

norm1

public double norm1()
One norm

Returns:
maximum column sum.

norm2

public double norm2()
Two norm

Returns:
maximum singular value.

normInf

public double normInf()
Infinity norm

Returns:
maximum row sum.

normF

public double normF()
Frobenius norm

Returns:
sqrt of sum of squares of all elements.

det

public double det()
Matrix determinant

Returns:
determinant

rank

public int rank()
Matrix rank

Returns:
effective numerical rank, obtained from SVD.

cond

public double cond()
Matrix condition (2 norm)

Returns:
ratio of largest to smallest singular value.

trace

public double trace()
Matrix trace.

Returns:
sum of the diagonal elements.

min

public Matrix min()
Generate a row matrix, each column contents the minimum value of the columns.

Returns:
An 1-by-n matrix.

minRows

public Matrix minRows()
Generate a row matrix, each column contents the minimum value of the columns.

Returns:
An 1-by-n matrix.

minColumns

public Matrix minColumns()
Generate a column matrix, each line contents the minimum value of the lines.

Returns:
An m-by-1 matrix.

max

public Matrix max()
Generate a row matrix, each column contents the maximum value of the columns.

Returns:
An 1-by-n matrix.

maxRows

public Matrix maxRows()
Generate a row matrix, each column contents the maximum value of the columns.

Returns:
An 1-by-n matrix.

maxColumns

public Matrix maxColumns()
Generate a column matrix, each line contents the maximum value of the lines.

Returns:
An m-by-1 matrix.

sum

public Matrix sum()
Generate a row matrix, each column contents the sum value of the columns.

Returns:
An 1-by-n matrix.

sumRows

public Matrix sumRows()
Generate a row matrix, each column contents the sum value of the columns.

Returns:
An 1-by-n matrix.

sumColumns

public Matrix sumColumns()
Generate a column matrix, each line contents the sum value of the lines.

Returns:
An m-by-1 matrix.

prod

public Matrix prod()
Generate a row matrix, each column contents the product value of the columns.

Returns:
An 1-by-n matrix.

prodRows

public Matrix prodRows()
Generate a row matrix, each column contents the product value of the columns.

Returns:
An 1-by-n matrix.

prodColumns

public Matrix prodColumns()
Generate a column matrix, each line contents the product value of the lines.

Returns:
An m-by-1 matrix.

dist

public Matrix dist(Matrix B)
Generate a matrix, each column contents the Euclidian distance between the columns.

Parameters:
B - Matrix
Returns:
An m-by-B.m matrix.

distRows

public Matrix distRows(Matrix B)
Generate a matrix, each column contents the Euclidian distance between the columns.

Parameters:
B - Matrix
Returns:
An m-by-B.m matrix.

distColumns

public Matrix distColumns(Matrix B)
Generate a matrix, each line contents the Euclidian distance between the lines.

Parameters:
B - Matrix
Returns:
An B.n-by-n matrix.

uminus

public Matrix uminus()
Unary minus

Returns:
-A

plus

public Matrix plus(Matrix B)
C = A + B

Parameters:
B - another matrix
Returns:
A + B

minus

public Matrix minus(Matrix B)
C = A - B

Parameters:
B - another matrix
Returns:
A - B

times

public Matrix times(double s)
Multiply a matrix by a scalar, C = s*A

Parameters:
s - scalar
Returns:
s*A

times

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

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

divide

public Matrix divide(double s)
Divide a matrix by a scalar, C = A/s

Parameters:
s - scalar
Returns:
A/s

divide

public Matrix divide(Matrix B)
Linear algebraic matrix division, A / B

Parameters:
B - another matrix
Returns:
Matrix division, A / B
Throws:
java.lang.IllegalArgumentException - Matrix inner dimensions must agree.
java.lang.IllegalArgumentException - Matrix inner dimensions must agree.

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

inverse

public Matrix inverse()
Matrix inverse or pseudoinverse

Returns:
inverse(A) if A is square, pseudoinverse otherwise.

times

public double[] times(double[] B)
Matrix multiplied by a column array

Parameters:
B - array to be post-multiplied
Returns:
A*B

times

public VectorN times(VectorN B)
Matrix multiplied by a column vector

Parameters:
B - vector to be post-multiplied
Returns:
A*B

ebePlus

public Matrix ebePlus(double s)
Add a scalar to each element of a matrix, C = A .+ s

Parameters:
s - double
Returns:
A .+ s

ebeMinus

public Matrix ebeMinus(double s)
Sub a scalar to each element of a matrix, C = A .- B

Parameters:
s - double
Returns:
A .- s

ebeTimes

public Matrix ebeTimes(double s)
Multiply a matrix by a scalar, C = s*A

Parameters:
s - scalar
Returns:
s*A

ebeTimes

public Matrix ebeTimes(Matrix B)
Element-by-element multiplication, C = A.*B

Parameters:
B - another matrix
Returns:
A.*B

ebeDivide

public Matrix ebeDivide(double s)
Divide a matrix by a scalar, C = A/s

Parameters:
s - scalar
Returns:
A/s

ebeDivide

public Matrix ebeDivide(Matrix B)
Element-by-element right division, C = A./B

Parameters:
B - another matrix
Returns:
A./B

ebeCos

public Matrix ebeCos()
Element-by-element cosinus

Returns:
cos.(A)

ebeSin

public Matrix ebeSin()
Element-by-element sinus

Returns:
sin.(A)

ebeExp

public Matrix ebeExp()
Element-by-element exponential

Returns:
exp.(A)

ebePow

public Matrix ebePow(double p)
Element-by-element power

Parameters:
p - double
Returns:
A.^p

ebePow

public Matrix ebePow(Matrix B)
Element-by-element power

Parameters:
B - another matrix
Returns:
A.^B

ebeLog

public Matrix ebeLog()
Element-by-element neperian logarithm

Returns:
log.(A)

ebeInv

public Matrix ebeInv()
Element-by-element inverse

Returns:
A.^-1

ebeSqrt

public Matrix ebeSqrt()
Element-by-element inverse

Returns:
A.^-1

ebeAbs

public Matrix ebeAbs()
Element-by-element inverse

Returns:
A.^-1

ebeFun

public Matrix ebeFun(DoubleFunction fun)
Element-by-element function evaluation

Parameters:
fun - function to apply
Returns:
f.(A)

ebeIndFun

public Matrix ebeIndFun(DoubleFunction fun)
Element-by-element indicial function evaluation

Parameters:
fun - function to apply
Returns:
f.(A)

lu

public LUDecomposition lu()
LU Decomposition

Returns:
LUDecomposition
See Also:
LUDecomposition

qr

public QRDecomposition qr()
QR Decomposition

Returns:
QRDecomposition
See Also:
QRDecomposition

chol

public CholeskyDecomposition chol()
Cholesky Decomposition

Returns:
CholeskyDecomposition
See Also:
CholeskyDecomposition

svd

public SingularValueDecomposition svd()
Singular Value Decomposition

Returns:
SingularValueDecomposition
See Also:
SingularValueDecomposition

eig

public EigenvalueDecomposition eig()
Eigenvalue Decomposition

Returns:
EigenvalueDecomposition
See Also:
EigenvalueDecomposition

sort

public int[] sort(int c)
Generate a column-permuted matrix, rows are permuted in order to sort the column 'c'

Parameters:
c - Number of the colum which leads the permuation
Returns:
An Integer Array.

sortRows

public int[] sortRows(int c)
Generate a column-permuted matrix, rows are permuted in order to sort the column 'c'

Parameters:
c - Number of the colum which leads the permuation
Returns:
An m-by-n matrix.

sortColumns

public int[] sortColumns(int l)
Generate a row-permuted matrix, columns are permuted in order to sort the row 'l'

Parameters:
l - Number of the row which leads the permuation
Returns:
An Integer Array.

sortedMatrix

public Matrix sortedMatrix(int c)
Generate a column-permuted matrix, rows are permuted in order to sort the column 'c'

Parameters:
c - Number of the colum which leads the permuation
Returns:
An m-by-n matrix.

sortedRowsMatrix

public Matrix sortedRowsMatrix(int c)
Generate a column-permuted matrix, rows are permuted in order to sort the column 'c'

Parameters:
c - Number of the colum which leads the permuation
Returns:
An m-by-n matrix.

sortedColumnsMatrix

public Matrix sortedColumnsMatrix(int l)
Generate a row-permuted matrix, columns are permuted in order to sort the row 'l'

Parameters:
l - Number of the row which leads the permuation
Returns:
An m-by-n matrix.

find

public int[][] find(double e)
Find an element

Parameters:
e - Element (value) to find
Returns:
A list of indices where this element is found.

find

public int[][] find(java.lang.String test,
                    double e)
Find elements verifying a boolean test

Parameters:
test - Test to apply: < > =...
e - Element (value) to compare
Returns:
A list of indices where this element is found.

findMatrix

public Matrix findMatrix(double e)
Find an element

Parameters:
e - Element (value) to find
Returns:
A list of indices where this element is found.

findMatrix

public Matrix findMatrix(java.lang.String test,
                         double e)
Find elements verifying a boolean test

Parameters:
test - Test to apply: < > =...
e - Element (value) to compare
Returns:
A list of indices where this element is found.

toCommandLine

public void toCommandLine(java.lang.String title)
Print the Matrix in the Command Line.

Parameters:
title - title to display in the command line.

toFile

public void toFile(java.lang.String fileName)
Save the Matrix in a file.

Parameters:
fileName - filename to save in.

toFile

public void toFile(java.io.File file)
Save the Matrix in a file.

Parameters:
file - file to save in.

fromFile

public static Matrix fromFile(java.lang.String fileName)
Load the Matrix from a file.

Parameters:
fileName - filename of the file to load.
Returns:
A matrix.

fromFile

public static Matrix fromFile(java.io.File file)
Load the Matrix from a file

Parameters:
file - file to load
Returns:
A matrix

toString

public java.lang.String toString()
Convert the Matrix into a String

Overrides:
toString in class java.lang.Object
Returns:
A String

fromString

public static Matrix fromString(java.lang.String s)
Load the Matrix from a String

Parameters:
s - String to load
Returns:
A matrix

toPanelTable

public MatrixTable toPanelTable()
Print the Matrix in a JTable

Returns:
A Swing JTable in a JPanel

toFrameTable

public void toFrameTable(java.lang.String title)
Print the Matrix data in a Table in a JFrame

Parameters:
title - Title of the JFrame.

toPanelPlot2D

public MatrixPlot2D toPanelPlot2D()
Plot the Matrix in a JPanel

Returns:
A MatrixPlot2D (extends a JPanel)

toFramePlot2D

public MatrixPlot2D toFramePlot2D(java.lang.String title)
Plot the Matrix in a JFrame

Parameters:
title - Title of the JFrame.
Returns:
A MatrixPlot2D (extends a Swing JPanel)

toPanelPlot2D

public MatrixPlot2D toPanelPlot2D(Matrix X)
Plot the Matrix in a JPanel

Parameters:
X - Matrix
Returns:
A MatrixPlot2D (extends a Swing JPanel)

toFramePlot2D

public MatrixPlot2D toFramePlot2D(java.lang.String title,
                                  Matrix X)
Plot the Matrix in a JFrame

Parameters:
title - Title of the JFrame.
X - Matrix
Returns:
A MatrixPlot2D (extends a Swing JPanel)

toPanelPlot3D

public MatrixPlot3D toPanelPlot3D()
Plot the Matrix in a JPanel

Returns:
A MatrixPlot3D (extends a Swing JPanel)

toFramePlot3D

public MatrixPlot3D toFramePlot3D(java.lang.String title)
Plot the Matrix in a JFrame

Parameters:
title - Title of the JFrame.
Returns:
A MatrixPlot3D (extends a Swing JPanel)

toPanelPlot3D

public MatrixPlot3D toPanelPlot3D(Matrix X,
                                  Matrix Y)
Plot the Matrix in a JFrame

Parameters:
X - Matrix
Y - Matrix
Returns:
A MatrixPlot3D (extends a Swing JPanel)

toFramePlot3D

public MatrixPlot3D toFramePlot3D(java.lang.String title,
                                  Matrix X,
                                  Matrix Y)
Plot the Matrix in a Window in a JFrame

Parameters:
title - Title of the JFrame.
X - Matrix
Y - Matrix
Returns:
A MatrixPlot3D (extends a Swing JPanel)

print

public void print()
Print the Matrix to System.out


print

public void print(java.io.PrintWriter pw)
Print the Matrix to a PrintWriter

Parameters:
pw - PrintWriter to print to.

print

public void print(java.lang.String title)
Print the Matrix to System.out

Parameters:
title - A title or label for the matrix

printrows

public void printrows(java.lang.String title,
                      int rows)
Print the first n rows of Matrix to System.out

Parameters:
title - A title or label for the matrix
rows - Number of rows to print

checkMatrixDimensions

public void checkMatrixDimensions(Matrix B)
Check if size(A) == size(B).

Parameters:
B - Matrix to test.

checkMatrixDimensions

public void checkMatrixDimensions(int m2,
                                  int n2)
Check if size(A) == m2*n2.

Parameters:
m2 - Number of rows.
n2 - Number of columns.

checkIndicesLengths

public static void checkIndicesLengths(int[] i,
                                       int[] j)
Check if indices have the same length.

Parameters:
i - Indices.
j - Indices.

checkIndicesDimensions

public static void checkIndicesDimensions(int[][] i,
                                          int[][] j)
Check if indices have the same length.

Parameters:
i - Indices.
j - Indices.

checkRowDimension

public void checkRowDimension(Matrix B)
Check if number of Rows(A) == number of Rows(B).

Parameters:
B - Matrix to test.

checkRowDimension

public void checkRowDimension(int row)
Check if number of Rows(A) == row.

Parameters:
row - number of rows.

checkColumnDimension

public void checkColumnDimension(Matrix B)
Check if number of Columns(A) == number of Columns(B).

Parameters:
B - Matrix to test.

checkColumnDimension

public void checkColumnDimension(int column)
Check if number of Columns(A) == column.

Parameters:
column - number of columns.

invert

public Matrix invert()
Invert a matrix.

Returns:
the inverse.