Apply a function that maps an array to a scalar along a given axis of a matrix or array. Returns a new matrix or array with one less dimension than the input.
The input Matrix
The dimension along which the callback is applied
The callback function that is applied. This Function should take an array or 1-d matrix as an input and return a number.
The residual matrix with the function applied over some dimension.
Set configuration options for math.js, and get current options. Will emit a ‘config’ event, with arguments (curr, prev, changes).
Available options: {number} relTol Minimum relative difference between two compared values, used by all comparison functions. {number} absTol Minimum absolute difference between two compared values, used by all comparison functions. {string} matrix A string ‘Matrix’ (default) or ‘Array’. {string} number A string ‘number’ (default), ‘BigNumber’, or ‘Fraction’ {number} precision The number of significant digits for BigNumbers. Not applicable for Numbers. {string} parenthesis How to display parentheses in LaTeX and string output. {string} randomSeed Random seed for seeded pseudo random number generator. Set to null to randomly seed.
Returns the current configuration
Parse an expression. Returns a node tree, which can be evaluated by invoking node.evaluate();
Simplify an expression tree.
Create a typed-function which checks the types of the arguments and can match them against multiple provided signatures. The typed-function automatically converts inputs in order to find a matching signature. Typed functions throw informative errors in case of wrong input arguments.
Optional name for the typed-function
Object with one or multiple function signatures
The created typed-function.
If null were to be included in this interface, it would be
auto-suggested as an import in VSCode. This causes issues because
null is not a valid label.
Calculate the absolute value of a number. For matrices, the function is evaluated element wise.
A number or matrix for which to get the absolute value
Absolute value of x
Calculate the inverse cosine of a value.
Function input
The arc cosine of x
Calculate the hyperbolic arccos of a value, defined as acosh(x) = ln(sqrt(x^2 - 1) + x).
Function input
The hyperbolic arccosine of x
Calculate the inverse cotangent of a value.
Function input
The arc cotangent of x
Calculate the inverse hyperbolic tangent of a value, defined as acoth(x) = (ln((x+1)/x) + ln(x/(x-1))) / 2.
Function input
The inverse hyperbolic tangent of x
Calculate the inverse cosecant of a value.
Function input
The arc cosecant of x
Calculate the inverse hyperbolic cosecant of a value, defined as acsch(x) = ln(1/x + sqrt(1/x^2 + 1)).
Function input
The inverse hyperbolic cosecant of x
Logical and. Test whether two values are both defined with a nonzero/nonempty value. For matrices, the function is evaluated element wise.
First value to and
Second value to and
Returns true when both inputs are defined with a nonzero/nonempty value.
Compute the argument of a complex value. For a complex number a + bi, the argument is computed as atan2(b, a). For matrices, the function is evaluated element wise.
A complex number or array with complex numbers
The argument of x
Calculate the inverse secant of a value.
Function input
The arc secant of x
Calculate the hyperbolic arcsecant of a value, defined as asech(x) = ln(sqrt(1/x^2 - 1) + 1/x).
Function input
The hyperbolic arcsecant of x
Calculate the inverse sine of a value.
Function input
The arc sine of x
Calculate the inverse tangent function with two arguments, y/x. By providing two arguments, the right quadrant of the computed angle can be determined. For matrices, the function is evaluated element wise.
Four quadrant inverse tangent
Calculate the hyperbolic arctangent of a value, defined as atanh(x) = ln((1 + x)/(1 - x)) / 2.
Function input
The hyperbolic arctangent of x
The Bell Numbers count the number of partitions of a set. A partition is a pairwise disjoint subset of S whose union is S. bellNumbers only takes integer arguments. The following condition must be enforced: n
= 0
Total number of objects in the set
B(n)
Bitwise AND two values, x & y. For matrices, the function is evaluated element wise.
First value to and
Second value to and
AND of x and y
Bitwise NOT value, ~x. For matrices, the function is evaluated element wise. For units, the function is evaluated on the best prefix base.
Value to not
NOT of x
Bitwise OR two values, x | y. For matrices, the function is evaluated element wise. For units, the function is evaluated on the lowest print base.
OR of x and y
Bitwise XOR two values, x ^ y. For matrices, the function is evaluated element wise.
First value to xor
Second value to xor
XOR of x and y
Create a boolean or convert a string or number to a boolean. In case of a number, true is returned for non-zero numbers, and false in case of zero. Strings can be 'true' or 'false', or can contain a number. When value is a matrix, all elements will be converted to boolean.
A value of any type
The boolean value
Calculate the cubic root of a value.
Value for which to calculate the cubic root.
OptionalallRoots: booleanOptional, false by default. Only applicable when x is a number or complex number. If true, all complex roots are returned, if false (default) the principal root is returned.
Returns the cubic root of x
Round a value towards plus infinity If x is complex, both real and imaginary part are rounded towards plus infinity. For matrices, the function is evaluated element wise.
Rounded value
Wrap any value in a chain, allowing to perform chained operations on the value. All methods available in the math.js library can be called upon the chain, and then will be evaluated with the value itself as first argument. The chain can be closed by executing chain.done(), which returns the final value. The chain has a number of special functions: done() Finalize the chain and return the chain's value. valueOf() The same as done() toString() Executes math.format() onto the chain's value, returning a string representation of the value.
Optionalvalue: TValueA value of any type on which to start a chained operation.
The created chain
Return a column from a Matrix.
An array or matrix
The index of the column
The retrieved column
Compute the number of ways of picking k unordered outcomes from n possibilities. Combinations only takes integer arguments. The following condition must be enforced: k <= n.
Number of possible combinations
Compare two values. Returns 1 when x > y, -1 when x < y, and 0 when x == y. x and y are considered equal when the relative difference between x and y is smaller than the configured relTol and absTol. The function cannot be used to compare values smaller than approximately 2.22e-16. For matrices, the function is evaluated element wise.
Returns the result of the comparison: 1 when x > y, -1 when x < y, and 0 when x == y.
Compare two values of any type in a deterministic, natural way. For numeric values, the function works the same as math.compare. For types of values that can’t be compared mathematically, the function compares in a natural way.
First value to compare
Second value to compare
Returns the result of the comparison: 1 when x > y, -1 when x < y, and 0 when x == y.
Compare two strings lexically. Comparison is case sensitive. Returns 1 when x > y, -1 when x < y, and 0 when x == y. For matrices, the function is evaluated element wise.
First string to compare
Second string to compare
Returns the result of the comparison: 1 when x > y, -1 when x < y, and 0 when x == y.
Parse and compile an expression. Returns a an object with a function evaluate([scope]) to evaluate the compiled expression.
The expression to be compiled
An object with the compiled expression
The expressions to be compiled
An array of objects with the compiled expressions
Create a complex value or convert a value to a complex value.
Optionalarg: string | MathNumericType | PolarCoordinatesReturns a complex value
Optionalarg: MathCollection<MathNumericType>Argument specifying the real part of the complex number
Argument specifying the imaginary part of the complex number
Returns a complex value
The composition counts of n into k parts. Composition only takes integer arguments. The following condition must be enforced: k <= n.
Returns the composition counts of n into k parts.
Concatenate two or more matrices. dim: number is a zero-based dimension over which to concatenate the matrices. By default the last dimension of the matrices.
Two or more matrices
Concatenated matrix
Compute the complex conjugate of a complex value. If x = a+bi, the complex conjugate of x is a - bi. For matrices, the function is evaluated element wise.
A complex number or array with complex numbers
The complex conjugate of x
Calculate the correlation coefficient between two matrix.
The first array or matrix to compute correlation coefficient
The second array or matrix to compute correlation coefficient
correlation coefficient
Calculate the cosine of a value.
Function input
The cosine of x
Calculate the hyperbolic cosine of a value, defined as cosh(x) = 1/2
Function input
The hyperbolic cosine of x
Calculate the cotangent of a value. cot(x) is defined as 1 / tan(x).
Function input
The cotangent of x
Calculate the hyperbolic cotangent of a value, defined as coth(x) = 1 / tanh(x).
Function input
The hyperbolic cotangent of x
Count the number of elements of a matrix, array or string.
A matrix, array or string.
The number of members passed in parameters
Create a user-defined unit and register it with the Unit type.
The name of the new unit. Must be unique. Example: ‘knot’
Optionaldefinition: string | Unit | UnitDefinitionDefinition of the unit in terms of existing units. For example, ‘0.514444444 m / s’.
Optionaloptions: CreateUnitOptions(optional) An object containing any of the following properties:- prefixes {string} “none”, “short”, “long”, “binary_short”, or “binary_long”. The default is “none”.- aliases {Array} Array of strings. Example: [‘knots’, ‘kt’, ‘kts’]- offset {Numeric} An offset to apply when converting from the unit. For example, the offset for celsius is 273.15. Default is 0.
The new unit
Create a user-defined unit and register it with the Unit type.
Definition of the unit
Optionaloptions: CreateUnitOptionsThe new unit
Calculate the cross product for two vectors in three dimensional space. The cross product of A = [a1, a2, a3] and B =[b1, b2, b3] is defined as: cross(A, B) = [ a2 * b3 - a3 * b2, a3 * b1 - a1 * b3, a1
First vector
Second vector
Returns the cross product of x and y
Calculate the cosecant of a value, defined as csc(x) = 1/sin(x).
Function input
The cosecant hof x
Calculate the hyperbolic cosecant of a value, defined as csch(x) = 1 / sinh(x).
Function input
The hyperbolic cosecant of x
Transpose and complex conjugate a matrix. All values of the matrix are reflected over its main diagonal and then the complex conjugate is taken. This is equivalent to complex conjugation for scalars and vectors.
Matrix to be ctransposed
Compute the cube of a value, x * x * x. For matrices, the function is evaluated element wise.
Number for which to calculate the cube
Cube of x
Compute the cumulative sum of a matrix or a list with values. In case of a (multi dimensional) array or matrix, the cumulative sums along a specified dimension (defaulting to the first) will be calculated.
A single matrix or multiple scalar values
The cumulative sums of the the values.
A single matrix
Optionaldim: numberThe dimension along which to sum (defaults to 0)
The cumulative sums along the given dimension
Calculate the determinant of a matrix.
A Matrix
the determinant of x
Create a diagonal matrix or retrieve the diagonal of a matrix. When x is a vector, a matrix with vector x on the diagonal will be returned. When x is a two dimensional matrix, the matrixes kth diagonal will be returned as vector. When k is positive, the values are placed on the super diagonal. When k is negative, the values are placed on the sub diagonal.
A two dimensional matrix or a vector
Optionalformat: stringThe matrix storage format. Default value: 'dense'.
Diagonal matrix from input vector, or diagonal from input matrix
Optionalformat: stringCalculate the difference between adjacent elements of a matrix or array.
A matrix or array containing the differences
Calculates: The Euclidean distance between two points in 2 and 3 dimensional spaces. Distance between point and a line in 2 and 3 dimensional spaces. Pairwise distance between a set of 2D or 3D points NOTE: When substituting coefficients of a line(a, b and c), use ax + by + c = 0 instead of ax + by = c For parametric equation of a 3D line, x0, y0, z0, a, b, c are from: (x−x0, y−y0, z−z0) = t(a, b, c)
Coordinates of the first point
Coordinates of the second point OR coefficients of a line in 3D OR first end-point of a line if the calculation is for distance between point and a line in 2D
Optionalz: object | MathCollection<MathNumericType>Coordinates of second end-point of a line if the calculation is for distance between point and a line in 2D
Returns the distance from two/three points
Calculate the dot product of two vectors. The dot product of A = [a1, a2, a3, ..., an] and B = [b1, b2, b3, ..., bn] is defined as: dot(A, B) = a1 * b1 + a2 * b2 + a3 * b3 + ... + an * bn
First vector
Second vector
Returns the dot product of x and y
Divide two matrices element wise. The function accepts both matrices and scalar values.
Quotient, x ./ y
Multiply two matrices element wise. The function accepts both matrices and scalar values.
Multiplication of x and y
Compute eigenvalues and eigenvectors of a matrix.
The eigenvalues are sorted by their absolute value, ascending.
An eigenvalue with multiplicity k will be listed k times.
The eigenvectors are returned as an array of objects, each with a
value and a vector. If the algorithm fails to converge,
it will throw an error – in that case, however, you may still find useful
information in err.values and err.vectors
Matrix to be diagonalized
Optionalopts: number | BigNumber | { eigenvectors?: true; precision?: number | BigNumber }Object containing an array of eigenvalues and a matrix with eigenvectors as columns.
Test whether two values are equal.
The function tests whether the relative difference between x and y is smaller than the configured relTol and absTol. The function cannot be used to compare values smaller than approximately 2.22e-16. For matrices, the function is evaluated element wise. In case of complex numbers, x.re must equal y.re, and x.im must equal y.im. Values null and undefined are compared strictly, thus null is only equal to null and nothing else, and undefined is only equal to undefined and nothing else.
Returns true when the compared values are equal, else returns false
Check equality of two strings. Comparison is case sensitive. For matrices, the function is evaluated element wise.
First string to compare
Second string to compare
Returns true if the values are equal, and false if not.
Compute the erf function of a value using a rational Chebyshev approximations for different intervals of x.
A real number
The erf of x
Evaluate an expression.
The expression to be evaluated
Optionalscope: MathScope<any>Scope to read/write variables
The result of the expression
Optionalscope: MathScope<any>Compute the matrix exponential, expm(A) = e^A. The matrix must be square. Not to be confused with exp(a), which performs element-wise exponentiation. The exponential is calculated using the Padé approximant with scaling and squaring; see “Nineteen Dubious Ways to Compute the Exponential of a Matrix,” by Moler and Van Loan.
A square matrix
The exponential of x
Compute the factorial of a value Factorial only supports an integer value as argument. For matrices, the function is evaluated element wise.
An integer number
The factorial of n
Calculate N-dimensional Fourier transform
An array or matrix
N-dimensional Fourier transformation of the array
Filter the items in an array or one dimensional matrix.
A one dimensional matrix or array to filter
A function or regular expression to test items. All entries for which test returns true are returned. When test is a function, it is invoked with three parameters: the value of the element, the index of the element, and the matrix/array being traversed. The function must return a boolean.
Round a value towards zero. For matrices, the function is evaluated element wise.
Rounded value
Flatten a multi dimensional matrix into a single dimensional matrix.
Matrix to be flattened
Returns the flattened matrix
Round a value towards minus infinity. For matrices, the function is evaluated element wise.
Rounded value
Iterate over all elements of a matrix/array, and executes the given callback function.
Format a value of any type into a string.
The value to be formatted
Optionaloptions: number | BigNumber | FormatOptions | ((item: any) => string)An object with formatting options.
Optionalcallback: (value: any) => stringA custom formatting function, invoked for all numeric elements in value, for example all elements of a matrix, or the real and imaginary parts of a complex number. This callback can be used to override the built-in numeric notation with any type of formatting. Function callback is called with value as parameter and must return a string.
The formatted value
Create a fraction convert a value to a fraction.
Arguments specifying the numerator and denominator of the fraction
Returns a fraction
Argument specifying the numerator of the fraction
Argument specifying the denominator of the fraction
Returns a fraction
Calculates the frequency response of a filter given its numerator and denominator coefficients.
The frequency response
Compute the gamma function of a value using Lanczos approximation for small values, and an extended Stirling approximation for large values.
A real or complex number
The gamma of n
Calculate the greatest common divisor for two or more values or arrays. For matrices, the function is evaluated element wise.
Two or more integer numbers
The greatest common divisor
Return the (name of the) data type of the elements of matrix, or 'mixed'.
the matrix
A string specifying the data type of the elements of m
Test whether a value is an numeric value. In case of a string, true is returned if the string contains a numeric value.
Value to be tested
Returns true when x is a number, BigNumber, bigint, Fraction, Boolean, or a String containing number. Returns false for other types. Throws an error in case of unknown types.
Retrieve help on a function or data type. Help files are retrieved from the documentation in math.expression.docs.
A function or function name for which to get help
A help object
Calculate the hypotenuse of a list with values. The hypotenuse is defined as: hypot(a, b, c, ...) = sqrt(a^2 + b^2 + c^2 + ...) For matrix input, the hypotenuse is calculated for all values in the matrix.
A list with numeric values or an Array or Matrix. Matrix and Array input is flattened and returns a single number for the whole matrix.
Returns the hypotenuse of the input values.
Create a 2-dimensional identity matrix with size m x n or n x n. The matrix has ones on the diagonal and zeros elsewhere.
The size for the matrix
Optionalformat: stringThe Matrix storage format
A matrix with ones on the diagonal
The x dimension for the matrix
The y dimension for the matrix
Optionalformat: stringThe Matrix storage format
A matrix with ones on the diagonal
Calculate N-dimensional inverse Fourier transform
An array or matrix
N-dimensional Fourier transformation of the array
Get the imaginary part of a complex number. For a complex number a + bi, the function returns b. For matrices, the function is evaluated element wise.
A complex number or array with complex numbers
The imaginary part of x
Import functions from an object or a module To avoid errors when using one of the imported functions extend module like this:
An object with functions to be imported.
Optionaloptions: ImportOptionsAn object with import options.
Create an index. An Index can store ranges having start, step, and end for multiple dimensions. Matrix.get, Matrix.set, and math.subset accept an Index as input.
Zero or more ranges or numbers.
Returns the created index
Calculates the point of intersection of two lines in two or three dimensions and of a line and a plane in three dimensions. The inputs are in the form of arrays or 1 dimensional matrices. The line intersection functions return null if the lines do not meet. Note: Fill the plane coefficients as x + y + z = c and not as x + y + z + c = 0.
Co-ordinates of first end-point of first line
Co-ordinates of second end-point of first line
Co-ordinates of first end-point of second line OR Coefficients of the plane's equation
Optionalz: MathCollection<MathNumericType>Co-ordinates of second end-point of second line OR null if the calculation is for line and plane
Returns the point of intersection of lines/lines-planes
Calculate the inverse of a square matrix.
Matrix to be inverted
The inverse of x
Test whether a value is bounded
Value to be tested
Boolean true when x represents a bounded mathematical entity
Test whether a value is finite, elementwise on collections
Value to be tested
Boolean | MathCollection
Test whether a value is an integer number. The function supports number, BigNumber, and Fraction. The function is evaluated element-wise in case of Array or Matrix input.
Value to be tested
Returns true when x contains a numeric, integer value. Throws an error in case of an unknown data type.
Test whether a value is NaN (not a number). The function supports types number, BigNumber, Fraction, Unit and Complex. The function is evaluated element-wise in case of Array or Matrix input.
Value to be tested
Returns true when x is NaN. Throws an error in case of an unknown data type.
Test whether a value is negative: smaller than zero. The function supports types number, BigNumber, Fraction, and Unit. The function is evaluated element-wise in case of Array or Matrix input.
Value to be tested
Returns true when x is larger than zero. Throws an error in case of an unknown data type.
Utils
Test whether a value is an numeric value. The function is evaluated element-wise in case of Array or Matrix input.
Value to be tested
Returns true when x is a number, BigNumber, bigint, Fraction, or boolean. Returns false for other types. Throws an error in case of unknown types.
Test whether a value is positive: larger than zero. The function supports types number, BigNumber, Fraction, and Unit. The function is evaluated element-wise in case of Array or Matrix input.
Value to be tested
Returns true when x is larger than zero. Throws an error in case of an unknown data type.
Test whether a value is prime: has no divisors other than itself and one. The function supports type number, bignumber. The function is evaluated element-wise in case of Array or Matrix input.
Value to be tested
Returns true when x is larger than zero. Throws an error in case of an unknown data type.
Test whether a value is zero. The function can check for zero for types number, BigNumber, Fraction, Complex, and Unit. The function is evaluated element-wise in case of Array or Matrix input.
Value to be tested
Returns true when x is zero. Throws an error in case of an unknown data type.
Calculate the Kullback-Leibler (KL) divergence between two distributions
First vector
Second vector
Returns distance between q and p
Calculate the Kronecker product of two matrices or vectors
First vector
Second vector
Returns the Kronecker product of x and y
Test whether value x is larger than y. The function returns true when x is larger than y and the relative difference between x and y is larger than the configured relTol and absTol. The function cannot be used to compare values smaller than approximately 2.22e-16. For matrices, the function is evaluated element wise.
Returns true when x is larger than y, else returns false
Test whether value x is larger or equal to y. The function returns true when x is larger than y or the relative difference between x and y is smaller than the configured relTol and absTol. The function cannot be used to compare values smaller than approximately 2.22e-16. For matrices, the function is evaluated element wise.
Returns true when x is larger than or equal to y, else returns false
Calculate the least common multiple for two or more values or arrays. lcm is defined as: lcm(a, b) = abs(a * b) / gcd(a, b) For matrices, the function is evaluated element wise.
The least common multiple
Gives the number of “leaf nodes” in the parse tree of the given
expression. A leaf node is one that has no subexpressions, essentially
either a symbol or a constant. Note that 5! has just one leaf, the 5;
the unary factorial operator does not add a leaf. On the other hand,
function symbols do add leaves, so sin(x)/cos(x) has four leaves.
Bitwise left logical shift of a value x by y number of bits, x << y. For matrices, the function is evaluated element wise. For units, the function is evaluated on the best prefix base.
x shifted left y times
Compute the log gamma function of a value, using Lanczos approximation for numbers and Stirling series for complex numbers.
A real or complex number
The log gamma of n
Calculate the logarithm of a value.
Returns the logarithm of x
Calculate the 10-base of a value. This is the same as calculating log(x, 10). For matrices, the function is evaluated element wise.
Value for which to calculate the logarithm.
Returns the 10-base logarithm of x
Calculate the logarithm of a value+1. For matrices, the function is evaluated element wise.
Returns the logarithm of x+1
Calculate the 2-base of a value. This is the same as calculating log(x, 2). For matrices, the function is evaluated element wise.
Value for which to calculate the logarithm.
Returns the 2-base logarithm of x
Solves the linear equation system by forwards substitution. Matrix must be a lower triangular matrix.
A N x N matrix or array (L)
A column vector with the b values
A column vector with the linear system solution (x)
Calculate the Matrix LU decomposition with partial pivoting. Matrix A is decomposed in two matrices (L, U) and a row permutation vector p where A[p,:] = L * U
OptionalA: MathCollection<MathNumericType>A two dimensional matrix or array for which to get the LUP decomposition.
The lower triangular matrix, the upper triangular matrix and the permutation matrix.
Solves the linear system A * x = b where A is an [n x n] matrix and b is a [n] column vector.
Invertible Matrix or the Matrix LU decomposition
Column Vector
Optionalorder: numberThe Symbolic Ordering and Analysis order, see slu for details. Matrix must be a SparseMatrix
Optionalthreshold: numberPartial pivoting threshold (1 for partial pivoting), see slu for details. Matrix must be a SparseMatrix.
Column vector with the solution to the linear system A * x = b
Optionalorder: numberOptionalthreshold: numberSolves the Continuous-time Lyapunov equation AP+PA'=Q for P, where Q is a positive semidefinite matrix. https://en.wikipedia.org/wiki/Lyapunov_equation
Matrix A
Matrix Q
Matrix P solution to the Continuous-time Lyapunov equation AP+PA'=Q
Compute the median absolute deviation of a matrix or a list with values. The median absolute deviation is defined as the median of the absolute deviations from the median.
A single matrix or multiple scalar values.
The median absolute deviation
Iterate over all elements of a matrix/array, and executes the given callback function.
Transformed map of x
Iterate over all elements of multiple matrices/arrays, and executes the given callback function.
The first matrix to iterate on.
The rest of the matrices and at the end the callback function is invoked with multiple parameters: the values of the elements, the indices of the elements, and the matrices/arrays being traversed.
Transformed map of matrices
Apply a function that maps an array to a scalar along a given axis of a matrix or array. Returns a new matrix or array with one less dimension than the input.
The input Matrix
The dimension along which the callback is applied
The callback function that is applied. This Function should take an array or 1-d matrix as an input and return a number.
The residual matrix with the function applied over some dimension.
Create a Matrix. The function creates a new math.type.Matrix object from an Array. A Matrix has utility functions to manipulate the data in the matrix, like getting the size and getting or setting values in the matrix. Supported storage formats are 'dense' and 'sparse'.
Optionalformat: MatrixStorageFormatThe Matrix storage format
The created Matrix
A multi dimensional array
Optionalformat: MatrixStorageFormatThe Matrix storage format
OptionaldataType: stringThe Matrix data type
The created Matrix
Optionalformat: MatrixStorageFormatOptionaldataType: stringCreate a dense matrix from vectors as individual columns. If you pass row vectors, they will be transposed (but not conjugated!)
a multi-dimensional number array or matrix
Create a matrix by evaluating a generating function at each index. The simplest overload returns a multi-dimensional array as long as size is an array. Passing size as a Matrix or specifying a format will result in returning a Matrix.
the size of the matrix to be created
Callback function invoked for every entry in the matrix
Optionaldatatype: stringOptionaldatatype: stringCreate a dense matrix from vectors as individual rows. If you pass column vectors, they will be transposed (but not conjugated!)
a multi-dimensional number array or matrix
Compute the maximum value of a matrix or a list with values. In case of a multi dimensional array, the maximum of the flattened array will be calculated. When dim is provided, the maximum over the selected dimension will be calculated. Parameter dim is zero-based.
Multiple scalar values
The maximum value
A single matrix
Optionaldimension: number | BigNumberThe maximum over the selected dimension
The maximum value
Compute the mean value of matrix or a list with values. In case of a multi dimensional array, the mean of the flattened array will be calculated. When dim is provided, the maximum over the selected dimension will be calculated. Parameter dim is zero-based.
Multiple scalar values
The mean of all values
A single matrix
Optionaldimension: number | BigNumberThe mean over the selected dimension
The mean value
Compute the median of a matrix or a list with values. The values are sorted and the middle value is returned. In case of an even number of values, the average of the two middle values is returned. Supported types of values are: Number, BigNumber, Unit In case of a (multi dimensional) array or matrix, the median of all elements will be calculated.
Multiple scalar values
The median value
Compute the minimum value of a matrix or a list of values. In case of a multi dimensional array, the minimum of the flattened array will be calculated. When dim is provided, the minimum over the selected dimension will be calculated. Parameter dim is zero-based.
multiple scalar values
The minimum value
A single matrix
Optionaldimension: number | BigNumberThe minimum over the selected dimension
The minimum value
Calculates the modulus, the remainder of an integer division. For matrices, the function is evaluated element wise. The modulus is defined as: x - y * floor(x / y)
Dividend
Divisor
Returns the remainder of x divided by y
Computes the mode of a set of numbers or a list with values(numbers or characters). If there are more than one modes, it returns a list of those values.
Multiple scalar values
The mode of all values
Multiple scalar values
The mode of all values
Multinomial Coefficients compute the number of ways of picking a1, a2, ..., ai unordered outcomes from n possibilities. multinomial takes one array of integers as an argument. The following condition must be enforced: every ai <= 0
Integer number of objects in the subset
multinomial coefficient
Multiply two values, x * y. The result is squeezed. For matrices, the matrix product is calculated.
Multiplication of x and y
Calculate the norm of a number, vector or matrix. The second parameter p is optional. If not provided, it defaults to 2.
Value for which to calculate the norm
Optionalp: string | number | BigNumberVector space. Supported numbers include Infinity and -Infinity. Supported strings are: 'inf', '-inf', and 'fro' (The Frobenius norm) Default value: 2.
the p-norm
Logical not. Flips boolean value of a given parameter. For matrices, the function is evaluated element wise.
First value to not
Returns true when input is a zero or empty value.
Calculate the nth root of a value. The principal nth root of a positive real number A, is the positive real solution of the equation x^root = A For matrices, the function is evaluated element wise.
The nth root of a
Optionalroot: number | BigNumberOptionalvalue: MathCollection<MathNumericType>Create a matrix filled with ones. The created matrix can have one or multiple dimensions.
A matrix filled with ones
Logical or. Test if at least one value is defined with a nonzero/nonempty value. For matrices, the function is evaluated element wise.
First value to or
Second value to or
Returns true when one of the inputs is defined with a nonzero/nonempty value.
Create a parser. The function creates a new math.expression.Parser object.
A Parser object
Partition-based selection of an array or 1D matrix. Will find the kth smallest value, and mutates the input array. Uses Quickselect.
A one dimensional matrix or array to sort
The kth smallest value to be retrieved; zero-based index
Optionalcompare: "desc" | "asc" | ((a: any, b: any) => number)An optional comparator function. The function is called as compare(a, b), and must return 1 when a > b, -1 when a < b, and 0 when a == b. Default value: 'asc'.
Returns the kth lowest value.
Compute the number of ways of obtaining an ordered subset of k elements from a set of n elements. Permutations only takes integer arguments. The following condition must be enforced: k <= n.
The number of permutations
Random pick a value from a one dimensional array. Array element is picked using a random function with uniform distribution.
A one dimensional array
Returns a single random value from array when number is undefined. Returns an array with the configured number of elements when number is defined.
Interpolate values into a string template.
A string containing variable placeholders.
An object containing variables which will be filled in in the template.
Optionalprecision: numberNumber of digits to format numbers. If not provided, the value will not be rounded.
Optionaloptions: number | objectFormatting options, or the number of digits to format numbers. See function math.format for a description of all options.
Interpolated string
Compute the product of a matrix or a list with values. In case of a (multi dimensional) array or matrix, the sum of all elements will be calculated.
Multiple scalar values
The product of all values
Multiple scalar values
The product of all values
Calculate the Matrix QR decomposition. Matrix A is decomposed in two matrices (Q, R) where Q is an orthogonal matrix and R is an upper triangular matrix.
A two dimensional matrix or array for which to get the QR decomposition.
Q: the orthogonal matrix and R: the upper triangular matrix
Compute the prob order quantile of a matrix or a list with values. The sequence is sorted and the middle value is returned. Supported types of sequence values are: Number, BigNumber, Unit Supported types of probability are: Number, BigNumber In case of a (multi dimensional) array or matrix, the prob order quantile of all elements will be calculated.
A single matrix or array
Optionalsorted: boolean=false is data sorted in ascending order
Quantile(s)
Return a random number larger or equal to min and smaller than max using a uniform distribution.
Optionalmin: numberMinimum boundary for the random value, included
Optionalmax: numberMaximum boundary for the random value, excluded
A random number
Optionalmin: numberOptionalmax: numberReturn a random integer number larger or equal to min and smaller than max using a uniform distribution.
Minimum boundary for the random value, included
Optionalmax: numberMaximum boundary for the random value, excluded
A random number
Optionalmin: numberOptionalmax: numberCreate an array from a range. By default, the range end is excluded. This can be customized by providing an extra parameter includeEnd.
A string 'start:end' or 'start:step:end'
OptionalincludeEnd: booleanParameters describing the ranges start, end, and optional step.
Transform a rationalizable expression in a rational fraction. If rational fraction is one variable polynomial then converts the numerator and denominator in canonical form, with decreasing exponents, returning the coefficients of numerator.
The expression to check if is a polynomial expression
Optionaloptional: boolean | objectscope of expression or true for already evaluated rational expression at input
Optionaldetailed: trueoptional True if return an object, false if return expression node (default)
The rational polynomial of expr
Get the real part of a complex number. For a complex number a + bi, the function returns a. For matrices, the function is evaluated element wise.
A complex number or array of complex numbers
The real part of x
Returns replacer function that can be used as replacer in JSON.stringify function.
Reshape a multi dimensional array to fit the specified dimensions
Matrix to be reshaped
One dimensional array with integral sizes for each dimension
A reshaped clone of matrix x
Resize a matrix
Matrix to be resized
One dimensional array with numbers
OptionaldefaultValue: string | numberZero by default, except in case of a string, in that case defaultValue = ' ' Default value: 0.
A resized clone of matrix x
Returns reviver function that can be used as reviver in JSON.parse function.
Bitwise right arithmetic shift of a value x by y number of bits, x >> y. For matrices, the function is evaluated element wise. For units, the function is evaluated on the best prefix base.
x sign-filled shifted right y times
Bitwise right logical shift of value x by y number of bits, x >>> y. For matrices, the function is evaluated element wise. For units, the function is evaluated on the best prefix base.
Value to be shifted
Amount of shifts
x zero-filled shifted right y times
Return a rotated matrix.
Multiplication of the rotation matrix and w
Return a Rotation Matrix for a given angle in radians
Rotation Matrix
Round a value towards the nearest integer. For matrices, the function is evaluated element wise.
Rounded value of x
Return a row from a Matrix.
An array or matrix
The index of the row
The retrieved row
Performs a real Schur decomposition of the real matrix A = UTU' where U is orthogonal and T is upper quasi-triangular. https://en.wikipedia.org/wiki/Schur_decomposition
Matrix A
Object containing both matrix U and T of the Schur Decomposition A=UTU'
Calculate the secant of a value, defined as sec(x) = 1/cos(x).
Function input
The secant of x
Calculate the hyperbolic secant of a value, defined as sech(x) = 1 / cosh(x).
Function input
The hyperbolic secant of x
Create the cartesian product of two (multi)sets. Multi-dimension arrays will be converted to single-dimension arrays and the values will be sorted in ascending order before the operation.
A (multi)set
A (multi)set
The cartesian product of two (multi)sets
Create the difference of two (multi)sets: every element of set1, that is not the element of set2. Multi-dimension arrays will be converted to single-dimension arrays before the operation
A (multi)set
A (multi)set
The difference of two (multi)sets
Collect the distinct elements of a multiset. A multi-dimension array will be converted to a single-dimension array before the operation.
A multiset
A set containing the distinct elements of the multiset
Create the intersection of two (multi)sets. Multi-dimension arrays will be converted to single-dimension arrays before the operation.
A (multi)set
A (multi)set
The intersection of two (multi)sets
Check whether a (multi)set is a subset of another (multi)set. (Every element of set1 is the element of set2.) Multi-dimension arrays will be converted to single-dimension arrays before the operation.
A (multi)set
A (multi)set
True if a1 is subset of a2, else false
Count the multiplicity of an element in a multiset. A multi-dimension array will be converted to a single-dimension array before the operation.
An element in the multiset
A multiset
The number of how many times the multiset contains the element
Create the powerset of a (multi)set. (The powerset contains very possible subsets of a (multi)set.) A multi-dimension array will be converted to a single-dimension array before the operation.
A multiset
The powerset of the (multi)set
Count the number of elements of a (multi)set. When a second parameter is ‘true’, count only the unique values. A multi-dimension array will be converted to a single-dimension array before the operation.
A multiset
The number of elements of the (multi)set
Create the symmetric difference of two (multi)sets. Multi-dimension arrays will be converted to single-dimension arrays before the operation.
A (multi)set
A (multi)set
The symmetric difference of two (multi)sets
Create the union of two (multi)sets. Multi-dimension arrays will be converted to single-dimension arrays before the operation.
A (multi)set
A (multi)set
The union of two (multi)sets
Optionaloptions: SimplifyOptionsOptionaloptions: SimplifyOptionsCalculate the hyperbolic sine of a value, defined as sinh(x) = 1/2 * (exp(x) - exp(-x)).
Function input
The hyperbolic sine of x
Calculate the size of a matrix or scalar.
A vector with the size of x
Calculate the Sparse Matrix LU decomposition with full pivoting. Sparse Matrix A is decomposed in two matrices (L, U) and two permutation vectors (pinv, q) where P * A * Q = L * U
A two dimensional sparse matrix for which to get the LU decomposition.
The Symbolic Ordering and Analysis order: 0 - Natural ordering, no permutation vector q is returned 1 - Matrix must be square, symbolic ordering and analysis is performed on M = A + A' 2 - Symbolic ordering and analysis is performed on M = A' * A. Dense columns from A' are dropped, A recreated from A'. This is appropriate for LU factorization of non-symmetric matrices. 3 - Symbolic ordering and analysis is performed on M = A' * A. This is best used for LU factorization is matrix M has no dense rows. A dense row is a row with more than 10*sqr(columns) entries.
Partial pivoting threshold (1 for partial pivoting)
The lower triangular matrix, the upper triangular matrix and the permutation vectors.
Test whether value x is smaller than y. The function returns true when x is smaller than y and the relative difference between x and y is smaller than the configured relTol and absTol. The function cannot be used to compare values smaller than approximately 2.22e-16. For matrices, the function is evaluated element wise.
Returns true when x is smaller than y, else returns false
Test whether value x is smaller or equal to y. The function returns true when x is smaller than y or the relative difference between x and y is smaller than the configured relTol and absTol. The function cannot be used to compare values smaller than approximately 2.22e-16. For matrices, the function is evaluated element wise.
Returns true when x is smaller than or equal to y, else returns false
Sort the items in a matrix
A one dimensional matrix or array to sort
An optional _comparator function or name. The function is called as compare(a, b), and must return 1 when a > b, -1 when a < b, and 0 when a == b. Default value: ‘asc’
Returns the sorted matrix
Create a Sparse Matrix. The function creates a new math.type.Matrix object from an Array. A Matrix has utility functions to manipulate the data in the matrix, like getting the size and getting or setting values in the matrix.
Optionaldata: MathCollection<MathNumericType>A two dimensional array
OptionaldataType: stringSparse Matrix data type
The created matrix
Calculate the square root of a value. For matrices, use either sqrtm for the matrix square root, or map(M, sqrt) to take the square root element wise.
Value for which to calculate the square root
Returns the square root of x
Calculate the principal square root of a square matrix. The principal square root matrix X of another matrix A is such that X * X = A.
The square matrix A
The principal square root of matrix A
Compute the square of a value, x * x.
Number for which to calculate the square
Squared value
Squeeze a matrix, remove inner and outer singleton dimensions from a matrix.
Matrix to be squeezed
Squeezed matrix
Compute the standard deviation of a matrix or a list with values. The standard deviations is defined as the square root of the variance: std(A) = sqrt(variance(A)). In case of a (multi dimensional) array or matrix, the standard deviation over all elements will be calculated. Optionally, the type of normalization can be specified as second parameter. The parameter normalization can be one of the following values: 'unbiased' (default) The sum of squared errors is divided by (n - 1) 'uncorrected' The sum of squared errors is divided by n 'biased' The sum of squared errors is divided by (n + 1)
variadic argument of number to calculate standard deviation
The standard deviation
Multiple scalar values
The standard deviation
Compute the standard deviation of a matrix or a list with values. The standard deviations is defined as the square root of the variance: std(A) = sqrt(variance(A)). In case of a (multi dimensional) array or matrix, the standard deviation over all elements will be calculated. Optionally, the type of normalization can be specified as second parameter. The parameter normalization can be one of the following values: 'unbiased' (default) The sum of squared errors is divided by (n - 1) 'uncorrected' The sum of squared errors is divided by n 'biased' The sum of squared errors is divided by (n + 1)
A single matrix to compute standard deviation.
Optionaldimension: numberA dimension to calculate standard deviation
Optionalnormalization: "unbiased" | "uncorrected" | "biased"Determines how to normalize the variance. Choose ‘unbiased’ (default), ‘uncorrected’, or ‘biased’. Default value: ‘unbiased’.
The standard deviation array
Compute the standard deviation of a matrix or a list with values. The standard deviations is defined as the square root of the variance: std(A) = sqrt(variance(A)). In case of a (multi dimensional) array or matrix, the standard deviation over all elements will be calculated. Optionally, the type of normalization can be specified as second parameter. The parameter normalization can be one of the following values: 'unbiased' (default) The sum of squared errors is divided by (n - 1) 'uncorrected' The sum of squared errors is divided by n 'biased' The sum of squared errors is divided by (n + 1)
A single matrix or multiple scalar values
Determines how to normalize the variance. Choose ‘unbiased’ (default), ‘uncorrected’, or ‘biased’. Default value: ‘unbiased’.
The standard deviation
The Stirling numbers of the second kind, counts the number of ways to partition a set of n labelled objects into k nonempty unlabelled subsets. stirlingS2 only takes integer arguments. The following condition must be enforced: k <= n. If n = k or k = 1, then s(n,k) = 1
S(n,k)
Create a string or convert any object into a string. Elements of Arrays and Matrices are processed element wise.
A value to convert to a string
The created string
Get or set a subset of a matrix or string.
An array, matrix, or string
For each dimension, an index or list of indices to get or set.
Optionalreplacement: anyAn array, matrix, or scalar. If provided, the subset is replaced with replacement. If not provided, the subset is returned
OptionaldefaultValue: anyDefault value, filled in on new entries when the matrix is resized. If not provided, math.matrix elements will be left undefined. Default value: undefined.
Either the retrieved subset or the updated matrix
Compute the sum of a matrix or a list with values. In case of a (multi dimensional) array or matrix, the sum of all elements will be calculated.
A single matrix or multiple scalar values
The sum of all values
Multiple scalar values
The sum of all values
A single matrix
Optionaldimension: number | BigNumberThe sum over the selected dimension
The sum of all values
Solves the real-valued Sylvester equation AX-XB=C for X, where A, B and C are matrices of appropriate dimensions, being A and B squared. The method used is the Bartels-Stewart algorithm. https://en.wikipedia.org/wiki/Sylvester_equation
Matrix A
Matrix B
Matrix C
Matrix X, solving the Sylvester equation
Determines if two expressions are symbolically equal, i.e. one is the result of valid algebraic manipulations on the other.
The first expression to compare
The second expression to compare
Optionaloptions: SimplifyOptionsOptional option object, passed to simplify
Returns true if a valid manipulation making the expressions equal is found.
Calculate the tangent of a value. tan(x) is equal to sin(x) / cos(x).
Function input
The tangent of x
Calculate the hyperbolic tangent of a value, defined as tanh(x) = (exp(2 * x) - 1) / (exp(2 * x) + 1).
Function input
The hyperbolic tangent of x
Change the unit of a value. For matrices, the function is evaluated element wise.
The unit to be converted.
New unit. Can be a string like "cm" or a unit without value.
Value with changed, fixed unit
Converts a unit to the most appropriate display unit. When no preferred units are provided, the function automatically find the best prefix. When preferred units are provided, it converts to the unit that gives a value closest to 1.
Unit with optimized prefix/unit
Calculate the trace of a matrix: the sum of the elements on the main diagonal of a square matrix.
A matrix
The trace of x
Transpose a matrix. All values of the matrix are reflected over its main diagonal. Only two dimensional matrices are supported.
Matrix to be transposed
The transposed matrix
Determine the type of a variable.
The variable for which to test the type
Returns the name of the type. Primitive types are lower case, non-primitive types are upper-camel-case. For example ‘number’, ‘string’, ‘Array’, ‘Date’.
Inverse the sign of a value, apply a unary minus operation. For matrices, the function is evaluated element wise. Boolean values and strings will be converted to a number. For complex numbers, both real and complex value are inverted.
Number to be inverted
Returns the value with inverted sign
Unary plus operation. Boolean values and strings will be converted to a number, numeric values will be returned as is. For matrices, the function is evaluated element wise.
Input value
Returns the input value when numeric, converts to a number when input is non-numeric.
Test whether two values are unequal. The function tests whether the relative difference between x and y is larger than the configured relTol and absTol. The function cannot be used to compare values smaller than approximately 2.22e-16. For matrices, the function is evaluated element wise. In case of complex numbers, x.re must unequal y.re, or x.im must unequal y.im. Values null and undefined are compared strictly, thus null is unequal with everything except null, and undefined is unequal with everything except undefined.
Returns true when the compared values are unequal, else returns false
Create a unit. Depending on the passed arguments, the function will create and return a new math.type.Unit object. When a matrix is provided, all elements will be converted to units.
The unit to be created
The created unit
The value of the unit to be created
Optionalunit: stringThe unit to be created
The created unit
Solves the linear equation system by backward substitution. Matrix must be an upper triangular matrix. U * x = b
A N x N matrix or array (U)
A column vector with the b values
A column vector with the linear system solution (x)
Compute the variance of a matrix or a list with values. In case of a (multi dimensional) array or matrix, the variance over all elements will be calculated. Optionally, the type of normalization can be specified as second parameter. The parameter normalization can be one of the following values: 'unbiased' (default) The sum of squared errors is divided by (n - 1) 'uncorrected' The sum of squared errors is divided by n 'biased' The sum of squared errors is divided by (n +
A single matrix or multiple scalar values
The variance
Compute the variance of a matrix or a list with values. In case of a (multi dimensional) array or matrix, the variance over all elements will be calculated. Optionally, the type of normalization can be specified as second parameter. The parameter normalization can be one of the following values: 'unbiased' (default) The sum of squared errors is divided by (n - 1) 'uncorrected' The sum of squared errors is divided by n 'biased' The sum of squared errors is divided by (n +
A matrix to compute variance.
Optionaldimension: numberA dimension to compute variance on
Optionalnormalization: "unbiased" | "uncorrected" | "biased"normalization Determines how to normalize the variance. Choose ‘unbiased’ (default), ‘uncorrected’, or ‘biased’. Default value: ‘unbiased’.
variance matrix.
A single matrix
normalization Determines how to normalize the variance. Choose ‘unbiased’ (default), ‘uncorrected’, or ‘biased’. Default value: ‘unbiased’.
The variance
Calculate the extended greatest common divisor for two values. See http://en.wikipedia.org/wiki/Extended_Euclidean_algorithm.
Returns an array containing 3 integers [div, m, n] where div = gcd(a, b) and am + bn = div
Logical xor. Test whether one and only one value is defined with a nonzero/nonempty value. For matrices, the function is evaluated element wise.
First value to xor
Second value to xor
Returns true when one and only one input is defined with a nonzero/nonempty value.
Create a matrix filled with zeros. The created matrix can have one or multiple dimensions.
A matrix filled with zeros
Compute the transfer function of a zero-pole-gain model.
The transfer function as array of numerator and denominator
Factory and Dependencies