org.jmat
Class MatlabSyntax

java.lang.Object
  |
  +--org.jmat.MatlabSyntax

public class MatlabSyntax
extends java.lang.Object

Description : Enables an easy to use Matlab-like syntax for invokation of main features.

Copyright : GPL


Field Summary
protected  long t
           
 
Constructor Summary
MatlabSyntax()
           
 
Method Summary
static Matrix abs(Matrix A)
          Element-by-element inverse
static Matrix chol(Matrix A)
          Cholesky Decomposition
static double cond(Matrix A)
          Matrix condition (2 norm)
static Matrix corrcoef(Matrix A)
          Generate a correlation matrix.
static Matrix cos(Matrix A)
          Element-by-element cosinus
static Matrix cov(Matrix A)
          Generate a covariance matrix.
static double det(Matrix A)
          Matrix determinant
static Matrix diag(Matrix A)
          Matrix diagonal extraction.
static Matrix diag(Matrix A, int num)
          Matrix diagonal extraction.
static void disp(Matrix A)
          Print the Matrix in the Command Line.
static void disp(java.lang.String text)
          Print the Matrix in the Command Line.
static Matrix divide(Matrix A, double s)
          Divide a matrix by a scalar, C = A/s
static Matrix divide(Matrix A, Matrix B)
          Linear algebraic matrix division, A / B
static Matrix ebeDivide(Matrix A, Matrix B)
          Element-by-element right division, C = A.
static Matrix ebeTimes(Matrix A, Matrix B)
          Element-by-element multiplication, C = A.
static Matrix eig_D(Matrix A)
          Eigenvalue Decomposition
static Matrix eig_V(Matrix A)
          Eigenvalue Decomposition
static Matrix exp(Matrix A)
          Element-by-element exponential
static RandomMatrix expRnd(double mu, int m, int n)
          Construct an m-by-n matrix of random numbers from an exponantial random variable.
static Matrix eye(int m, int n)
          Generate identity matrix
static Matrix find(Matrix A, java.lang.String test, double e)
          Find elements verifying a boolean test
static double get(Matrix A, int i, int j)
          Get a single element.
static Matrix get(Matrix A, int i0, int i1, int j0, int j1)
          Get a submatrix.
static Matrix getColumn(Matrix A, int c)
          Copy an internal one-dimensional array from a column.
static Matrix getRow(Matrix A, int l)
          Copy an internal one-dimensional array from a row.
static Plot2DPanel hist(Matrix X, int n)
          Plot the Matrix in a JFrame
static Plot2DPanel hist(java.lang.String title, Matrix X, int n)
          Plot the Matrix in a JFrame
static Matrix inc(int m, int n)
          Generate a matrix with a constant pitch beetwen each row
static Matrix inc(int m, int n, double begin, double pitch)
          Generate a matrix with a constant pitch beetwen each row
static Matrix inv(Matrix A)
          Matrix inverse or pseudoinverse
static Matrix load(java.lang.String fileName)
          Load the Matrix from an ASCII file.
static Matrix log(Matrix A)
          Element-by-element neperian logarithm
static Matrix lu_L(Matrix A)
          LU Decomposition
static Matrix lu_P(Matrix A)
          LU Decomposition
static Matrix lu_U(Matrix A)
          LU Decomposition
static Matrix matrix(double[][] B)
          Construct a matrix from a 2D-array.
static Matrix matrix(int m, int n, double s)
          Construct an m-by-n constant matrix.
static Matrix max(Matrix A)
          Generate a row matrix, each column contents the maximum value of the columns.
static Matrix mean(Matrix A)
          Generate a row matrix, each column contents the mean value of the columns.
static Matrix merge(Matrix A, Matrix B, int n)
          Generate a matrix from other matrix.
static Matrix min(Matrix A)
          Generate a row matrix, each column contents the minimum value of the columns.
static Matrix minus(Matrix A, Matrix B)
          C = A - B
static double norm(Matrix A, java.lang.String n)
          Norm
static RandomMatrix normRnd(double mu, double sigma, int m, int n)
          Construct an m-by-n matrix of random numbers from an normal random variable.
static Matrix ones(int m, int n)
          Construct an m-by-n matrix of ones.
static Plot2DPanel plot(Matrix X, Matrix Y)
          Plot the Matrix in a JFrame
static Plot2DPanel plot(java.lang.String title, Matrix X, Matrix Y)
          Plot the Matrix in a JFrame
static Plot3DPanel plot3(Matrix X, Matrix Y, Matrix Z)
          Plot the Matrix in a Window in a JFrame
static Plot3DPanel plot3(java.lang.String title, Matrix X, Matrix Y, Matrix Z)
          Plot the Matrix in a Window in a JFrame
static Matrix plus(Matrix A, Matrix B)
          C = A + B
static Matrix power(Matrix A, double p)
          Element-by-element power
static Matrix power(Matrix A, Matrix B)
          Element-by-element power
static Matrix prod(Matrix A)
          Generate a row matrix, each column contents the product value of the columns.
static Matrix qr_Q(Matrix A)
          QR Decomposition
static Matrix qr_R(Matrix A)
          QR Decomposition
static Matrix rand(int m, int n)
          Generate matrix with random elements
static int rank(Matrix A)
          Matrix rank
static Matrix reshape(Matrix A, int m2, int n2)
          Matrix reshape by Row.
static Matrix resize(Matrix A, int m2, int n2)
          Matrix resize.
static void save(java.lang.String fileName, Matrix A)
          Save the Matrix in an ASCII file.
static void set(Matrix A, int i, int j, double s)
          Set a single element.
static void set(Matrix A, int i0, int i1, int j0, int j1, Matrix X)
          Set a submatrix.
static void setColumn(Matrix A, int c, Matrix B)
          Set a column to an internal one-dimensional Column.
static void setRow(Matrix A, int l, Matrix B)
          Copy an internal one-dimensional array from a row.
static Matrix sin(Matrix A)
          Element-by-element sinus
static int size(Matrix A, int dim)
          Get row dimension.
static Matrix solve(Matrix A, Matrix B)
          Solve A*X = B
static Matrix sort_I(Matrix A)
          Generate a column-permuted matrix, rows are permuted in order to sort the column 'c'
static Matrix sort_Y(Matrix A)
          Generate a column-permuted matrix, rows are permuted in order to sort the column 'c'
static Matrix sqrt(Matrix A)
          Element-by-element inverse
static Matrix sum(Matrix A)
          Generate a row matrix, each column contents the sum value of the columns.
static Matrix svd_S(Matrix A)
          Singular Value Decomposition
static Matrix svd_U(Matrix A)
          Singular Value Decomposition
static Matrix svd_V(Matrix A)
          Singular Value Decomposition
static Matrix t(Matrix A)
          Matrix transpose.
 void tic()
          reset the time counter
static Matrix times(Matrix A, double s)
          Multiply a matrix by a scalar, C = s*A
static Matrix times(Matrix A, Matrix B)
          Linear algebraic matrix multiplication, A * B
 double toc()
          set the time counter
static double trace(Matrix A)
          Matrix trace.
static RandomMatrix triangRnd(int m, int n, double min, double mod, double max)
          Construct an m-by-n matrix of random numbers from an triangular random variable.
static Matrix uminus(Matrix A)
          Unary minus
static RandomMatrix unifRnd(int m, int n, double min, double max)
          Construct an m-by-n matrix of random numbers from an uniform random variable.
static Matrix var(Matrix A)
          Generate a variance matrix.
static Matrix zeros(int m, int n)
          Construct an m-by-n matrix of zeros.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

t

protected long t
Constructor Detail

MatlabSyntax

public MatlabSyntax()
Method Detail

zeros

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

Parameters:
m - Number of rows.
n - Number of colums.
Returns:
An m-by-n matrix of zeros.

ones

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

Parameters:
m - Number of rows.
n - Number of colums.
Returns:
An m-by-n matrix of ones.

matrix

public static Matrix 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.
Returns:
An m-by-n matrix of scalar.

matrix

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

Parameters:
B - Two-dimensional array of doubles.
Returns:
An m-by-n matrix.
Throws:
java.lang.IllegalArgumentException - All rows must have the same length

normRnd

public static RandomMatrix normRnd(double mu,
                                   double sigma,
                                   int m,
                                   int n)
Construct an m-by-n matrix of random numbers from an normal random variable.

Parameters:
m - Number of rows.
n - Number of columns.
mu - Mean of the normal random variable.
sigma - Variance of the normal random variable.
Returns:
A RandomMatrix.

expRnd

public static RandomMatrix expRnd(double mu,
                                  int m,
                                  int n)
Construct an m-by-n matrix of random numbers from an exponantial random variable.

Parameters:
m - Number of rows.
n - Number of columns.
mu - Parmaeter of the exponential random variable.
Returns:
A RandomMatrix.

unifRnd

public static RandomMatrix unifRnd(int m,
                                   int n,
                                   double min,
                                   double max)
Construct an m-by-n matrix of random numbers from an uniform random variable.

Parameters:
m - Number of rows.
n - Number of columns.
min - Min of the uniform random variable.
max - Max of the uniform random variable.
Returns:
A RandomMatrix.

triangRnd

public static RandomMatrix triangRnd(int m,
                                     int n,
                                     double min,
                                     double mod,
                                     double max)
Construct an m-by-n matrix of random numbers from an triangular random variable.

Parameters:
m - Number of rows.
n - Number of columns.
min - Min of the uniform random variable.
mod - Mode of the uniform random variable.
max - Max of the uniform random variable.
Returns:
A RandomMatrix.

rand

public static Matrix rand(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.

eye

public static Matrix eye(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.

inc

public static Matrix inc(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.

inc

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

Parameters:
m - Number of rows.
n - Number of colums.
Returns:
An m-by-n matrix.

merge

public static Matrix merge(Matrix A,
                           Matrix B,
                           int n)
Generate a matrix from other matrix.

Parameters:
A - 1st Matrix to merge.
B - 2nd Matrix to merge.
n - dimension to merge.
Returns:
An m1+m2+...-by-n matrix.

get

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

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

get

public static Matrix get(Matrix A,
                         int i0,
                         int i1,
                         int j0,
                         int j1)
Get a submatrix.

Parameters:
A - Matrix.
i0 - Initial row index
i1 - Final row index
j0 - Initial column index
j1 - Final column index
Returns:
A(i0:i1,j0:j1)

getRow

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

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

getColumn

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

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

size

public static int size(Matrix A,
                       int dim)
Get row dimension.

Parameters:
A - Matrix.
dim - Dimension to return (1 = number of rows, 2 = number of columns).
Returns:
the number of rows or columns.

diag

public static Matrix diag(Matrix A)
Matrix diagonal extraction.

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

diag

public static Matrix diag(Matrix A,
                          int num)
Matrix diagonal extraction.

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

set

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

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

set

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

Parameters:
A - Matrix.
i0 - Initial row index
i1 - Final row index
j0 - Initial column index
j1 - Final column index
X - subMatrix to add

setRow

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

Parameters:
A - Matrix.
l - Row index
B - Row-matrix

setColumn

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

Parameters:
A - Matrix.
c - Column index
B - Column-matrix

resize

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

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

reshape

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

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

t

public static Matrix t(Matrix A)
Matrix transpose.

Parameters:
A - Matrix.
Returns:
A'

norm

public static double norm(Matrix A,
                          java.lang.String n)
Norm

Parameters:
A - Matrix.
n - Norm indice.
Returns:
norm value.

det

public static double det(Matrix A)
Matrix determinant

Parameters:
A - Matrix.
Returns:
determinant

rank

public static int rank(Matrix A)
Matrix rank

Parameters:
A - Matrix.
Returns:
effective numerical rank, obtained from SVD.

cond

public static double cond(Matrix A)
Matrix condition (2 norm)

Parameters:
A - Matrix.
Returns:
ratio of largest to smallest singular value.

trace

public static double trace(Matrix A)
Matrix trace.

Parameters:
A - Matrix.
Returns:
sum of the diagonal elements.

min

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

Parameters:
A - Matrix.
Returns:
An 1-by-n matrix.

max

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

Parameters:
A - Matrix.
Returns:
An 1-by-n matrix.

sum

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

Parameters:
A - Matrix.
Returns:
An 1-by-n matrix.

prod

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

Parameters:
A - Matrix.
Returns:
An 1-by-n matrix.

mean

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

Parameters:
A - Matrix.
Returns:
An 1-by-n matrix.

cov

public static Matrix cov(Matrix A)
Generate a covariance matrix.

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

corrcoef

public static Matrix corrcoef(Matrix A)
Generate a correlation matrix.

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

var

public static Matrix var(Matrix A)
Generate a variance matrix.

Parameters:
A - Matrix.
Returns:
An 1-by-n matrix.

uminus

public static Matrix uminus(Matrix A)
Unary minus

Parameters:
A - Matrix.
Returns:
-A

plus

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

Parameters:
A - Matrix.
B - another matrix
Returns:
A + B

minus

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

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

times

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

Parameters:
A - Matrix.
s - scalar
Returns:
s*A

times

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

Parameters:
A - Matrix.
B - another matrix
Returns:
Matrix product, A * B

divide

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

Parameters:
A - Matrix.
s - scalar
Returns:
A/s

divide

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

Parameters:
A - Matrix.
B - another matrix
Returns:
Matrix division, A / B

solve

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

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

inv

public static Matrix inv(Matrix A)
Matrix inverse or pseudoinverse

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

ebeTimes

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

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

ebeDivide

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

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

cos

public static Matrix cos(Matrix A)
Element-by-element cosinus

Parameters:
A - Matrix.
Returns:
cos.(A)

sin

public static Matrix sin(Matrix A)
Element-by-element sinus

Parameters:
A - Matrix.
Returns:
sin.(A)

exp

public static Matrix exp(Matrix A)
Element-by-element exponential

Parameters:
A - Matrix.
Returns:
exp.(A)

power

public static Matrix power(Matrix A,
                           double p)
Element-by-element power

Parameters:
A - Matrix.
p - double
Returns:
A.^p

power

public static Matrix power(Matrix A,
                           Matrix B)
Element-by-element power

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

log

public static Matrix log(Matrix A)
Element-by-element neperian logarithm

Parameters:
A - Matrix.
Returns:
log.(A)

sqrt

public static Matrix sqrt(Matrix A)
Element-by-element inverse

Parameters:
A - Matrix.
Returns:
sqrt.(A)

abs

public static Matrix abs(Matrix A)
Element-by-element inverse

Parameters:
A - Matrix.
Returns:
|A|

lu_L

public static Matrix lu_L(Matrix A)
LU Decomposition

Parameters:
A - Matrix.
Returns:
L

lu_U

public static Matrix lu_U(Matrix A)
LU Decomposition

Parameters:
A - Matrix.
Returns:
U

lu_P

public static Matrix lu_P(Matrix A)
LU Decomposition

Parameters:
A - Matrix.
Returns:
P

qr_Q

public static Matrix qr_Q(Matrix A)
QR Decomposition

Parameters:
A - Matrix.
Returns:
Q

qr_R

public static Matrix qr_R(Matrix A)
QR Decomposition

Parameters:
A - Matrix.
Returns:
R

chol

public static Matrix chol(Matrix A)
Cholesky Decomposition

Parameters:
A - Matrix.
Returns:
L

svd_S

public static Matrix svd_S(Matrix A)
Singular Value Decomposition

Parameters:
A - Matrix.
Returns:
S

svd_U

public static Matrix svd_U(Matrix A)
Singular Value Decomposition

Parameters:
A - Matrix.
Returns:
U

svd_V

public static Matrix svd_V(Matrix A)
Singular Value Decomposition

Parameters:
A - Matrix.
Returns:
V

eig_V

public static Matrix eig_V(Matrix A)
Eigenvalue Decomposition

Parameters:
A - Matrix.
Returns:
V

eig_D

public static Matrix eig_D(Matrix A)
Eigenvalue Decomposition

Parameters:
A - Matrix.
Returns:
D

sort_I

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

Parameters:
A - Matrix.
Returns:
An int[] Array.

sort_Y

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

Parameters:
A - Matrix.
Returns:
An m-by-n matrix.

find

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

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

disp

public static void disp(Matrix A)
Print the Matrix in the Command Line.

Parameters:
A - Matrix.

disp

public static void disp(java.lang.String text)
Print the Matrix in the Command Line.

Parameters:
text - String.

save

public static void save(java.lang.String fileName,
                        Matrix A)
Save the Matrix in an ASCII file.

Parameters:
A - Matrix.
fileName - filename to save in.

load

public static Matrix load(java.lang.String fileName)
Load the Matrix from an ASCII file.

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

hist

public static Plot2DPanel hist(Matrix X,
                               int n)
Plot the Matrix in a JFrame

Parameters:
X - Matrix.
n - Number of slices.
Returns:
A MatrixPlot2DPanel (extends a Swing JPanel)

hist

public static Plot2DPanel hist(java.lang.String title,
                               Matrix X,
                               int n)
Plot the Matrix in a JFrame

Parameters:
X - Matrix.
n - Number of slices.
title - Title of the JFrame.
Returns:
A MatrixPlot2DPanel (extends a Swing JPanel)

plot

public static Plot2DPanel plot(Matrix X,
                               Matrix Y)
Plot the Matrix in a JFrame

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

plot

public static Plot2DPanel plot(java.lang.String title,
                               Matrix X,
                               Matrix Y)
Plot the Matrix in a JFrame

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

plot3

public static Plot3DPanel plot3(Matrix X,
                                Matrix Y,
                                Matrix Z)
Plot the Matrix in a Window in a JFrame

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

plot3

public static Plot3DPanel plot3(java.lang.String title,
                                Matrix X,
                                Matrix Y,
                                Matrix Z)
Plot the Matrix in a Window in a JFrame

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

tic

public void tic()
reset the time counter


toc

public double toc()
set the time counter

Returns:
time etween tic and toc