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) fraction_matrix(matrix) → {Array.<Array.<Numbas.math.Fraction>>}
Convert a matrix of numbers to a matrix of Fractions.
Parameters:
Name | Type | Description |
---|---|---|
matrix |
matrix |
Returns:
Type | Description |
---|---|
Array.<Array.<Numbas.math.Fraction>> |
(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) reduced_row_echelon_form(matrix) → {fraction_matrix}
Put a matrix representing a system of equations in reduced row-echelon form. Can:
- Swap two rows
- Multiply a row by a scalar
- Subtract a multiple of one row from another As well as being in row-echelon form, the matrix has the property that the first non-zero entry in each row is also the only non-zero entry in its column.
Parameters:
Name | Type | Description |
---|---|---|
matrix |
fraction_matrix |
Returns:
Type | Description |
---|---|
fraction_matrix |
(static) row_echelon_form(matrix) → {fraction_matrix}
Put a matrix in row-echelon form.
Parameters:
Name | Type | Description |
---|---|---|
matrix |
fraction_matrix |
Returns:
Type | Description |
---|---|
fraction_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 |
(static) transpose(m) → {matrix}
Matrix transpose.
Parameters:
Name | Type | Description |
---|---|---|
m |
matrix |
Returns:
Type | Description |
---|---|
matrix |
(static) unfraction_matrix(matrix) → {matrix}
Convert a matrix of fractions to a matrix of numbers.
Parameters:
Name | Type | Description |
---|---|---|
matrix |
Array.<Array.<Numbas.math.Fraction>> |
Returns:
Type | Description |
---|---|
matrix |