Skip to content
This repository has been archived by the owner on Jan 3, 2024. It is now read-only.

Matrix Object

Matias Vazquez-Levi edited this page Jan 27, 2021 · 11 revisions

Import

const Matrix = require('dannjs').matrix;

Contructor( rows , cols )

When you create a matrix, you need to specify the number of rows & the number of columns.

const m1 = new Matrix(4,4);

Object Properties

  • rows
    A numeric value representing the number of rows.

  • cols
    A numeric value representing the number of columns.

  • matrix
    The matrix as an array containing other arrays.

Functions

set( matrix );

This function sets the matrix of a matrix object.

  • matrix
    A matrix formatted as an array containing arrays. The initial dimensions don't need to be the same as the new matrix dimensions.

example:

let m1 = new Matrix(3,3);

m1.log({table:true});
// outputs: 3x3 matrix

let matrix = [
    [1,0],
    [0,1]
];

m1.set(matrix);

m1.log({table:true});
// outputs: 2x2 matrix


insert( value , x , y );

This function sets a specific value in the matrix.

  • value
    The value to be inserted into the specified coordinates in the matrix

  • x
    Column index

  • y
    Row index


initiate( value );

This function resets the matrix, all values are set to the same value.

  • value (optional)
    The value to be set through out the matrix. Is set to 0 by default


log( options );

Logs information about the matrix.

  • options (optional)
    Options on how to log the matrix.
Property Type Function
decimals Integer The number of decimals the logged data is going to have. It is set to 3 by default.
Table Boolean Whether or not we want to print our matrix in the form of a table or a normal Matrix object log.




Clone this wiki locally