Skip to content

3koo2/Matrix

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Matrix Class Documentation

The Matrix class represents a mathematical matrix and provides various methods for matrix operations such as addition, multiplication, transposition, and determinant calculation.

Constructors

Matrix(double[][] matrixElements)

Creates a matrix from a two-dimensional array of doubles. Blank elements are replaced by zeros.

Matrix(int rows, int columns, double[] elements)

Creates a matrix with the specified number of rows and columns, initializing it with the given elements. Blank elements are replaced by zeros.

Matrix(int rows, int columns, double element)

Creates a matrix with the specified number of rows and columns, initializing all elements to the given value.

Methods

public String toString()

Returns a string representation of the matrix, formatted for readability.

public double get(int i, int j)

Returns the element of the matrix at the specified row and column. Indices start at 1, as in mathematics.

public void set(int i, int j, double element)

Sets the element of the matrix at the specified row and column to the given value. Indices start at 1.

public Matrix submatrix(int i, int j)

Returns a submatrix excluding the specified row and column.

public double determinant() throws SquareMatrixExpected

Returns the determinant of the matrix. Throws SquareMatrixExpected if the matrix is not square.

public Matrix copy()

Returns a copy of the matrix.

public Matrix transpose()

Returns the transpose of the matrix (switches rows and columns).

public Matrix det_matrix() throws SquareMatrixExpected

Returns the determinant matrix of this matrix (determinant of submatrix per element, alternating signs). Throws SquareMatrixExpected if the matrix is not square.

public Matrix inverse() throws SquareMatrixExpected

Returns the multiplicative inverse of this matrix. Throws SquareMatrixExpected if the matrix is not square.

Static Methods

public static Matrix zero(int rows, int columns)

Returns the zero matrix of the specified order.

public static Matrix identity(int size)

Returns the identity matrix for a given order.

Static Operations

public static Matrix add(Matrix a, Matrix b)

Returns the sum of two matrices.

public static Matrix multiply(Matrix a, Matrix b)

Returns the product of two matrices.

public static Matrix multiply(Matrix a, double b)

Returns the product of a matrix and a scalar.

public static Matrix multiply(double a, Matrix b)

Returns the product of a scalar and a matrix.

The overview of these methods was generated by AI. I have checked it, and it seems to be accurate. Use at your own risk.

About

Java Matrix Library

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages