1.1.4 • Published 2 years ago

@antononyshch/matrixts v1.1.4

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

Matrixts

Matrixts is a small library for matrices written in TypeScript with zero dependencies!

It's just a class with static methods which cover almost all operations over matrices you need to work with.

Table of content

Installation

npm install @antononyshch/matrixts

Features

  • Check if matrices are equal
  • Getting identity/unit matrices with
    • Built in; dimension 2x2, 3x3
    • Any dimension you may want
  • Multiplication
    • Built in; multiplication 3x1, 2x2, 3x3
    • Multiplications of any dimension
  • Addition
  • Subtraction
  • Power
  • Transposition
  • Exclude / Minor
  • Determinants
  • Inverse

Suppose we have some arbitrary matrices:

export const m2x2_1 = [
    [4, 7],
    [0, -4]
]
export const m2x2_2 = [
    [1, -5],
    [2, 4]
]

export const m3x3_1 = [
    [4, 7, 2],
    [0, -4, 1],
    [9, -3, 5]
]
export const m3x3_2 = [
    [1, -5, 2],
    [2, 4, -1],
    [4, 3, 9]
]
export const m4x4_1 = [
    [1, -5, 2, 5],
    [2, 4, -1, 2],
    [4, 3, 9, 1],
    [1, 2, 3, 4]
]
  1. Equality

    return Matrix.equal(m3x3_1, m3x3_1);
    // Result: true
  2. Unit/Identity matrices

    • Unit 2x2
    Matrix.getUnit2x2();
    // Result:
    <!-- [
        [1, 0],
        [0, 1]
    ] -->
    • Unit 3x3
    Matrix.getUnit3x3();
    // Result:
    <!-- [
        [1, 0, 0],
        [0, 1, 0],
        [0, 0, 1]
    ] -->
    • Arbitrary unit matrix
    Matrix.getUnit(4);
    // Result:
    <!-- [
        [1, 0, 0, 0],
        [0, 1, 0, 0],
        [0, 0, 1, 0]
        [0, 0, 0, 1]
    ] -->
  3. Multiplication

    • To number
    Matrix.mulToN(m3x3_1, 2);
    // Result:
    <!-- [
        [8, 14, 4],
        [0, -8, 2],
        [18, -6, 10]
    ] -->
    • Multiplication
    Matrix.mul(m3x3_1, m3x3_2);
    // Result:
    <!-- [
        [4, 14, 8],
        [-0, -16, 3],
        [18, 3, 45]
    ] -->
    • Multiplication 2x2
    Matrix.mul2x2(m2x2_1, m2x2_2);
    // Result:
    <!-- [
        [4, 14],
        [-0, -16]
    ] -->
    • Multiplication 3x3
    Matrix.mul3x3(m3x3_1, m3x3_2);
    // Result:
    <!-- [
        [4, 14, 8],
        [-0, -16, 3],
        [18, 3, 45]
    ] -->
    • Multiplication 3x3 to vector
    Matrix.mul3x1(m3x3_1, v);
    // Result:
    [[65, 12, 22]]
  4. Addition

    Matrix.add(m2x2_1, m2x2_2);
    // Result:
    <!-- [
        [5, 2],
        [2, 0]
    ] -->
  5. Subtraction

    Matrix.sub(m2x2_1, m2x2_2);
    // Result:
    <!-- [
        [3, 12],
        [-2, -8]
    ] -->
  6. Power

    Matrix.power(m2x2_1, 2);
    // Result:
    <!-- [
        [16, 49],
        [0, 16]
    ] -->
  7. Transposition

    Matrix.trans(m3x2_1);
    // Result:
    <!-- [
        [1, 2],
        [-5, 4],
        [2, -1]
    ] -->
  8. Exclude

    Matrix.exclude(m4x4_1, 2, 2);
    // Result: 
    [
        [1, 2, 5]
        [4, 9, 1]
        [1, 3, 4]
    ]
  9. Determinants

    • Determinant 2x2
    Matrix.determ2x2(m2x2_1);
    // Result: -16
    • Determinant 3x3
    Matrix.determ3x3(m3x3_1);
    // Result: 67
    • Determinant 4x4
    Matrix.determ4x4(m4x4_1);
    // Result: 674
  10. Inverse

    • Inverse 2x2
    Matrix.inverse2x2(m2x2_1);
    // Result:
    <!-- [
       [0.25, 0.4375],
       [0,	-0.25],
    ] -->
- Inverse 3x3
```typescript
Matrix.inverse3x3(m3x3_1);
// Result:
<!-- [
    [-0.2537313401699066, -0.611940324306488, 0.2238806039094925],
    [0.13432836532592773, 0.02985074557363987, -0.05970149114727974],
    [0.5373134613037109, 1.1194030046463013, -0.23880596458911896]
] -->
```
1.1.4

2 years ago

1.1.3

2 years ago

1.1.2

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago