Skip to content

damianc/math-matrix

Folders and files

NameName
Last commit message
Last commit date

Latest commit

8bb7ba9 · Nov 8, 2024

History

69 Commits
Nov 8, 2024
Nov 8, 2024
Nov 6, 2024
Nov 6, 2024

Repository files navigation

Math.matrix

Support for matrices in JavaScript.

const M = [
  [1,2],
  [3,4]
];

const determinant = Math.matrix.det(M);
// -2

Functions

Operations

  • add(A,B) - performs addition of matrices A and B
  • sub(A,B) - performs subtraction of matrices A and B
  • mul(A,B) - performs multiplication of matrices A and B
  • mulByScalar(M,k) - performs multiplication of a matrix M by a scalar value k
  • transpose(M) - performs transposition of a matrix M

Properties

  • det(M) - returns the determinant of a matrix M
  • order(M) - returns the order of a matrix M
  • trace(M) - returns the trace of a matrix M
  • cofactor(M,i,j) - returns a cofactor for element a i j in a matrix M
  • cofactorMatrix(M) - returns the cofactor matrix for a matrix M
  • adjointMatrix(M) - returns the adjoint matrix for a matrix M
  • inverseMatrix(M) - returns the inverse matrix for a matrix M

Minors

  • minorMatrix(M) - returns the minor matrix for a matrix M
  • minor(M,i,j) - returns a minor for element a i j in a matrix M
  • minorize(M,i,j) - returns a matrix M with i-th row and j-th column removed

Creating a Matrix

  • initNullMatrix(m,n) - creates a null matrix of order m × n
  • initScalarMatrix(n,k=1) - creates a scalar matrix of order n × n with a scalar value k on the diagonal
  • initIdentityMatrix(n) - creates an identity matrix of order n × n

Altering a Matrix

  • removeRow(M,i) - returns a matrix M with i-th row removed
  • removeColumn(M,j) - returns a matrix M with j-th column removed
  • insertRow(M,i,row) - returns a matrix M with additional row inserted just before i-th row
  • insertColumn(M,j,column) - returns a matrix M with additional column inserted just before j-th column
  • swapRows(M,m,n) - returns a matrix M with m-th and n-th rows swapped
  • swapColumns(M,m,n) - returns a matrix M with m-th and n-th columns swapped
  • getRow(M,i) - returns i-th row of a matrix M
  • getColumn(M,j) - returns j-th column of a matrix M

Testing

  • isSquare(M) - checks if a matrix M is the square matrix
  • isEqual(A,B) - checks if a matrix A is equal to a matrix B

About

Support for matrices in JavaScript.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published