new Matrix(rows, cols, value) → {Matrix}
creates a new Matrix. Entries are stored in a Float64Array.
| Name | Type | Default | Description |
|---|---|---|---|
rows | number | null | The amount of rows of the matrix. |
cols | number | null | The amount of columns of the matrix. |
value | function | | 0 | Can be a function with row and col as parameters, a number, or "zeros", "identity" or "I", or "center".
|
- Source
- module:numerical/neumair_sum
returns a rows times cols Matrix filled with value.
- Type:
- Matrix
let A = new Matrix(10, 10, () => Math.random()); //creates a 10 times 10 random matrix.
let B = new Matrix(3, 3, "I"); // creates a 3 times 3 identity matrix.Requires
- module:numerical/neumair_sum
Members
asArray
Returns the Matrix as a Array of Arrays.
- Source
diag
Returns the diagonal of the Matrix.
- Source
mean
Returns the mean of all entries of the Matrix.
- Source
meanCols
Returns the mean of each column of the matrix.
- Source
meanRows
Returns the mean of each row of the matrix.
- Source
shape
Returns the number of rows and columns of the Matrix.
- Source
shape
Returns the matrix in the given shape with the given function which returns values for the entries of the matrix.
- Source
sum
Returns the sum oof all entries of the Matrix.
- Source
T
Returns a new transposed Matrix. Short-form of {@function transpose}.
- Source
to2dArray
Returns the Matrix as a Array of Float64Arrays.
- Source
values
Returns the entries of the Matrix.
- Source
Methods
(static) det(A) → {Number}
Computes the determinante of A, by using the LU decomposition of A.
| Name | Type | Description |
|---|---|---|
A | Matrix |
- Source
det - Returns the determinate of the Matrix A.
- Type:
- Number
(static) from(A, typeopt) → {Matrix}
Creates a Matrix out of A.
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
A | Matrix | | The matrix, array, or number, which should converted to a Matrix. | ||
type | "row" | | <optional> | "row" | If |
- Source
- Type:
- Matrix
let A = Matrix.from([[1, 0], [0, 1]]); //creates a two by two identity matrix.
let S = Matrix.from([1, 2, 3], "diag"); // creates a 3 by 3 matrix with 1, 2, 3 on its diagonal. [[1, 0, 0], [0, 2, 0], [0, 0, 3]](static) LU(A) → {Object}
LU decomposition of the Matrix A. Creates two matrices, so that the dot product LU equals A.
| Name | Type | Description |
|---|---|---|
A | Matrix |
- Source
result - Returns the left triangle matrix L and the upper triangle matrix U.
- Type:
- Object
(static) solve(A, b) → {Matrix}
Solves the equation Ax = b. Returns the result x.
- Source
- Type:
- Matrix
(static) solve_CG(A, b, randomizeropt, tolopt) → {Matrix}
Solves the equation Ax = b using the conjugate gradient method. Returns the result x.
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
A | Matrix | Matrix | ||
b | Matrix | Matrix | ||
randomizer | Randomizer | <optional> | null | |
tol | Number | <optional> | 1e-3 |
- Source
- Type:
- Matrix
(static) SVD(M, kopt) → {Object}
Computes the k components of the SVD decomposition of the matrix M
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
M | Matrix | |||
k | int | <optional> | 2 |
- Source
- Type:
- Object
add(value, optionsopt) → {Matrix}
Entrywise addition with value.
| Name | Type | Attributes | Description | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
value | Matrix | | ||||||||||||
options | Object | <optional> | Properties
|
- Source
- Type:
- Matrix
let A = Matrix.from([[1, 2], [3, 4]]); // a 2 by 2 matrix.
let B = A.clone(); // B == A;
A.add(2); // [[3, 4], [5, 6]];
A.add(B); // [[2, 4], [6, 8]];add_entry(row, col, value) → {Matrix}
Adds a given value to the colth entry from the rowth row of the Matrix.
| Name | Type | Description |
|---|---|---|
row | int | |
col | int | |
value | float64 |
- Source
- Type:
- Matrix
clone() → {Matrix}
Clones the Matrix.
- Source
- Type:
- Matrix
col(col) → {Array}
Returns the colth column from the Matrix.
| Name | Type | Description |
|---|---|---|
col | Number |
- Source
- Type:
- Array
concat(B, typeopt) → {Matrix}
Appends matrix B to the matrix.
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
B | Matrix | matrix to append. | ||
type | "horizontal" | | <optional> | "horizontal" | type of concatenation. |
- Source
- Type:
- Matrix
let A = Matrix.from([[1, 1], [1, 1]]); // 2 by 2 matrix filled with ones.
let B = Matrix.from([[2, 2], [2, 2]]); // 2 by 2 matrix filled with twos.
A.concat(B, "horizontal"); // 2 by 4 matrix. [[1, 1, 2, 2], [1, 1, 2, 2]]
A.concat(B, "vertical"); // 4 by 2 matrix. [[1, 1], [1, 1], [2, 2], [2, 2]]
A.concat(B, "diag"); // 4 by 4 matrix. [[1, 1, 0, 0], [1, 1, 0, 0], [0, 0, 2, 2], [0, 0, 2, 2]]divide(value, optionsopt) → {Matrix}
Entrywise division with value.
| Name | Type | Attributes | Description | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
value | Matrix | | ||||||||||||
options | Object | <optional> | Properties
|
- Source
- Type:
- Matrix
let A = Matrix.from([[1, 2], [3, 4]]); // a 2 by 2 matrix.
let B = A.clone(); // B == A;
A.divide(2); // [[0.5, 1], [1.5, 2]];
A.divide(B); // [[1, 1], [1, 1]];dot(B) → {Matrix|Array}
Returns the dot product. If B is an Array or Float64Array then an Array gets returned. If B is a Matrix then a Matrix gets returned.
| Name | Type | Description |
|---|---|---|
B | Matrix | | the right side |
- Source
- Type:
- Matrix |
Array
dotTrans(B) → {Matrix|Array}
Returns the dot product with the transposed version of B. If B is an Array or Float64Array then an Array gets returned. If B is a Matrix then a Matrix gets returned.
| Name | Type | Description |
|---|---|---|
B | Matrix | | the right side |
- Source
- Type:
- Matrix |
Array
entry(row, col) → {float64}
Returns the colth entry from the rowth row of the Matrix.
| Name | Type | Description |
|---|---|---|
row | int | |
col | int |
- Source
- Type:
- float64
gather(row_indices, col_indices) → {Matrix}
Returns a new array gathering entries defined by the indices given by argument.
| Name | Type | Description |
|---|---|---|
row_indices | Array.<Number> | Array consists of indices of rows for gathering entries of this matrix |
col_indices | Array.<Number> | Array consists of indices of cols for gathering entries of this matrix |
- Source
- Type:
- Matrix
get_block(start_row, start_col, end_rowopt, end_colopt) → {Matrix}
Extracts the entries from the start_rowth row to the end_rowth row, the start_colth column to the end_colth column of the matrix. If end_row or end_col is empty, the respective value is set to this.rows or this.cols.
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
start_row | Number | |||
start_col | Number | |||
end_row | Number | <optional> | null | |
end_col | Number | <optional> | null |
- Source
Returns a end_row - start_row times end_col - start_col matrix, with respective entries from the matrix.
- Type:
- Matrix
let A = Matrix.from([[1, 2, 3], [4, 5, 6], [7, 8, 9]]); // a 3 by 3 matrix.
A.get_block(1, 1); // [[5, 6], [8, 9]]
A.get_block(0, 0, 1, 1); // [[1]]
A.get_block(1, 1, 2, 2); // [[5]]
A.get_block(0, 0, 2, 2); // [[1, 2], [4, 5]]inverse() → {Matrix}
Returns the inverse of the Matrix.
- Source
- Type:
- Matrix
(generator) iterate_rows() → {Float64Array}
Returns an generator yielding each row of the Matrix.
- Source
- Type:
- Float64Array
mult(value, optionsopt) → {Matrix}
Entrywise multiplication with value.
| Name | Type | Attributes | Description | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
value | Matrix | | ||||||||||||
options | Object | <optional> | Properties
|
- Source
- Type:
- Matrix
let A = Matrix.from([[1, 2], [3, 4]]); // a 2 by 2 matrix.
let B = A.clone(); // B == A;
A.mult(2); // [[2, 4], [6, 8]];
A.mult(B); // [[1, 4], [9, 16]];outer(B) → {Matrix}
Computes the outer product from this and B.
| Name | Type | Description |
|---|---|---|
B | Matrix |
- Source
- Type:
- Matrix
row(row) → {Float64Array}
Returns the rowth row from the Matrix.
| Name | Type | Description |
|---|---|---|
row | Number |
- Source
- Type:
- Float64Array
set_block(offset_row, offset_col, B) → {Matrix}
Writes the entries of B in A at an offset position given by offset_row and offset_col.
| Name | Type | Description |
|---|---|---|
offset_row | int | |
offset_col | int | |
B | Matrix |
- Source
- Type:
- Matrix
set_entry(row, col, value) → {Matrix}
Sets the colth entry from the rowth row of the Matrix to the given value.
| Name | Type | Description |
|---|---|---|
row | int | |
col | int | |
value | float64 |
- Source
- Type:
- Matrix
set_row(row, values) → {Matrix}
Sets the entries of rowth row from the Matrix to the entries from values.
| Name | Type | Description |
|---|---|---|
row | Number | |
values | Array |
- Source
- Type:
- Matrix
sub(value, optionsopt) → {Matrix}
Entrywise subtraction with value.
| Name | Type | Attributes | Description | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
value | Matrix | | ||||||||||||
options | Object | <optional> | Properties
|
- Source
- Type:
- Matrix
let A = Matrix.from([[1, 2], [3, 4]]); // a 2 by 2 matrix.
let B = A.clone(); // B == A;
A.sub(2); // [[-1, 0], [1, 2]];
A.sub(B); // [[0, 0], [0, 0]];sub_entry(row, col, value) → {Matrix}
Subtracts a given value from the colth entry from the rowth row of the Matrix.
| Name | Type | Description |
|---|---|---|
row | int | |
col | int | |
value | float64 |
- Source
- Type:
- Matrix
swap_rows(row1, row2) → {Matrix}
Swaps the rows row1 and row2 of the Matrix.
| Name | Type | Description |
|---|---|---|
row1 | Number | |
row2 | Number |
- Source
- Type:
- Matrix
transDot(B) → {Matrix|Array}
Transposes the current matrix and returns the dot product with B. If B is an Array or Float64Array then an Array gets returned. If B is a Matrix then a Matrix gets returned.
| Name | Type | Description |
|---|---|---|
B | Matrix | | the right side |
- Source
- Type:
- Matrix |
Array
transpose() → {Matrix}
Returns a new transposed Matrix.
- Source
- Type:
- Matrix