1.0.5 • Published 10 months ago

matrixlab.ts v1.0.5

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

ladunjexa GitHub license Deploy
  Status npm version matrixlab Maintained PRs Welcome

matrixlab.ts is a matrix math library written in TypeScript with no dependencies.

How to install it

Using npm

npm install --save matrixlab.ts

Or add the unpkg cdn link to your html

<script src="https://unpkg.com/matrixlab.ts">

Usage

Import the module, from TypeScript or ES6 JavaScript

import { Matrix } from "matrixlab.ts";

The library is built as an ECMAScript module (.mjs file), but it also exports a UMD version if needed.

Then use the methods as you want

const m1 = new Matrix(2, 2, [
  [1, 2],
  [3, 4],
]);
m1.multiply(2);
// ==>
// Matrix {
//   rows: 2,
//   cols: 2,
//   values: [ [ 2, 4 ], [ 6, 8 ] ]
// }
m1.set(0, 0, 5);
m1.at(0, 0); // ==> 5

Documentation

Constructor

constructordescription
Matrix()Creates a 1x1 matrix with zero value
Matrix(n)Creates an nxn matrix with zeroes
Matrix(data)Creates a matrix from the specified 2D array
Matrix(rows, columns)Creates an mxn matrix with zeroes
Matrix(rows, columns, data)Creates a matrix from the specified 2D array (with the specified dimensions)
Matrix(n, data)Creates an nxn matrix from the specified 2D array

Accessors and Mutators

memberdescription
rowsRetrieves the number of rows in the matrix
columnsRetrieves the number of columns in the matrix
dataGets the data of the matrix

Public Methods

methoddescription
shapeGets the shape of the matrix
sizeGets the size of the matrix
set(row, column, value)Sets the value at the specified row and column indices
at(row, column)Retrieves the value at the specified row and column indices
reset()Sets all matrix values to 0
clone()Returns a new instance of the matrix
setData(array)Copies data from the specified 2D array to the matrix
add(matrix)Adds the specified matrix to the current matrix
subtract(matrix)Subtracts the specified matrix from the current matrix
multiply(Matrix / Scalar)Multiplies the current matrix by the specified matrix or scalar
modulo(modulus)Modulos the current matrix by the specified modulus
isSquare()Checks if the matrix is square
isSymmetric()Checks if the matrix is symmetric
isIdentity()Checks if the matrix is identity
setShape(array)Sets the shape of the matrix
setAsIdentity()Sets the matrix as an identity matrix
transpose()Transposes the matrix
determinant()Calculates the determinant of the matrix
getCofactor(row, column)Calculates the cofactor of the matrix for the specified row and column
getMinor(row, column)Calculates the minor of the matrix for the specified row and column
trace()Calculates the trace of the matrix
inverse()Calculates the inverse of the matrix
rowSpace()Calculates the row space of the matrix
colSpace()Calculates the column space of the matrix
isSameOrder(matrix)Checks if the matrix has the same order as the specified matrix
equals()Checks if the matrix is equal to the specified matrix

Private Methods

methoddescription
_isOutOfMatrix(row, col)Checks if the specified row and column indices are out of the matrix's bounds
_initializeMatrix()Initializes the matrix with the specified dimensions and data

For more information, please refer to the Matrix Class documentation

Contributing

Contributions are always welcome!

See contributing.md for ways to get started.

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

The MatrixLab is open source and distributed under the MIT License.

Contact

If you want to contact me, you can reach me at @ladunjexa.

1.0.5

10 months ago

1.0.4

10 months ago

1.0.3

10 months ago

1.0.2

11 months ago

1.0.1

11 months ago

1.0.0

11 months ago