RdcPanda
Class Matrix

java.lang.Object
  extended by RdcPanda.Matrix
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable

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

This class is modified from the Jama numeric package. Written by Lincong Wang (2001-2005).

See Also:
Serialized Form

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
 java.lang.Object clone()
          Clone the Matrix object.
 Matrix copy()
          Make a deep copy of a matrix.
static double det(double[][] a)
          Generate identity matrix.
 Matrix eulerMat(double alpha, double beta, double gamma)
          A method for generating an euler Matrix from three Euler angles.
 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.
 int getRowDimension()
          Get row dimension.
static Matrix identity(int m, int n)
          Generate identity matrix.
 Matrix minus(Matrix B)
          C = A - B.
 double norm1()
          One norm.
 Matrix plus(Matrix B)
          C = A + B.
 void print(int w, int d)
          Print the matrix to stdout.
 void print(java.text.NumberFormat format, int width)
          Prints the.
 void print(java.io.PrintWriter output, int w, int d)
          Print the matrix to the output stream.
 void print(java.io.PrintWriter output, java.text.NumberFormat format, int width)
          Print the matrix to the output stream.
 Matrix rotationMat(double theta, java.lang.String axis)
          make a 3x3 rotation matrix with a rotation angle theta and along an axis Please note that only axis only take +/-x, y, z A method by Lincong Wang.
 void set(int i, int j, double s)
          Set a single element.
 SingularValueDecomposition svd()
          Singular Value Decomposition.
 Matrix times(double s)
          Multiply a matrix by a scalar, C = s*A.
 double[] times(double[] B)
          Times.
 Matrix times(Matrix B)
          Linear algebraic matrix multiplication, A * B.
 double trace()
          Trace.
 Matrix transpose()
          Matrix transpose.
 Matrix uminus()
          -a of every elements.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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:
java.lang.IllegalArgumentException - All rows must have the same length

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

copy

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

Returns:
the matrix

rotationMat

public Matrix rotationMat(double theta,
                          java.lang.String axis)
make a 3x3 rotation matrix with a rotation angle theta and along an axis Please note that only axis only take +/-x, y, z A method by Lincong Wang.

Parameters:
theta - the rotation angle
axis - the axis along which the rotation is made
Returns:
the 3x3 matrix

eulerMat

public Matrix eulerMat(double alpha,
                       double beta,
                       double gamma)
A method for generating an euler Matrix from three Euler angles. The convention, refer to the Method of methemetical physics by CalTec guys

Parameters:
alpha - the alpha angle
beta - the beta angle
gamma - the gamma angle
Returns:
an Euler matrix Wrote by Lincong

clone

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

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

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

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

transpose

public Matrix transpose()
Matrix transpose.

Returns:
A'

uminus

public Matrix uminus()
-a of every elements.

Returns:
the matrix

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.

times

public double[] times(double[] B)
Times.

Parameters:
B - the b
Returns:
the double[]

norm1

public double norm1()
One norm.

Returns:
maximum column sum.

trace

public double trace()
Trace.

Returns:
the double

print

public void print(int w,
                  int d)
Print the matrix to stdout. Line the elements up in columns with a Fortran-like 'Fw.d' style format.

Parameters:
w - Column width.
d - Number of digits after the decimal.

print

public void print(java.io.PrintWriter output,
                  int w,
                  int d)
Print the matrix to the output stream. Line the elements up in columns with a Fortran-like 'Fw.d' style format.

Parameters:
output - Output stream.
w - Column width.
d - Number of digits after the decimal.

print

public void print(java.text.NumberFormat format,
                  int width)
Prints the.

Parameters:
format - the format
width - the width

print

public void print(java.io.PrintWriter output,
                  java.text.NumberFormat format,
                  int width)
Print the matrix to the output stream. Line the elements up in columns. Use the format object, and right justify within columns of width characters. Note that is the matrix is to be read back in, you probably will want to use a NumberFormat that is set to US Locale.

Parameters:
output - the output stream.
format - A formatting object to format the matrix elements
width - Column width.
See Also:
DecimalFormat.setDecimalFormatSymbols(java.text.DecimalFormatSymbols)

svd

public SingularValueDecomposition svd()
Singular Value Decomposition.

Returns:
SingularValueDecomposition
See Also:
SingularValueDecomposition

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.

det

public static double det(double[][] a)
Generate identity matrix.

Parameters:
a - the a
Returns:
An m-by-n matrix with ones on the diagonal and zeros elsewhere.