Matrix operations.
These operations are very lax about the dimensions of vectors - they stick zeros in when pairs of matrices don't line up exactly.
Methods
(static) abs(m) → {number}
Matrix determinant. Only works up to 3x3 matrices.
Parameters:
Name | Type | Description |
---|---|---|
m |
matrix |
Throws:
-
"matrixmath.abs.too big" if the matrix has more than 3 rows.
- Type
- Numbas.Error
Returns:
Type | Description |
---|---|
number |
(static) add(a, b) → {matrix}
Add two matrices.
Parameters:
Name | Type | Description |
---|---|---|
a |
matrix | |
b |
matrix |
Returns:
Type | Description |
---|---|
matrix |
(static) combine_diagonally(m1, m2) → {matrix}
Combine two matrices diagonally.
Parameters:
Name | Type | Description |
---|---|---|
m1 |
matrix | |
m2 |
matrix |
Returns:
Type | Description |
---|---|
matrix |
(static) combine_horizontally(m1, m2) → {matrix}
Combine two matrices horizontally.
Parameters:
Name | Type | Description |
---|---|---|
m1 |
matrix | |
m2 |
matrix |
Returns:
Type | Description |
---|---|
matrix |
(static) combine_vertically(m1, m2) → {matrix}
Combine two matrices vertically.
Parameters:
Name | Type | Description |
---|---|---|
m1 |
matrix | |
m2 |
matrix |
Returns:
Type | Description |
---|---|
matrix |
(static) eq(a, b) → {boolean}
Are two matrices equal? True if each pair of corresponding elements is equal.
Parameters:
Name | Type | Description |
---|---|---|
a |
matrix | |
b |
matrix |
Returns:
Type | Description |
---|---|
boolean |
(static) gauss_jordan_elimination(m) → {matrix}
Perform Gauss-Jordan elimination on a copy of the given matrix.
Parameters:
Name | Type | Description |
---|---|---|
m |
matrix |
Returns:
Type | Description |
---|---|
matrix |
(static) id(n) → {matrix}
Make an NxN
identity matrix.
Parameters:
Name | Type | Description |
---|---|---|
n |
number |
Returns:
Type | Description |
---|---|
matrix |
(static) inverse(m) → {matrix}
Find the inverse of the given square matrix.
Parameters:
Name | Type | Description |
---|---|---|
m |
matrix |
Returns:
Type | Description |
---|---|
matrix |
(static) lu_decomposition(m) → {Array.<matrix>}
LU decomposition: decompose a square matrix m into a lower-triangular matrix L and upper-triangular matrix U, satisfying m = L*U
.
Parameters:
Name | Type | Description |
---|---|---|
m |
matrix |
Returns:
Type | Description |
---|---|
Array.<matrix> |
(static) map(m, fn) → {matrix}
Apply given function to each element.
Parameters:
Name | Type | Description |
---|---|---|
m |
matrix | |
fn |
function |
Returns:
Type | Description |
---|---|
matrix |
(static) mul(a, b) → {matrix}
Multiply two matrices.
Parameters:
Name | Type | Description |
---|---|---|
a |
matrix | |
b |
matrix |
Throws:
-
"matrixmath.mul.different sizes" if
a
doesn't have as many columns asb
has rows. - Type
- Numbas.Error
Returns:
Type | Description |
---|---|
matrix |
(static) negate(m) → {matrix}
Negate a matrix - negate each of its elements .
Parameters:
Name | Type | Description |
---|---|---|
m |
matrix |
Returns:
Type | Description |
---|---|
matrix |
(static) neq(a, b) → {boolean}
Are two matrices unequal?
Parameters:
Name | Type | Description |
---|---|---|
a |
matrix | |
b |
matrix |
Returns:
Type | Description |
---|---|
boolean |
- Source:
- See:
(static) numcolumns(m) → {number}
Returns number of columns in a matrix.
Parameters:
Name | Type | Description |
---|---|---|
m |
matrix |
Returns:
Type | Description |
---|---|
number |
(static) numrows(m) → {number}
Returns number of row in a matrix.
Parameters:
Name | Type | Description |
---|---|---|
m |
matrix |
Returns:
Type | Description |
---|---|
number |
(static) precround(m, dp) → {matrix}
Round each element to given number of decimal places.
Parameters:
Name | Type | Description |
---|---|---|
m |
matrix | |
dp |
number | Number of decimal places. |
Returns:
Type | Description |
---|---|
matrix |
(static) scalardiv(m, k) → {matrix}
Divide a matrix by a scalar.
Parameters:
Name | Type | Description |
---|---|---|
m |
matrix | |
k |
number |
Returns:
Type | Description |
---|---|
matrix |
(static) scalarmul(k, m) → {matrix}
Multiply a matrix by a scalar.
Parameters:
Name | Type | Description |
---|---|---|
k |
number | |
m |
matrix |
Returns:
Type | Description |
---|---|
matrix |
(static) siground(m, sf) → {matrix}
Round each element to given number of significant figures.
Parameters:
Name | Type | Description |
---|---|---|
m |
matrix | |
sf |
number | Number of decimal places. |
Returns:
Type | Description |
---|---|
matrix |
(static) sub(a, b) → {matrix}
Subtract one matrix from another.
Parameters:
Name | Type | Description |
---|---|---|
a |
matrix | |
b |
matrix |
Returns:
Type | Description |
---|---|
matrix |
(static) sum_cells(m) → {number}
Sum of every cell.
Parameters:
Name | Type | Description |
---|---|---|
m |
matrix |
Returns:
Type | Description |
---|---|
number |