SuanShu, a Java numerical and statistical library

com.numericalmethod.suanshu.matrix.doubles.operation
Class ElementaryOperation

java.lang.Object
  extended by com.numericalmethod.suanshu.matrix.doubles.operation.ElementaryOperation

public class ElementaryOperation
extends java.lang.Object

There are three elementary row operations which are equivalent to left multiplying an elementary matrix. They are row switching, row multiplication, and row addition.

By applying these operations to an identity matrix, I, the resultant matrix, T, is a transformation matrix, such that left multiplying T to a matrix A, i.e., T %*% A, is equivalent to applying the same sequence of operations to A.

Similiarly, the three elementary column operations are: column switching, column multiplication, and column addition. Column operations correspond to right multiplying a transformation matrix.

See Also:
Wikipedia: Elementary matrix

Constructor Summary
ElementaryOperation(int dim)
          Construct an instance of ElementaryOperation of dimension dim.
ElementaryOperation(int nRows, int nCols)
          Construct an instance of ElementaryOperation of dimension nRows x nCols.
ElementaryOperation(Matrix T)
          Get a copy of a transformation matrix.
 
Method Summary
 void addColumn(int col1, int col2, double scale)
          Column addition: A[col1, ] = A[col1, ] + scale * A[col2, ]
 void addRow(int row1, int row2, double scale)
          Row addition: A[row1, ] = A[row1, ] + scale * A[row2, ]
 double get(int row, int col)
          Get the matrix element at [row, col].
 void scaleColumn(int col, double scale)
          Scale a column: A[col, ] = scale * A[col, ]
 void scaleRow(int row, double scale)
          Scale a row: A[row, ] = scale * A[row, ]
 void swapColumn(int col1, int col2)
          Swap columns: A[col1, ] = A[col2, ] A[col2, ] = A[col1, ]
 void swapRow(int row1, int row2)
          Swap rows: A[row1, ] = A[row2, ] A[row2, ] = A[row1, ]
 Matrix T()
          Get a copy of the transformation matrix T.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ElementaryOperation

public ElementaryOperation(int nRows,
                           int nCols)
Construct an instance of ElementaryOperation of dimension nRows x nCols.

The initial transformation matrix T is an identity matrix, if it is square. Otherwise, the rightmost columns are padded with zeros.

Parameters:
nRows - number of rows of T
nCols - number of columns of T

ElementaryOperation

public ElementaryOperation(int dim)
Construct an instance of ElementaryOperation of dimension dim.

The initial transformation matrix T is an identity matrix.

Parameters:
dim - dimension of T

ElementaryOperation

public ElementaryOperation(Matrix T)
Get a copy of a transformation matrix.

Parameters:
T - a copy of the transformation matrix
Method Detail

get

public double get(int row,
                  int col)
Get the matrix element at [row, col].

Parameters:
row - row index
col - column index
Returns:
T[row, col]

T

public Matrix T()
Get a copy of the transformation matrix T.

Returns:
a copy of T

swapRow

public void swapRow(int row1,
                    int row2)
Swap rows:
 A[row1, ] = A[row2, ]
 A[row2, ] = A[row1, ]
 

Parameters:
row1 - the row to become row2
row2 - the row to become row1

scaleRow

public void scaleRow(int row,
                     double scale)
Scale a row:
A[row, ] = scale * A[row, ]

Parameters:
row - the row to be scaled
scale - the scaling factor

addRow

public void addRow(int row1,
                   int row2,
                   double scale)
Row addition:
A[row1, ] = A[row1, ] + scale * A[row2, ]

Parameters:
row1 - addend; the row to add to; the row changes afterward
row2 - the row to add with
scale - the scaling factor for row2

swapColumn

public void swapColumn(int col1,
                       int col2)
Swap columns:
 A[col1, ] = A[col2, ]
 A[col2, ] = A[col1, ]
 

Parameters:
col1 - becoming col2
col2 - becoming col1

scaleColumn

public void scaleColumn(int col,
                        double scale)
Scale a column:
A[col, ] = scale * A[col, ]

Parameters:
col - the column to be scaled
scale - the scaling factor

addColumn

public void addColumn(int col1,
                      int col2,
                      double scale)
Column addition:
A[col1, ] = A[col1, ] + scale * A[col2, ]

Parameters:
col1 - addend; the column to add to; the column changes afterward
col2 - the column to add with
scale - the scaling factor for col2

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

SuanShu, a Java numerical and statistical library

Copyright © 2011 Numerical Method Inc. Ltd. All Rights Reserved.