AvoMatrix.js
is a standalone JavaScript library that can perform basic matrix math.
It can be used for a variety of projects like storing image- and map data for games
or to design a very basic neural network.
This library can be used by everyone for every purpose, though I would strongly
appreciate sending me a message if you decide to use it.
Almost all matrix-operations can be performed static and non-static!
Download the AvoMatrix.js file and
import it in your JavaScript projects by adding
a < script src="" > tag to your index.html
file and changing
the source to the location of the
AvoMatrix.js file.
You can find the Documentation.js Documentation here
Meta
- version: 1.0.0
- author: AvoLord
- Matrix
Creates a new matrix-object with given rows, columns and fill
- Matrix_Class_Error_Message
Sets the Error-messages and the state
Creates a new matrix-object with given rows, columns and fill
Kind: global class
- Matrix
- new Matrix(rows, columns, fill)
- instance
- .show()
- .dim() ⇒
Array - .random(min, max)
- .toArray() ⇒
- .toArray_flat() ⇒
- .toString() ⇒
- .serialize() ⇒
- .reduce() ⇒
- .map(func)
- .row_map(row, func)
- .col_map(col, func)
- .copy() ⇒
- .unit()
- .diagonal(diagonal_num, filler)
- .fill(filler)
- .transpose() ⇒
- .invert()
- .add(Obj)
- .sub(Obj)
- .mult(Obj)
- .div(Obj)
- .triangle(above, below)
- .isTriangle() ⇒
Boolean - .hasEmpty() ⇒
Boolean - .determinant(iterations) ⇒
Number - .solveLGS(iterations) ⇒
Array
- static
- .Error_Message()
- .randomInt(min, max) ⇒
Number - .array_mult(a1, a2) ⇒
Object - .fromArray(array) ⇒
Object - .diagonal(M1, diagnonal_num, filler) ⇒
Object - .random(M1, min, max) ⇒
Object - .map(M1, func) ⇒
Object - .add(M1, Obj) ⇒
Object - .sub(M1, Obj) ⇒
Object - .mult(M1, Obj) ⇒
Object - .div(M1, Obj) ⇒
Object - .prod(M1, M2) ⇒
Object - .invert(M1) ⇒
Object - .deserialize(data) ⇒
| Param | Type | Description |
|---|---|---|
| rows | Number |
The amount of rows of the matrix |
| columns | Number |
The amount of columns of the matrix |
| fill | Number |
The number with wich the matrix will be filled |
Shows the contents of the matrix in the console
Kind: instance method of Matrix
Returns the dimensions of the matrix
Kind: instance method of Matrix
Returns: Array - - Dimensions [rows, columns]
Randomizes the elements of a matrix
Kind: instance method of Matrix
| Param | Type | Description |
|---|---|---|
| min | Number |
The minimum random number |
| max | Number |
The maximum random number |
Represents a matrix as a two-dimensional array
Kind: instance method of Matrix
Returns: An array with the elements of the input-matrix
Represents a matrix as a one-dimensional array
Kind: instance method of Matrix
Returns: An array with the elements of the input-matrix
Represents a matrix as a string
Kind: instance method of Matrix
Returns: A string with the elements of the input-matrix
Represents a matrix-object as a JSON-file
Kind: instance method of Matrix
Returns: A JSON-file with the elements of the input-matrix-object
Creates the sum of all elements of the matrix
Kind: instance method of Matrix
Returns: The sum of all the elements of the input-matrix
Maps a function to all elements of the matrix
Kind: instance method of Matrix
| Param | Type | Description |
|---|---|---|
| func | function |
The function that will be mapped to the matrix elements |
Maps a function to a specific row of elements of the matrix
Kind: instance method of Matrix
| Param | Type | Description |
|---|---|---|
| row | Number |
The targeted row |
| func | function |
The function that will be mapped to the matrix elements |
Maps a function to a specific collumn of elements of the matrix
Kind: instance method of Matrix
| Param | Type | Description |
|---|---|---|
| col | Number |
The targeted collumn |
| func | function |
The function that will be mapped to the matrix elements |
Creates a copy of a matrix-object
Kind: instance method of Matrix
Returns: A copy of the input-matrix
Converts the matrix to a unit-matrix
Kind: instance method of Matrix
Converts the matrix to a diagonal matrix with custom infill
Kind: instance method of Matrix
| Param | Type | Description |
|---|---|---|
| diagonal_num | Number |
The value of the diagonal line |
| filler | Number |
The value that the other elements will have |
Fills the matrix with a specified number
Kind: instance method of Matrix
| Param | Type | Description |
|---|---|---|
| filler | Number |
the number with wich the matrix will be filled |
Creates the transposed version of a matrix
Kind: instance method of Matrix
Returns: The transposed matrix
Inverts the elements of a matrix
Kind: instance method of Matrix
Adds elements of another matrix or a number to the initial matrix
Kind: instance method of Matrix
| Param | Type | Description |
|---|---|---|
| Obj | Number |
The number that will be added to all elements of the initial matrix |
| Obj | Object |
The matrix whose elements are added to the elements of the initial matrix |
Subtracts elements of another matrix or a number from the initial matrix
Kind: instance method of Matrix
| Param | Type | Description |
|---|---|---|
| Obj | Number |
The number that will be subtracted from all elements of the initial matrix |
| Obj | Object |
The matrix whose elements are subtracted from the elements of the initial matrix |
Multiplies elements of another matrix or a number with the initial matrix
Kind: instance method of Matrix
| Param | Type | Description |
|---|---|---|
| Obj | Number |
The number that will multiply all elements of the initial matrix |
| Obj | Object |
The matrix whose elements multiply the elements of the initial matrix |
Divides elements of the initial matrix by the elements of another matrix or number
Kind: instance method of Matrix
| Param | Type | Description |
|---|---|---|
| Obj | Number |
The number that will divide added to all elements of the initial matrix |
| Obj | Object |
The matrix whose elements divide the elements of the initial matrix |
Transforms a matrix to a "triangle-form"
Kind: instance method of Matrix
| Param | Type | Default | Description |
|---|---|---|---|
| above | Boolean |
true |
Converts the upper-right corner |
| below | Boolean |
false |
Converts the lower-left corner |
Checks if a matrix is in a "triangle-form"
Kind: instance method of Matrix
Returns: Boolean - - Matrix is in triangle-form
Checks if a matrix has empty rows or collumns
Kind: instance method of Matrix
Returns: Boolean - - Matrix has empty rows or collumns
Calculates the determinant of a matrix
Kind: instance method of Matrix
Returns: Number - the determinant of the matrix
Warning: Do not enter the perameter iterations because that is just for recursion purposes!
| Param | Type | Default | Description |
|---|---|---|---|
| iterations | Number |
0 |
The amount of recursion that occurred |
Solves a system of linear equations represented as a matrix
Kind: instance method of Matrix
Returns: Array - The solved variables
Warning: WARNING: Work In Progress
Warning: Do not enter the parameter iterations because that is just for recursion purposes!
| Param | Type | Description |
|---|---|---|
| iterations | Number |
The amount of recursion that occurred |
Toggels if Error messages are displayed
Kind: static method of Matrix
Creates a random Integer
Kind: static method of Matrix
Returns: Number - - A random number between min and max
| Param | Type | Description |
|---|---|---|
| min | Number |
The minimum random number |
| max | Number |
The maximum random number |
The scalar-multiplication of two arrays seen as vectors
Kind: static method of Matrix
Returns: Object - The scalar-product of two "vectors"
| Param | Type | Description |
|---|---|---|
| a1 | Object |
The first array / vector |
| a2 | Object |
The second array / vector |
Creates matrix-object from a two-dimensional array
Kind: static method of Matrix
Returns: Object - A new matrix-object with the values form the array
| Param | Type | Description |
|---|---|---|
| array | Object |
The array that will be converted to a matrix |
Creates a diagnonal matrix-object
Kind: static method of Matrix
Returns: Object - A new matrix with the same dimensions as the input-matrix but with a new set of numbers
| Param | Type | Description |
|---|---|---|
| M1 | Object |
The matrix that will be cloned and converted |
| diagnonal_num | Number |
The number that will fill the diagonal line |
| filler | Number |
The number that will fill the result |
Creates a matrix-object with random numbers
Kind: static method of Matrix
Returns: Object - A new matrix with the same dimensions as the input-matrix but with random numbers randing form min to max
| Param | Type | Description |
|---|---|---|
| M1 | Object |
The matrix that will be cloned and converted |
| min | Number |
The minimum random number |
| max | Number |
The maximum random number |
Creates a matrix on which a function has been mapped to
Kind: static method of Matrix
Returns: Object - A new matrix with the same dimensions as the input-matrix but with a new set of numbers
| Param | Type | Description |
|---|---|---|
| M1 | Object |
The Matrix that will be cloned and converted |
| func | function |
The function that will alter the elements of the matrix |
Creates a new matrix from the sum of the elements of two matrices or a matrix and a number
Kind: static method of Matrix
Returns: Object - A new Matrix with the same dimensions as the input Matrix but with a new set of numbers
| Param | Type | Description |
|---|---|---|
| M1 | Object |
The matrix that will be cloned and converted |
| Obj | Number |
The number that will be added to all elements of the matrix |
| Obj | Object |
The matrix whose elements will be added to the elements of M1 |
Creates a new matrix from the difference of the elements of two matrices or a matrix and a number
Kind: static method of Matrix
Returns: Object - A new Matrix with the same dimensions as the input Matrix but with a new set of numbers
| Param | Type | Description |
|---|---|---|
| M1 | Object |
The matrix that will be cloned and converted |
| Obj | Number |
The number that will be subtracted from all elements of the matrix |
| Obj | Object |
The matrix whose elements will be subtracted from the elements of M1 |
Creates a new matrix from the product of the elements of two matrices or a matrix and a number
Kind: static method of Matrix
Returns: Object - A new Matrix with the same dimensions as the input Matrix but with a new set of numbers
| Param | Type | Description |
|---|---|---|
| M1 | Object |
The matrix that will be cloned and converted |
| Obj | Number |
The number that will be multiplied with all elements of the matrix |
| Obj | Object |
The matrix whose elements will be multiplied by the elements of M1 |
Creates a new matrix from the division of the elements of two matrices or a matrix and a number
Kind: static method of Matrix
Returns: Object - A new Matrix with the same dimensions as the input Matrix but with a new set of numbers
| Param | Type | Description |
|---|---|---|
| M1 | Object |
The matrix that will be cloned and converted |
| Obj | Number |
The number that will be divided from all elements of the matrix |
| Obj | Object |
The matrix whose elements will be divided by the elements of M1 |
Creates a new matrix from the multiplication of two matrices
Kind: static method of Matrix
Returns: Object - The Product of the matrix multiplication
| Param | Type | Description |
|---|---|---|
| M1 | Object |
The first matrix |
| M2 | Object |
The second matrix that will be multiplied with the first |
Creates a new matrix whose values are inverted
Kind: static method of Matrix
Returns: Object - A new matrix with the same dimensions as the input-matrix but with an inverted set of numbers
| Param | Type | Description |
|---|---|---|
| M1 | Object |
The matrix that will be cloned and converted |
Creates a new matrix-object from a JSON-file
Kind: static method of Matrix
Returns: A new matrix-objet with the information of the JSON-file
| Param | Description |
|---|---|
| data | The JSON-file that contains all the necessary information of a matrix-object |
Sets the Error-messages and the state
Kind: global variable