public class GIMatrix extends Object
Please note that although in most books matrix elements' indexes take values between [1..n] I chose not to disturb Java language way of calling indexes; so the indexes used here take values between [0..n-1] instead.
Constructor and Description |
---|
GIMatrix(double[][] array)
Class constructor.
|
GIMatrix(GIMatrix matrix)
Class constructor.
|
GIMatrix(GIMatrix[][] table)
Class constructor.
|
GIMatrix(int[][] array)
Class constructor.
|
GIMatrix(int line,
int col)
Class constructor.
|
Modifier and Type | Method and Description |
---|---|
GIMatrix |
add(GIMatrix b)
Addition from two matrices.
|
GIMatrix |
addLine(int i,
int j,
double c)
Returns the resulting matrix of an elementary linear operation that consists of adding one line,
multiplied by some constant factor, to another line.
|
double |
determinant()
Returns the determinant of this matrix.
|
GIMatrix |
diagonal()
Returns a matrix containing all of the diagonal elements of this matrix and zero (0) everywhere
else.
|
boolean |
equals(GIMatrix matrix)
Verifies if two given matrix are equal or not.
|
GIMatrix |
GaussJordan()
Gauss-Jordan algorithm.
|
double[][] |
getArrayValue()
Returns the internal representation of the matrix, that is an array of double objects.
|
GIMatrix |
getColumn(int j)
Returns the column-matrix at the given line index.
|
GIMatrix |
getLine(int i)
Returns the line-matrix at the given line index.
|
double |
getValueAt(int i,
int j)
Returns the value of the given element.
|
int |
height()
Returns the number of lines of the matrix.
|
static GIMatrix |
identity(int n)
Returns the identity matrix.
|
GIMatrix |
inverse()
Returns the transpose of this matrix.
|
GIMatrix |
invertLine(int i,
int j)
Returns the resulting matrix of an elementary linear operation that consists of inverting two lines.
|
boolean |
isAntisymmetric()
Verifies if the matrix is antisymmetric, that is if the matrix is equal to the opposite of
it's transpose.
|
boolean |
isDiagonal()
Verifies whether or not the matrix is diagonal.
|
boolean |
isInvertible()
Verifies if the matrix is invertible or not by asking for its determinant.
|
boolean |
isSquare()
Verifies if the matrix is square, that is if it has an equal number of lines and columns.
|
boolean |
isSymmetric()
Verifies if the matrix is symmetric, that is if the matrix is equal to it's transpose.
|
boolean |
isTriangularInferior()
Verifies if the matrix is triangular inferior or not.
|
boolean |
isTriangularSuperior()
Verifies if the matrix is triangular superior or not.
|
GIMatrix |
multiply(double c)
Returns the result of the scalar multiplication of the matrix, that is the multiplication of every
of its elements by a given number.
|
GIMatrix |
multiply(GIMatrix matrix)
Returns the result of the matrix multiplication of this matrix by another one.
|
GIMatrix |
multiplyLine(int i,
double c)
Returns the resulting matrix of an elementary linear operation that consists of multiplying a
single line of the matrix by a constant.
|
void |
setArrayValue(double[][] array)
Resets the value of the matrix to the given array of double numbers.
|
void |
setColumn(int j,
GIMatrix column)
Sets the column of the matrix at the specified index to a new value.
|
void |
setLine(int i,
GIMatrix line)
Sets the line of the matrix at the specified index to a new value.
|
void |
setValueAt(int i,
int j,
double element)
Sets the value of the element at the given index.
|
double |
trace()
Returns the trace of this matrix, that is the sum of the elements of its diagonal.
|
GIMatrix |
transpose()
Returns the transpose of this matrix.
|
int |
width()
Returns the number of columns of the matrix.
|
static GIMatrix |
zero(int m,
int n)
Returns a null matrix (with zeros everywhere) of given dimensions.
|
public GIMatrix(int[][] array)
array
- an array of integer (first index is the line, second is the column)public GIMatrix(double[][] array) throws BadMatrixFormatException
array
- an array of double objects (first index is the line, second is the column)BadMatrixFormatException
- in case the given array is unproper to construct a matrixpublic GIMatrix(int line, int col)
line
- number of linescol
- number of columnspublic GIMatrix(GIMatrix matrix)
matrix
- a Matrix objectpublic GIMatrix(GIMatrix[][] table) throws BadMatrixFormatException
table
- an array of matricesBadMatrixFormatException
- if the table is not properly instantiatedpublic int height()
public int width()
public double[][] getArrayValue()
public void setArrayValue(double[][] array) throws BadMatrixFormatException
array
- an array of double objects (first index is the line, second is the column)BadMatrixFormatException
- in case the given array is unproper to construct a matrixpublic double getValueAt(int i, int j) throws IndexOutOfBoundsException
i
- the line numberj
- the column numberIndexOutOfBoundsException
- if the given index is out of the matrix's rangepublic void setValueAt(int i, int j, double element) throws IndexOutOfBoundsException
i
- the line numberj
- the column numberelement
- the double to place at the given index in the MatrixIndexOutOfBoundsException
- if the given index is out of the matrix's rangepublic GIMatrix getLine(int i) throws IndexOutOfBoundsException
i
- the line numberIndexOutOfBoundsException
- if the given index is out of the matrix's rangepublic GIMatrix getColumn(int j) throws IndexOutOfBoundsException
j
- the column numberIndexOutOfBoundsException
- if the given index is out of the matrix's rangepublic void setLine(int i, GIMatrix line) throws IndexOutOfBoundsException, BadMatrixFormatException
i
- the line numberline
- the line to be placed at the specified indexIndexOutOfBoundsException
- if the given index is out of the matrix's rangeBadMatrixFormatException
- in case the given Matrix is unproper to replace a line of this Matrixpublic void setColumn(int j, GIMatrix column) throws IndexOutOfBoundsException, BadMatrixFormatException
j
- the column numbercolumn
- the column to be placed at the specified indexIndexOutOfBoundsException
- if the given index is out of the matrix's rangeBadMatrixFormatException
- in case the given Matrix is unproper to replace a column of this Matrixpublic static GIMatrix identity(int n)
n
- the matrix's dimension (identity matrix is a square matrix)public static GIMatrix zero(int m, int n)
m
- number of linesn
- number of columnspublic boolean equals(GIMatrix matrix) throws BadMatrixFormatException
matrix
- the Matrix object to be compared toBadMatrixFormatException
- if the given matrix doesn't have the same dimensions as this onepublic boolean isSquare()
public boolean isSymmetric() throws BadMatrixFormatException
BadMatrixFormatException
- if the matrix is not squarepublic boolean isAntisymmetric() throws BadMatrixFormatException
BadMatrixFormatException
- if the matrix is not squarepublic boolean isTriangularSuperior() throws BadMatrixFormatException
BadMatrixFormatException
- if the matrix is not squarepublic boolean isTriangularInferior() throws BadMatrixFormatException
BadMatrixFormatException
- if the matrix is not squarepublic boolean isDiagonal() throws BadMatrixFormatException
BadMatrixFormatException
- if the matrix is not squarepublic boolean isInvertible() throws BadMatrixFormatException
BadMatrixFormatException
- if the matrix is not squarepublic GIMatrix inverse() throws MatrixNotInvertibleException
MatrixNotInvertibleException
- if the matrix is not squarepublic GIMatrix GaussJordan()
public GIMatrix transpose() throws BadMatrixFormatException
BadMatrixFormatException
- if the matrix is not squarepublic GIMatrix diagonal() throws BadMatrixFormatException
BadMatrixFormatException
- if the matrix is not squarepublic GIMatrix multiplyLine(int i, double c) throws IndexOutOfBoundsException
i
- the line numberc
- the double constant that multiplies the lineIndexOutOfBoundsException
- if the given index is out of the matrix's rangepublic GIMatrix invertLine(int i, int j) throws IndexOutOfBoundsException
i
- the first line numberj
- the second line numberIndexOutOfBoundsException
- if the given index is out of the matrix's rangepublic GIMatrix addLine(int i, int j, double c) throws IndexOutOfBoundsException
i
- the first line numberj
- the second line number (to be added to the first)c
- the double constant that multiplies the first lineIndexOutOfBoundsException
- if the given index is out of the matrix's rangepublic GIMatrix multiply(double c)
c
- the constant by which the matrix is multipliedpublic GIMatrix multiply(GIMatrix matrix) throws BadMatrixFormatException
matrix
- the matrix following this one in the matrix multiplicationBadMatrixFormatException
- if the matrix passed in arguments has wrong dimensionspublic double determinant() throws BadMatrixFormatException
BadMatrixFormatException
- if the matrix is not squarepublic double trace() throws BadMatrixFormatException
BadMatrixFormatException
- if the matrix is not squareCopyright © 2022. All rights reserved.