Skip to content

Avolord/AvoMatrix

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Introduction

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!

Usage

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

Classes

Matrix

Creates a new matrix-object with given rows, columns and fill

Members

Matrix_Class_Error_Message

Sets the Error-messages and the state

Matrix

Creates a new matrix-object with given rows, columns and fill

Kind: global class

new Matrix(rows, columns, fill)

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

matrix.show()

Shows the contents of the matrix in the console

Kind: instance method of Matrix

matrix.dim() ⇒ Array

Returns the dimensions of the matrix

Kind: instance method of Matrix Returns: Array - - Dimensions [rows, columns]

matrix.random(min, max)

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

matrix.toArray() ⇒

Represents a matrix as a two-dimensional array

Kind: instance method of Matrix Returns: An array with the elements of the input-matrix

matrix.toArray_flat() ⇒

Represents a matrix as a one-dimensional array

Kind: instance method of Matrix Returns: An array with the elements of the input-matrix

matrix.toString() ⇒

Represents a matrix as a string

Kind: instance method of Matrix Returns: A string with the elements of the input-matrix

matrix.serialize() ⇒

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

matrix.reduce() ⇒

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

matrix.map(func)

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

matrix.row_map(row, func)

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

matrix.col_map(col, func)

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

matrix.copy() ⇒

Creates a copy of a matrix-object

Kind: instance method of Matrix Returns: A copy of the input-matrix

matrix.unit()

Converts the matrix to a unit-matrix

Kind: instance method of Matrix

matrix.diagonal(diagonal_num, filler)

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

matrix.fill(filler)

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

matrix.transpose() ⇒

Creates the transposed version of a matrix

Kind: instance method of Matrix Returns: The transposed matrix

matrix.invert()

Inverts the elements of a matrix

Kind: instance method of Matrix

matrix.add(Obj)

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

matrix.sub(Obj)

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

matrix.mult(Obj)

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

matrix.div(Obj)

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

matrix.triangle(above, below)

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

matrix.isTriangle() ⇒ Boolean

Checks if a matrix is in a "triangle-form"

Kind: instance method of Matrix Returns: Boolean - - Matrix is in triangle-form

matrix.hasEmpty() ⇒ Boolean

Checks if a matrix has empty rows or collumns

Kind: instance method of Matrix Returns: Boolean - - Matrix has empty rows or collumns

matrix.determinant(iterations) ⇒ Number

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

matrix.solveLGS(iterations) ⇒ Array

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

Matrix.Error_Message()

Toggels if Error messages are displayed

Kind: static method of Matrix

Matrix.randomInt(min, max) ⇒ Number

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

Matrix.array_mult(a1, a2) ⇒ Object

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

Matrix.fromArray(array) ⇒ Object

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

Matrix.diagonal(M1, diagnonal_num, filler) ⇒ Object

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

Matrix.random(M1, min, max) ⇒ Object

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

Matrix.map(M1, func) ⇒ Object

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

Matrix.add(M1, Obj) ⇒ Object

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

Matrix.sub(M1, Obj) ⇒ Object

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

Matrix.mult(M1, Obj) ⇒ Object

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

Matrix.div(M1, Obj) ⇒ Object

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

Matrix.prod(M1, M2) ⇒ Object

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

Matrix.invert(M1) ⇒ Object

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

Matrix.deserialize(data) ⇒

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

Matrix_Class_Error_Message

Sets the Error-messages and the state

Kind: global variable

About

A Javascript Matrix library.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published