# Class Matrix

java.lang.Object
javajs.util.Matrix

All Implemented Interfaces:
  `Cloneable`

public class Matrix extends Object implements Cloneable
streamlined and refined for Jmol by Bob Hanson from http://math.nist.gov/javanumerics/jama/ Jama = Java Matrix class.

Version:
  5 August 1998
Author:
  The MathWorks, Inc. and the National Institute of Standards and Technology.

## Field Summary

Fields
Modifier and Type
Field
Description
`double[][]`
`a`
`protected int`
`m`
`protected int`
`n`

## Constructor Summary

Constructors
Constructor
Description
`Matrix(double[][] a, int m, int n)`
Construct a matrix quickly without checking arguments.

## Method Summary

Modifier and Type
Method
Description
`Matrix`
`add(Matrix b)`
add two matrices
`Object`
`clone()`
Clone the Matrix object.
`Matrix`
`copy()`
Make a deep copy of a matrix
`double[][]`
`getArray()`
Access the internal two-dimensional array.
`double[][]`
`getArrayCopy()`
Copy the internal two-dimensional array.
`int`
`getColumnDimension()`
Get column dimension.
`Matrix`
`getMatrixSelected(int[] r, int n)`
Get a submatrix for a give number of columns and selected row set.
`Matrix`
`getRotation()`
similarly to M3/M4 standard rotation/translation matrix we set a rotationTranslation matrix to be: [ nxn rot nx1 trans 1xn 0 1x1 1 ]
`int`
`getRowDimension()`
Get row dimension.
`Matrix`
`getSubmatrix(int i0, int j0, int nrows, int ncols)`
Get a submatrix.
`Matrix`
`getTranslation()`
`static Matrix`
`identity(int m, int n)`
Generate identity matrix
`Matrix`
`inverse()`
Matrix inverse or pseudoinverse
`Matrix`
`mul(Matrix b)`
Linear algebraic matrix multiplication, A * B
`static Matrix`
`newT(T3 r, boolean asColumn)`
`Matrix`
`scaleAdd(Matrix b, double scale)`
X = A + B*scale
`Matrix`
`sub(Matrix b)`
subtract two matrices
`String`
`toString()`
`double`
`trace()`
Matrix trace.
`Matrix`
`transpose()`
Matrix transpose.

### Methods inherited from class Object

`equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

## Field Details

### a

public double[][] a

### m

protected int m

### n

protected int n

## Constructor Details

### Matrix

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

Parameters:
  `a` - Two-dimensional array of doubles or null
  `m` - Number of rows.
  `n` - Number of colums.

## Method Details

### 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.

### 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.

### copy

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

Returns:
  copy

### clone

public Object clone()
Clone the Matrix object.

Overrides:
  `clone` in class `Object`

### getSubmatrix

public Matrix getSubmatrix(int i0, int j0, int nrows, int ncols)
Get a submatrix.

Parameters:
  `i0` - Initial row index
  `j0` - Initial column index
  `nrows` - Number of rows
  `ncols` - Number of columns
Returns:
  submatrix

### getMatrixSelected

public Matrix getMatrixSelected(int[] r, int n)
Get a submatrix for a give number of columns and selected row set.

Parameters:
  `r` - Array of row indices.
  `n` - number of rows
Returns:
  submatrix

### transpose

public Matrix transpose()
Matrix transpose.

Returns:
  A'

### add

public Matrix add(Matrix b)
add two matrices

Parameters:
  `b` -
Returns:
  new Matrix this + b

### sub

public Matrix sub(Matrix b)
subtract two matrices

Parameters:
  `b` -
Returns:
  new Matrix this - b

### scaleAdd

public Matrix scaleAdd(Matrix b, double scale)
X = A + B*scale

Parameters:
  `b` -
  `scale` -
Returns:
  X

### mul

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

Parameters:
  `b` - another matrix
Returns:
  Matrix product, A * B or null for wrong dimension

### inverse

public Matrix inverse()
Matrix inverse or pseudoinverse

Returns:
  inverse (m == n) or pseudoinverse (m != n)

### trace

public double trace()
Matrix trace.

Returns:
  sum of the diagonal elements.

### identity

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

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

### getRotation

public Matrix getRotation()
similarly to M3/M4 standard rotation/translation matrix we set a rotationTranslation matrix to be: [ nxn rot nx1 trans 1xn 0 1x1 1 ]

Returns:
  rotation matrix

### getTranslation

public Matrix getTranslation()

### newT

public static Matrix newT(T3 r, boolean asColumn)

### toString

public String toString()

Overrides:
  `toString` in class `Object`