Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

matrmath

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

matrmath

A library for performing common matrix operations.

  • 0.1.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

matrmath

A library for performing matrix operations.

Installation

npm install matrmath

Usage

Utilize the functions in this library for performing matrix operations.

For example, compute the diagonal difference of a square (n x n) matrix:

const mtr = require("matrmath");

let diff = mtr.diagonalDiff([
    [2, 5, 3],
    [4, 6, 1],
    [7, 8, 9]
]);

console.log(diff);
// |(2+6+9) - (3+6+7)| = |17-16| = 1

Or compute a matrix in reduced row echelon form:

const mtr = require("matrmath");

let reduced = mtr.rowReduce([
    [5, 8, 2],
    [3, 5, 3],
    [6, 4, 9]
]);

console.log(reduced);
// [ [ 1, 0, 0 ], [ 0, 1, 0 ], [ 0, 0, 1 ] ]

Config

rowReduce(M)

Transform a matrix in-place and return the reduced row-echelon form of a matrix. Row replacement is achieved through Gaussian Elimination.

  • M - number[][] - A 2-dimensional array.
  • square - boolean - Optional boolean parameter to specify if the matrix is square (ie 3x3, 4x4 etc).

diagonalDiff(M)

Return the diagonal difference of a square. The diagonal difference is the absolute value of the left diagonal minus the right diagonal in a square matrix.

  • M - number[][] | number[] - A 2-dimensional array, or optionally 1D array.
  • is2D - boolean - Optional boolean parameter to specify if the matrix is 1D instead of 2D.
  • debug - boolean - Optional boolean parameter to output the lib object with items used in computations.

isSquare(M)

Check whether a 2D or 1D matrix is square. That is the number of rows equals the number of columns in a n x m layout where n = rows and m = columns and n must equal m.

  • M - number[][] | number[] - A 2D or 1D array, or optionally 1D array.
  • is2D - boolean - Optional boolean parameter to specify if the matrix is 1D instead of 2D.

det(M)

Calculate the determinant of a matrix.

  • M - number[][] - A 2-dimensional array.

isIndependent(M)

Calculate whether a square matrix is linearly independent. If the determinant of a matrix is not equal to 0, its linearly independent.

  • M - number[][] - A 2-dimensional array.

isDependent(M)

Calculate whether a square matrix is linearly dependent. Meaning its determinant equals 0.

  • M - number[][] - A 2-dimensional array.

Tests

npm run test

Todo

  • Add a utility for transforming points in R^n to R^n. In other words, transform a set of points in some space (R2) to points in (R3). Have a initial input matrix and a transformation matrix as parameters to output the points after being multiplied by the transformation matrix.

Resources

Keywords

FAQs

Package last updated on 09 Aug 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc