1.0.1 • Published 2 years ago

lats v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

LATS (Linear Algebra library written in TypeScript)

Installing (2 options):

- For the latest stable version:

npm install lats 

- Import from CDN:

<script src="https://unpkg.com/lats">
<!-- add this line above in the heading of your html file: -->

The example of usage:

import { Vector, Matrix } from 'lats';

/*Vector*/
const vec1 = new Vector([1, 2, 3]);
const vec2 = new Vector([-1, -2, -3]);
const vec3 = vec1.add(vec2);

vec3.values; // returns [0, 0, 0];

/*Matrix*/
const mat = new Matrix(2, 2, [1, 2, 3, 4]);
mat.scale(9);

mat.values; // returns [[9, 18], [27, 36]]
mat.valuesLine; // returns [9, 18, 27, 36] 

Tests (Mocha + chai)

to run tests: 1. clone this repository 2. install all development dependencies (npm install) 3. run command under this line

npm run test

Documentation

new Vector(values: number[])

property/methodreturndescription
values getterarraywithout equal sign returns Vector's values as array
values setterwith equal sign changes Vector's values (new value must be in same dimension as actual)
rows getternumberVector's size
reset()replaces Vector's values with 0s
at(index: number)numberreturns Vector's value at position of index
setAt(index: number, value: number)replaces Vector's value at position of index
add(vec2: Vector)Vectorvec1 + vec2 returns new Vector *
subtract(vec2: Vector)Vectorvec1 - vec2 returns new Vector *
multiply(vec2: Vector)Vectorvec1 vec2 returns new Vector
divide(vec2: Vector)Vectorvec1 / vec2 returns new Vector *
inverse()replaces Vector's values with the opposite (1, 2, 3 => -1, -2, -3)
clone()Vectorreturns Vector with exactly the same values as parent have
equals(vec2: Vector)booleancompares values of vec1 and vec2 and returns true if they are the same, or returns false if they are not
scale(n: number)replaces Vector's values with actual values multiplied by n
dot(vec2: Vector)numberreturns Vectors dot *
sqrdLength()numberreturns Vector's squared length
vlength()numberreturns Vector's length
noramalize()Vectorreturns new Vector that equal to normalized actual
cross(vec2: Vector)Vectorreturns new Vector equal to cross product of vec1 and vec2 *

* Both vectors must have the same dimension.

new Matrix(rows: number, columns: numbers, values: number[])

property/methodreturndescription
values getterarraywithout equal sign returns values of Matrix as array of array (like [1, 2, 3, 4, 5, 6, 7, 8, 9])
values setterwith equal sign changes values of Matrix (new value must be in same form and size as actual)
valuesLine getterarrayreturns values of Matrix as array (like 1, 2, 3, 4, 5, 6, 7, 8, 9)
columns getternumberreturns count of columns of Matrix
rows getternumberreturns count of rows of Matrix
reset()replaces values of Matrix with 0s
clone()Matrixreturns Matrix with exactly the same values as parent have
at(rIndex: number, cIndex: number)numberreturns value of Matrix at position of indexes
add(mat2: Matrix)Matrixmat1 + mat2 returns new Matrix *
subtract(mat2: Matrix)Matrixmat1 - mat2 returns new Matrix *
multiply(mat2: Matrix)Matrixmat1 mat2 returns new Matrix
divide(mat2: Matrix)Matrixmat1 / mat2 returns new Matrix *
equals(mat2: Matrix)booleancompares values of mat1 and mat2 and returns true if they are the same, or returns false if they are not
square()Matrixreturns new Matrix with values same as actual has but squared
transpose()Matrixreturns new Matrix with values same as actual has but transposed
scale(n: number)replaces values of Matrix with actual values multiplied by n
inverse()replaces values of Matrix with the opposite (1, 2, 3 => -1, -2, -3)

* Both matrices must have the same form and size.