## Class Matrix

• ```public class Matrix
extends Object```
This class contains a matrix.
Author:
Stephan Michels <stephan@vern.chem.tu-berlin.de>
Source code:
main
Belongs to CDK module:
qm
Created on:
2001-06-07
• ### Field Summary

Fields
Modifier and Type Field Description
`int` `columns`
the number of columns of this matrix
`double[][]` `matrix`
the content of this matrix
`int` `rows`
the number of rows of this matrix
• ### Constructor Summary

Constructors
Constructor Description
`Matrix​(double[][] array)`
Creates a Matrix with content of an array.
```Matrix​(int rows, int columns)```
Creates a new Matrix.
• ### Method Summary

All Methods
Modifier and Type Method Description
`Matrix` `add​(Matrix b)`
`double` `contraction()`
`Matrix` `diagonalize​(int maxNumRot)`
Diagonalize this matrix with the Jacobi algorithm.
`Matrix` `duplicate()`
Copies a matrix.
`static Vector` ```elimination​(Matrix matrix, Vector vector)```
Solves a linear equation system with Gauss elimination.
`int` `getColumns()`
Returns the number of columns.
`int` `getRows()`
Returns the number of rows.
`Vector` `getVectorFromColumn​(int index)`
Creates a Vector with the content of a column from this Matrix.
`Vector` `getVectorFromDiagonal()`
Creates a Vector with the content of the diagonal elements from this Matrix.
`Vector` `getVectorFromRow​(int index)`
Creates a Vector with the content of a row from this Matrix.
`Matrix` `mul​(double a)`
Multiplies a scalar with this Matrix.
`Matrix` `mul​(Matrix b)`
Multiplies this Matrix with another one.
`Vector` `mul​(Vector a)`
Multiplies a Vector with this Matrix.
`Matrix` `normalize​(Matrix S)`
Normalizes the vectors of this matrix.
`Matrix` `orthonormalize​(Matrix S)`
Orthonormalize the vectors of this matrix by Gram-Schmidt.
`Matrix` `similar​(Matrix U)`
Similar transformation Ut * M * U
`Matrix` `sub​(Matrix b)`
Subtracts from two matrices.
`String` `toString()`
Return a matrix as a String.
`Matrix` `transpose()`
Transposes a matrix.
• ### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`
• ### Field Detail

• #### matrix

`public final double[][] matrix`
the content of this matrix
• #### rows

`public final int rows`
the number of rows of this matrix
• #### columns

`public int columns`
the number of columns of this matrix
• ### Constructor Detail

• #### Matrix

```public Matrix​(int rows,
int columns)```
Creates a new Matrix.
• #### Matrix

`public Matrix​(double[][] array)`
Creates a Matrix with content of an array.
• ### Method Detail

• #### getRows

`public int getRows()`
Returns the number of rows.
• #### getColumns

`public int getColumns()`
Returns the number of columns.
• #### getVectorFromRow

`public Vector getVectorFromRow​(int index)`
Creates a Vector with the content of a row from this Matrix.
• #### getVectorFromColumn

`public Vector getVectorFromColumn​(int index)`
Creates a Vector with the content of a column from this Matrix.
• #### getVectorFromDiagonal

`public Vector getVectorFromDiagonal()`
Creates a Vector with the content of the diagonal elements from this Matrix.

`public Matrix add​(Matrix b)`
• #### sub

`public Matrix sub​(Matrix b)`
Subtracts from two matrices.
• #### mul

`public Matrix mul​(Matrix b)`
Multiplies this Matrix with another one.
• #### mul

`public Vector mul​(Vector a)`
Multiplies a Vector with this Matrix.
• #### mul

`public Matrix mul​(double a)`
Multiplies a scalar with this Matrix.
• #### duplicate

`public Matrix duplicate()`
Copies a matrix.
• #### transpose

`public Matrix transpose()`
Transposes a matrix.
• #### similar

`public Matrix similar​(Matrix U)`
Similar transformation Ut * M * U
• #### contraction

`public double contraction()`
• #### toString

`public String toString()`
Return a matrix as a String.
Overrides:
`toString` in class `Object`
• #### diagonalize

`public Matrix diagonalize​(int maxNumRot)`
Diagonalize this matrix with the Jacobi algorithm.
Parameters:
`maxNumRot` - Count of max. rotations
Returns:
Matrix m, with m^t * this * m = diagonal
Keywords:
Jacobi algorithm, diagonalization
• #### elimination

```public static Vector elimination​(Matrix matrix,
Vector vector)```
Solves a linear equation system with Gauss elimination.
Keywords:
Gauss elimination
• #### orthonormalize

`public Matrix orthonormalize​(Matrix S)`
Orthonormalize the vectors of this matrix by Gram-Schmidt.
Keywords:
orthonormalization, Gram-Schmidt algorithm
• #### normalize

`public Matrix normalize​(Matrix S)`
Normalizes the vectors of this matrix.