This is the alpha release of the Typescript Math Toolkit Matrix class for creating and transforming dense matrices, as well as solving small, dense systems of linear equations.
As with many other classes in the toolkit, the primary purpose of this alpha release is to spur additional testing and API feedback. For example, will there ever be a need to compute matrix norms, eigenvalues, SVD? If so, is this capability better exposed in an advanced Matrix class?
Inquiring minds want to know :)
Author: Jim Armstrong - The Algorithmist
@algorithmist
theAlgorithmist [at] gmail [dot] com
Typescript: 2.3.2
Version: 1.0
Installation involves all the usual suspects
- npm and gulp installed globally
- Clone the repository
- npm install
- get coffee (this is the most important step)
-
gulp compile
-
gulp test
The test suite is in Mocha/Chai and specs reside in the test folder.
The TSMT$Matrix class represents a dense, m x n matrix as an array of m arrays of type number, each of length n.
The TSMT$Matrix class may also be used to solve linear equations of the form Ax = b. This is accomplished by an LU factorization and backsolve. Since the factorization is expensive, it is only updated if matrix data changes.
Even if the data is sparse and contains a significant number of zeros, the TSMT$Matrix class always treats a matrix as dense.
The list of public methods for the TSMT$Matrix class is as follows:
fromArray( matrix: Array<Array<number>> ): void
get factorized():boolean
get m(): number
get n(): number
getRow(index: number): Array<number>
getColumn(index: number): Array<number>
clear(): void
addRow(row: Array<number>): void
appendRow(row: Array<number>): void
insertRow(index: number, row: Array<number>): void
removeFirst(): void
removeLast(): void
deleteRow(index: number): void
clone(): TSMT$Matrix
sumColumns(): Array<number>
sumRows(): Array<number>
add(matrix: TSMT$Matrix): void
addTo(matrix: TSMT$Matrix): TSMT$Matrix
subtract(matrix: TSMT$Matrix): void
subtractFrom(matrix: TSMT$Matrix): TSMT$Matrix
timesScalar(s: number): void
transpose(): void
transposeInto(): TSMT$Matrix
timesVector(v: Array<number>): Array<number>
multiply(matrix: TSMT$Matrix): void
multiplyInto(matrix: TSMT$Matrix): TSMT$Matrix
solve(b: Array<number>): Array<number>
A sample usage indicating solution of a linear system of equations is shown below
const matrix: TSMT$Matrix = new TSMT$Matrix();
matrix.appendRow( [1, -2, -2, -3] );
matrix.appendRow( [3, -9, 0, -9] );
matrix.appendRow( [-1, 2, 4, 7] );
matrix.appendRow( [-3, -6, 26, 2] );
const solution:Array<number> = __matrix.solve( [1, 1, 1, 1] );
Refer to the specs in the test folder for more usage examples.
Apache 2.0
Free Software? Yeah, Homey plays that