Skip to content
ErikHaag edited this page Dec 30, 2022 · 18 revisions

Matrix

Constructor

Columns

the number of columns this matrix will have.

...indicies

The values in the matrix in reading order. can be Numbers, BigInts, or Rationals. They all get converted to Rationals.

let A = new Matrix(2,1,2,3,4);

If indices is the string "identity", creates an identity matrix of given size.

Methods

toLatex

Returns a latex string representing the Matrix.

let A = new Matrix(2,1, 2, new Rational(2n,3n), 10);
console.log(A.toLatex()); // "\begin{bmatrix}1 & 2 // \frac{2}{3} & 10 \end{bmatrix}"

A =

The latex of a Matrix is not easy to follow, so I'll use codecogs Latex renderer to show matrices after the code runs. Unfortunately the renderer doesn't allow me to color the background, so you might want to change to light mode as black on grey isn't the easiest to read.

clone

returns a copy of the matrix so you can manipulate it without affecting the original.

let A = new Matrix(2,1,2,3,4);
let copy = A.clone();
copy.gaussianElimination();

A =

copy =

swapRows

swaps 2 rows of a matrix, where the top row is row 0.

 A = new matrix(2,1,2,3,4,5,6);
 A.swapRows(0,2);

A =

addRow

Adds a multiple of one row to another.

let A = new Matrix(3,1,2,3,4,5,6);
let B = A.clone();
A.addRow(0,1,new Rational(-1n));
B.addRow(0,1);

A =

B =

scaleRow

Multiplies a row by a Rational.

let A = new Matrix(2,1,2,3,4);
A.scaleRow(0,new Rational(3n));

A =

scale

Multiplies all the indices by a Rational.

let A = new Matrix(2,1,2,3,4);
A.scale(new Rational(3n));

A =

transpose

Returns a transposed copy of this.

let A = new Matrix(1,1,2,3,4);
let transposedA = A.transpose();

A =

transposedA =

isSquare

Returns true if this is a square matrix.

let square = new Matrix(3,1,2,3,4,5,6,7,8,9);
let nonsquare = new Marix(2,1,2,3,4,5,6);
console.log(square.isSquare()); // true
console.log(nonsquare.isSquare()); // false

gaussianElimination

Does gaussian elimination on this, row reducing the matrix.

determinate

returns the determinate of this

Clone this wiki locally