mathjs
- Version 14.4.0
- Published
- 9.51 MB
- 9 dependencies
- Apache-2.0 license
Install
npm i mathjs
yarn add mathjs
pnpm add mathjs
Overview
Math.js is an extensive math library for JavaScript and Node.js. It features a flexible expression parser with support for symbolic computation, comes with a large set of built-in functions and constants, and offers an integrated solution to work with dif
Index
Interfaces
MathJsChain
- abs()
- acos()
- acosh()
- acot()
- acoth()
- acsc()
- acsch()
- add()
- and()
- apply
- arg()
- asec()
- asech()
- asin()
- asinh()
- atan()
- atan2()
- atanh()
- bellNumbers()
- bigint()
- bignumber()
- bitAnd()
- bitNot()
- bitOr()
- bitXor()
- boolean()
- catalan()
- cbrt()
- ceil()
- clone()
- combinations()
- compare()
- compareNatural()
- compareText()
- compile()
- complex()
- composition()
- concat()
- conj()
- cos()
- cosh()
- cot()
- coth()
- count()
- createUnit()
- cross()
- csc()
- csch()
- cube()
- deepEqual()
- derivative()
- det()
- diag()
- distance()
- divide()
- done()
- dot()
- dotDivide()
- dotMultiply()
- dotPow()
- equal()
- equalText()
- erf()
- evaluate()
- exp()
- expm()
- expm1()
- factorial()
- filter()
- fix()
- flatten()
- floor()
- forEach()
- format()
- fraction()
- freqz()
- gamma()
- gcd()
- help()
- hypot()
- identity()
- im()
- index()
- intersect()
- inv()
- isInteger()
- isNaN()
- isNegative()
- isNumeric()
- isPositive()
- isPrime()
- isZero()
- kldivergence()
- kron()
- larger()
- largerEq()
- lcm()
- leafCount()
- leftShift()
- log()
- log10()
- log1p()
- log2()
- lsolve()
- lup()
- lusolve()
- lyap()
- mad()
- map()
- mapSlices()
- matrix()
- max()
- mean()
- median()
- min()
- mod()
- mode()
- multinomial()
- multiply()
- norm()
- not()
- nthRoot()
- number()
- numeric()
- ones()
- or()
- parse()
- partitionSelect()
- permutations()
- pickRandom()
- pow()
- print()
- prod()
- qr()
- quantileSeq()
- random()
- randomInt()
- range()
- rationalize()
- re()
- reshape()
- resize()
- resolve()
- rightArithShift()
- rightLogShift()
- round()
- schur()
- sec()
- sech()
- setCartesian()
- setDifference()
- setDistinct()
- setIntersect()
- setIsSubset()
- setMultiplicity()
- setPowerset()
- setSize()
- setSymDifference()
- setUnion()
- sign()
- simplify()
- simplifyConstant()
- simplifyCore()
- sin()
- sinh()
- size()
- slu()
- smaller()
- smallerEq()
- sort()
- sparse()
- splitUnit()
- sqrt()
- sqrtm()
- square()
- squeeze()
- std()
- stirlingS2()
- string()
- subset()
- subtract()
- sum()
- symbolicEqual()
- tan()
- tanh()
- to()
- trace()
- transpose()
- typeOf()
- unaryMinus()
- unaryPlus()
- unequal()
- unit()
- usolve()
- variance()
- xgcd()
- xor()
- zeros()
- zeta()
- zpk2tf()
MathJsInstance
- abs()
- AccessorNode
- acos()
- acosh()
- acot()
- acoth()
- acsc()
- acsch()
- add()
- and()
- apply
- arg()
- ArrayNode
- asec()
- asech()
- asin()
- asinh()
- AssignmentNode
- atan()
- atan2()
- atanh()
- bellNumbers()
- bigint()
- bignumber()
- bitAnd()
- bitNot()
- bitOr()
- bitXor()
- BlockNode
- boolean()
- catalan()
- cbrt()
- ceil()
- chain()
- clone()
- column()
- combinations()
- compare()
- compareNatural()
- compareText()
- compile()
- complex()
- composition()
- concat()
- ConditionalNode
- config
- conj()
- ConstantNode
- corr()
- cos()
- cosh()
- cot()
- coth()
- count()
- createUnit()
- cross()
- csc()
- csch()
- cube()
- cumsum()
- deepEqual()
- derivative()
- det()
- diag()
- distance()
- divide()
- dot()
- dotDivide()
- dotMultiply()
- dotPow()
- e
- eigs()
- equal()
- equalText()
- erf()
- evaluate()
- exp()
- expm()
- expm1()
- expression
- factorial()
- fft()
- filter()
- fix()
- flatten()
- floor()
- forEach()
- format()
- fraction()
- freqz()
- FunctionAssignmentNode
- FunctionNode
- gamma()
- gcd()
- hasNumericValue()
- help()
- hypot()
- i
- identity()
- ifft()
- im()
- import()
- index()
- IndexNode
- Infinity
- intersect()
- inv()
- isAccessorNode()
- isArray
- isArrayNode()
- isAssignmentNode()
- isBigInt()
- isBigNumber()
- isBlockNode()
- isBoolean()
- isChain()
- isCollection()
- isComplex()
- isConditionalNode()
- isConstantNode()
- isDate()
- isDenseMatrix()
- isFraction()
- isFunction()
- isFunctionAssignmentNode()
- isFunctionNode()
- isHelp()
- isIndex()
- isIndexNode()
- isInteger()
- isMap()
- isMatrix()
- isNaN()
- isNegative()
- isNode()
- isNull()
- isNumber()
- isNumeric()
- isObject()
- isObjectNode()
- isObjectWrappingMap()
- isOperatorNode()
- isParenthesisNode()
- isPartitionedMap()
- isPositive()
- isPrime()
- isRange()
- isRangeNode()
- isRegExp()
- isRelationalNode()
- isResultSet()
- isSparseMatrix()
- isString()
- isSymbolNode()
- isUndefined()
- isUnit()
- isZero()
- kldivergence()
- kron()
- larger()
- largerEq()
- lcm()
- leafCount()
- leftShift()
- lgamma()
- LN10
- LN2
- log()
- log10()
- LOG10E
- log1p()
- log2()
- LOG2E
- lsolve()
- lup()
- lusolve()
- lyap()
- mad()
- map()
- mapSlices()
- matrix()
- Matrix
- matrixFromColumns()
- matrixFromFunction()
- matrixFromRows()
- max()
- mean()
- median()
- min()
- mod()
- mode()
- multinomial()
- multiply()
- NaN
- Node
- norm()
- not()
- nthRoot()
- number()
- numeric()
- ObjectNode
- ones()
- OperatorNode
- or()
- ParenthesisNode
- parse
- parser()
- partitionSelect()
- permutations()
- phi
- pi
- pickRandom()
- pinv()
- polynomialRoot()
- pow()
- print()
- prod()
- qr()
- quantileSeq()
- random()
- randomInt()
- range()
- RangeNode
- rationalize()
- re()
- RelationalNode
- replacer()
- reshape()
- resize()
- resolve()
- reviver()
- rightArithShift()
- rightLogShift()
- rotate()
- rotationMatrix()
- round()
- row()
- schur()
- sec()
- sech()
- setCartesian()
- setDifference()
- setDistinct()
- setIntersect()
- setIsSubset()
- setMultiplicity()
- setPowerset()
- setSize()
- setSymDifference()
- setUnion()
- sign()
- simplify
- simplifyConstant()
- simplifyCore()
- sin()
- sinh()
- size()
- slu()
- smaller()
- smallerEq()
- sort()
- sparse()
- splitUnit()
- sqrt()
- SQRT1_2
- SQRT2
- sqrtm()
- square()
- squeeze()
- std()
- stirlingS2()
- string()
- subset()
- subtract()
- sum()
- sylvester()
- symbolicEqual()
- SymbolNode
- tan()
- tanh()
- tau
- to()
- trace()
- transpose()
- typed
- typeOf()
- unaryMinus()
- unaryPlus()
- unequal()
- uninitialized
- unit()
- Unit
- usolve()
- variance()
- version
- xgcd()
- xor()
- zeros()
- zeta()
- zpk2tf()
Type Aliases
- FactoryDependencies
- FactoryFunction
- MathArray
- MathCollection
- MathExpression
- MathGeneric
- MathJsFunctionName
- MathJsStatic
- MathNodeCommon
- MathNumericType
- MathScalarType
- MathType
- MatrixFromFunctionCallback
- MatrixStorageFormat
- NoLiteralType
- OperatorNodeFn
- OperatorNodeMap
- OperatorNodeOp
- SimplifyContext
- SimplifyRule
- UnitSystemName
Interfaces
interface AccessorNode
interface AccessorNode<TObject extends MathNode = MathNode> extends MathNode {}
property index
index: IndexNode;
property isAccessorNode
isAccessorNode: true;
property name
name: string;
property object
object: TObject;
property type
type: 'AccessorNode';
interface AccessorNodeCtor
interface AccessorNodeCtor {}
construct signature
new <TObject extends MathNode = MathNode>( object: TObject, index: IndexNode): AccessorNode<TObject>;
interface ArrayNode
interface ArrayNode<TItems extends MathNode[] = MathNode[]> extends MathNode {}
property isArrayNode
isArrayNode: true;
property items
items: [...TItems];
property type
type: 'ArrayNode';
interface ArrayNodeCtor
interface ArrayNodeCtor {}
construct signature
new <TItems extends MathNode[] = MathNode[]>( items: [...TItems]): ArrayNode<TItems>;
interface AssignmentNode
interface AssignmentNode<TValue extends MathNode = MathNode> extends MathNode {}
interface AssignmentNodeCtor
interface AssignmentNodeCtor {}
construct signature
new <TValue extends MathNode = MathNode>( object: SymbolNode, value: TValue): AssignmentNode<TValue>;
construct signature
new <TValue extends MathNode = MathNode>( object: SymbolNode | AccessorNode, index: IndexNode, value: TValue): AssignmentNode<TValue>;
interface BaseUnit
interface BaseUnit {}
property dimensions
dimensions: number[];
property key
key: string;
interface BigNumber
interface BigNumber extends Decimal {}
interface BlockNode
interface BlockNode<TNode extends MathNode = MathNode> extends MathNode {}
property blocks
blocks: Array<{ node: TNode; visible: boolean }>;
property isBlockNode
isBlockNode: true;
property type
type: 'BlockNode';
interface BlockNodeCtor
interface BlockNodeCtor {}
construct signature
new <TNode extends MathNode = MathNode>( arr: Array<{ node: TNode } | { node: TNode; visible: boolean }>): BlockNode;
interface Complex
interface Complex {}
property im
im: number;
property re
re: number;
method clone
clone: () => Complex;
method compare
compare: (a: Complex, b: Complex) => number;
method equals
equals: (other: Complex) => boolean;
method format
format: (precision?: number) => string;
method fromJSON
fromJSON: (json: object) => Complex;
method fromPolar
fromPolar: { (polar: object): Complex; (r: number, phi: number): Complex };
method toJSON
toJSON: () => object;
method toPolar
toPolar: () => PolarCoordinates;
method toString
toString: () => string;
interface ConditionalNode
interface ConditionalNode< TCond extends MathNode = MathNode, TTrueNode extends MathNode = MathNode, TFalseNode extends MathNode = MathNode> extends MathNode {}
property condition
condition: TCond;
property falseExpr
falseExpr: TFalseNode;
property isConditionalNode
isConditionalNode: boolean;
property trueExpr
trueExpr: TTrueNode;
property type
type: 'ConditionalNode';
interface ConditionalNodeCtor
interface ConditionalNodeCtor {}
construct signature
new < TCond extends MathNode = MathNode, TTrueNode extends MathNode = MathNode, TFalseNode extends MathNode = MathNode>( condition: TCond, trueExpr: TTrueNode, falseExpr: TFalseNode): ConditionalNode;
interface ConfigOptions
interface ConfigOptions {}
property absTol
absTol?: number;
property epsilon
epsilon?: number;
Deprecated
Use
relTol
andabsTol
instead
property matrix
matrix?: 'Matrix' | 'Array';
property number
number?: 'number' | 'BigNumber' | 'bigint' | 'Fraction';
property numberFallback
numberFallback?: 'number' | 'BigNumber';
property precision
precision?: number;
property predictable
predictable?: boolean;
property randomSeed
randomSeed?: string | null;
property relTol
relTol?: number;
interface ConstantNode
interface ConstantNode< TValue extends | string | number | boolean | null | undefined | bigint | BigNumber | Fraction = number> extends MathNode {}
property isConstantNode
isConstantNode: true;
property type
type: 'ConstantNode';
property value
value: TValue;
interface ConstantNodeCtor
interface ConstantNodeCtor {}
construct signature
new < TValue extends | string | number | boolean | null | undefined | bigint | BigNumber | Fraction = string>( value: TValue): ConstantNode<TValue>;
interface CreateUnitOptions
interface CreateUnitOptions {}
interface Distribution
interface Distribution {}
method pickRandom
pickRandom: (array: any) => any;
method random
random: (size: any, min?: any, max?: any) => any;
method randomInt
randomInt: (min: any, max?: any) => any;
interface EvalFunction
interface EvalFunction {}
method evaluate
evaluate: (scope?: any) => any;
interface FactoryFunctionMap
interface FactoryFunctionMap {}
index signature
[key: string]: FactoryFunction<any> | FactoryFunctionMap;
interface FormatOptions
interface FormatOptions {}
property fraction
fraction?: string;
Available values: 'ratio' (default) or 'decimal'. For example format(fraction(1, 3)) will output '1/3' when 'ratio' is configured, and will output 0.(3) when 'decimal' is configured.
property lowerExp
lowerExp?: number | BigNumber;
Exponent determining the lower boundary for formatting a value with an exponent when notation='auto. Default value is -3.
property notation
notation?: | 'fixed' | 'exponential' | 'engineering' | 'auto' | 'hex' | 'bin' | 'oct';
Number notation. Choose from: 'fixed' Always use regular number notation. For example '123.40' and '14000000' 'exponential' Always use exponential notation. For example '1.234e+2' and '1.4e+7' 'auto' (default) Regular number notation for numbers having an absolute value between lower and upper bounds, and uses exponential notation elsewhere. Lower bound is included, upper bound is excluded. For example '123.4' and '1.4e7'.
property precision
precision?: number | BigNumber;
A number between 0 and 16 to round the digits of the number. In case of notations 'exponential' and 'auto', precision defines the total number of significant digits returned and is undefined by default. In case of notation 'fixed', precision defines the number of significant digits after the decimal point, and is 0 by default.
property upperExp
upperExp?: number | BigNumber;
Exponent determining the upper boundary for formatting a value with an exponent when notation='auto. Default value is 5.
property wordSize
wordSize?: number | BigNumber;
The word size in bits to use for formatting in binary, octal, or hexadecimal notation. To be used only with
'bin'
,'oct'
, or'hex'
values fornotation
option. When this option is defined the value is formatted as a signed twos complement integer of the given word size and the size suffix is appended to the output.
interface FractionDefinition
interface FractionDefinition {}
interface FunctionAssignmentNode
interface FunctionAssignmentNode<TExpr extends MathNode = MathNode> extends MathNode {}
property expr
expr: TExpr;
property isFunctionAssignmentNode
isFunctionAssignmentNode: true;
property name
name: string;
property params
params: string[];
property type
type: 'FunctionAssignmentNode';
interface FunctionAssignmentNodeCtor
interface FunctionAssignmentNodeCtor {}
construct signature
new <TExpr extends MathNode = MathNode>( name: string, params: string[], expr: TExpr): FunctionAssignmentNode<TExpr>;
interface FunctionNode
interface FunctionNode<TFn = SymbolNode, TArgs extends MathNode[] = MathNode[]> extends MathNode {}
property args
args: [...TArgs];
property fn
fn: TFn;
property isFunctionNode
isFunctionNode: true;
property type
type: 'FunctionNode';
interface FunctionNodeCtor
interface FunctionNodeCtor {}
property onUndefinedFunction
onUndefinedFunction: (name: string) => any;
construct signature
new <TFn = SymbolNode, TArgs extends MathNode[] = MathNode[]>( fn: TFn, args: [...TArgs]): FunctionNode<TFn, TArgs>;
interface Help
interface Help {}
interface ImportObject
interface ImportObject {}
index signature
[key: string]: any;
interface ImportOptions
interface ImportOptions {}
interface Index
interface Index {}
interface IndexNode
interface IndexNode<TDims extends MathNode[] = MathNode[]> extends MathNode {}
property dimensions
dimensions: [...TDims];
property dotNotation
dotNotation: boolean;
property isIndexNode
isIndexNode: true;
property type
type: 'IndexNode';
interface IndexNodeCtor
interface IndexNodeCtor {}
construct signature
new <TDims extends MathNode[] = MathNode[]>(dimensions: [...TDims]): IndexNode;
construct signature
new <TDims extends MathNode[] = MathNode[]>( dimensions: [...TDims], dotNotation: boolean): IndexNode<TDims>;
interface LUDecomposition
interface LUDecomposition {}
interface MathJsChain
interface MathJsChain<TValue> {}
property apply
apply: MathJsChain<TValue>['mapSlices'];
Deprecated
backwards-compatibility old name of mapSlices
method abs
abs: <T extends unknown>(this: MathJsChain<T>) => MathJsChain<T>;
Calculate the absolute value of a number. For matrices, the function is evaluated element wise.
method acos
acos: <T extends number | BigNumber | Complex | MathCollection<any>>( this: MathJsChain<T>) => MathJsChain<T>;
Calculate the inverse cosine of a value. For matrices, the function is evaluated element wise.
method acosh
acosh: <T extends number | BigNumber | Complex | MathCollection<any>>( this: MathJsChain<T>) => MathJsChain<T>;
Calculate the hyperbolic arccos of a value, defined as acosh(x) = ln(sqrt(x^2 - 1) + x). For matrices, the function is evaluated element wise.
method acot
acot: <T extends number | BigNumber | Complex | MathCollection<any>>( this: MathJsChain<T>) => MathJsChain<T>;
Calculate the inverse cotangent of a value. For matrices, the function is evaluated element wise.
method acoth
acoth: <T extends number | BigNumber | Complex | MathCollection<any>>( this: MathJsChain<T>) => MathJsChain<T>;
Calculate the inverse hyperbolic tangent of a value, defined as acoth(x) = (ln((x+1)/x) + ln(x/(x-1))) / 2. For matrices, the function is evaluated element wise.
method acsc
acsc: <T extends number | BigNumber | Complex | MathCollection<any>>( this: MathJsChain<T>) => MathJsChain<T>;
Calculate the inverse cosecant of a value. For matrices, the function is evaluated element wise.
method acsch
acsch: <T extends number | BigNumber | Complex | MathCollection<any>>( this: MathJsChain<T>) => MathJsChain<T>;
Calculate the inverse hyperbolic cosecant of a value, defined as acsch(x) = ln(1/x + sqrt(1/x^2 + 1)). For matrices, the function is evaluated element wise.
method add
add: { <T extends unknown>(this: MathJsChain<T>, y: T): MathJsChain<T>; (this: MathJsChain<any>, y: any): MathJsChain<any>;};
Add two values, x + y. For matrices, the function is evaluated element wise.
Parameter y
Second value to add
method and
and: ( this: MathJsChain< number | BigNumber | bigint | Complex | Unit | MathCollection >, y: number | BigNumber | bigint | Complex | Unit | MathCollection) => MathJsChain<boolean | MathCollection>;
Logical and. Test whether two values are both defined with a nonzero/nonempty value. For matrices, the function is evaluated element wise.
Parameter y
Second value to and
method arg
arg: { (this: MathJsChain<number | Complex>): MathJsChain<number>; (this: MathJsChain<BigNumber | Complex>): MathJsChain<BigNumber>; (this: MathJsChain<MathArray<any>>): MathJsChain<MathArray<any>>; (this: MathJsChain<Matrix<any>>): MathJsChain<Matrix<any>>;};
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.
method asec
asec: <T extends number | BigNumber | Complex | MathCollection<any>>( this: MathJsChain<T>) => MathJsChain<T>;
Calculate the inverse secant of a value. For matrices, the function is evaluated element wise.
method asech
asech: <T extends number | BigNumber | Complex | MathCollection<any>>( this: MathJsChain<T>) => MathJsChain<T>;
Calculate the hyperbolic arcsecant of a value, defined as asech(x) = ln(sqrt(1/x^2 - 1) + 1/x). For matrices, the function is evaluated element wise.
method asin
asin: <T extends number | BigNumber | Complex | MathCollection<any>>( this: MathJsChain<T>) => MathJsChain<T>;
Calculate the inverse sine of a value. For matrices, the function is evaluated element wise.
method asinh
asinh: <T extends number | BigNumber | Complex | MathCollection<any>>( this: MathJsChain<T>) => MathJsChain<T>;
Calculate the hyperbolic arcsine of a value, defined as asinh(x) = ln(x + sqrt(x^2 + 1)). For matrices, the function is evaluated element wise.
method atan
atan: <T extends number | BigNumber | Complex | MathCollection<any>>( this: MathJsChain<T>) => MathJsChain<T>;
Calculate the inverse tangent of a value. For matrices, the function is evaluated element wise.
method atan2
atan2: <T extends number | BigNumber | Complex | MathCollection<any>>( this: MathJsChain<T>, x: number) => MathJsChain<T>;
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.
method atanh
atanh: <T extends number | BigNumber | Complex | MathCollection<any>>( this: MathJsChain<T>) => MathJsChain<T>;
Calculate the hyperbolic arctangent of a value, defined as atanh(x) = ln((1 + x)/(1 - x)) / 2. For matrices, the function is evaluated element wise.
method bellNumbers
bellNumbers: { (this: MathJsChain<number>): MathJsChain<number>; (this: MathJsChain<BigNumber>): MathJsChain<BigNumber>;};
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
method bigint
bigint: { ( this: MathJsChain< number | string | Fraction | BigNumber | bigint | boolean | null > ): MathJsChain<bigint>; <T extends MathCollection<any>>(this: MathJsChain<T>): MathJsChain<T>;};
Create a bigint, which can store integers with arbitrary precision. When a matrix is provided, all elements will be converted to bigint.
method bignumber
bignumber: { ( this: MathJsChain< | number | string | Fraction | BigNumber | bigint | Unit | boolean | null > ): MathJsChain<BigNumber>; <T extends MathCollection<any>>(this: MathJsChain<T>): MathJsChain<T>;};
Create a BigNumber, which can store numbers with arbitrary precision. When a matrix is provided, all elements will be converted to BigNumber.
method bitAnd
bitAnd: <T extends number | bigint | BigNumber | MathCollection<any>>( this: MathJsChain<T>, y: number | BigNumber | bigint | MathCollection) => MathJsChain<NoLiteralType<T>>;
Bitwise AND two values, x & y. For matrices, the function is evaluated element wise.
Parameter y
Second value to and
method bitNot
bitNot: <T extends number | bigint | BigNumber | MathCollection<any>>( this: MathJsChain<T>) => MathJsChain<T>;
Bitwise NOT value, ~x. For matrices, the function is evaluated element wise. For units, the function is evaluated on the best prefix base.
method bitOr
bitOr: <T extends number | bigint | BigNumber | MathCollection<any>>( this: MathJsChain<T>, y: T) => MathJsChain<T>;
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.
Parameter y
Second value to or
method bitXor
bitXor: <T extends number | bigint | BigNumber | MathCollection<any>>( this: MathJsChain<T>, y: number | BigNumber | bigint | MathCollection) => MathJsChain<NoLiteralType<T>>;
Bitwise XOR two values, x ^ y. For matrices, the function is evaluated element wise.
Parameter y
Second value to xor
method boolean
boolean: { (this: MathJsChain<string | number | boolean | null>): MathJsChain<boolean>; (this: MathJsChain<MathCollection<any>>): MathJsChain<MathCollection<any>>;};
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.
method catalan
catalan: { (this: MathJsChain<number>): MathJsChain<number>; (this: MathJsChain<BigNumber>): MathJsChain<BigNumber>;};
The Catalan Numbers enumerate combinatorial structures of many different types. catalan only takes integer arguments. The following condition must be enforced: n >= 0
method cbrt
cbrt: <T extends number | BigNumber | Complex | Unit>( this: MathJsChain<T>, allRoots?: boolean) => MathJsChain<T>;
Calculate the cubic root of a value. For matrices, the function is evaluated element wise.
Parameter allRoots
Optional, 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.
method ceil
ceil: { <T extends unknown>( this: MathJsChain<T>, n?: number | BigNumber | MathCollection ): MathJsChain<T>; <U extends MathCollection<any>>( this: MathJsChain<any>, n: U ): MathJsChain<U>; (this: MathJsChain<Unit>, unit: Unit): MathJsChain<Unit>; <U extends MathCollection<Unit>>( this: MathJsChain<U>, unit: Unit ): MathJsChain<U>; ( this: MathJsChain<Unit>, n: number | BigNumber, unit: Unit ): MathJsChain<Unit>; <U extends MathCollection<Unit>>( this: MathJsChain<U>, n: number | BigNumber, unit: Unit ): MathJsChain<U>;};
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.
Parameter n
Number of decimals Default value: 0.
method clone
clone: <TValue>(this: MathJsChain<TValue>) => MathJsChain<TValue>;
Clone an object.
method combinations
combinations: <T extends number | BigNumber>( n: MathJsChain<T>, k: number | BigNumber) => MathJsChain<NoLiteralType<T>>;
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.
Parameter k
Number of objects in the subset
method compare
compare: ( this: MathJsChain<MathType | string>, y: MathType | string) => MathJsChain<number | BigNumber | Fraction | MathCollection>;
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.
Parameter y
Second value to compare
method compareNatural
compareNatural: (this: MathJsChain<any>, y: any) => MathJsChain<number>;
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.
Parameter y
Second value to compare
method compareText
compareText: ( this: MathJsChain<string | MathCollection>, y: string | MathCollection) => MathJsChain<number | MathCollection>;
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.
Parameter y
Second string to compare
method compile
compile: (this: MathJsChain<MathExpression>) => MathJsChain<EvalFunction>;
Parse and compile an expression. Returns a an object with a function evaluate([scope]) to evaluate the compiled expression.
method complex
complex: { ( this: MathJsChain<Complex | string | PolarCoordinates>, im?: number ): MathJsChain<Complex>; (this: MathJsChain<MathCollection<any>>): MathJsChain<MathCollection<any>>;};
Create a complex value or convert a value to a complex value.
Parameter im
Argument specifying the imaginary part of the complex number
method composition
composition: <T extends number | BigNumber>( this: MathJsChain<T>, k: number | BigNumber) => MathJsChain<NoLiteralType<T>>;
The composition counts of n into k parts. Composition only takes integer arguments. The following condition must be enforced: k <= n.
Parameter k
Number of objects in the subset
method concat
concat: ( this: MathJsChain<Array<MathCollection | number | BigNumber>>) => MathJsChain<MathCollection>;
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.
method conj
conj: <T extends number | BigNumber | Complex | MathCollection<any>>( this: MathJsChain<T>) => MathJsChain<NoLiteralType<T>>;
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.
method cos
cos: <T extends number | BigNumber | Complex | MathCollection<any>>( this: MathJsChain<T>) => MathJsChain<T>;
Calculate the cosine of a value. For matrices, the function is evaluated element wise.
method cosh
cosh: <T extends number | BigNumber | Complex | MathCollection<any>>( this: MathJsChain<T>) => MathJsChain<T>;
Calculate the hyperbolic cosine of a value, defined as cosh(x) = 1/2 * (exp(x) + exp(-x)). For matrices, the function is evaluated element wise.
method cot
cot: <T extends number | BigNumber | Complex | MathCollection<any>>( this: MathJsChain<T>) => MathJsChain<T>;
Calculate the cotangent of a value. cot(x) is defined as 1 / tan(x). For matrices, the function is evaluated element wise.
method coth
coth: <T extends number | BigNumber | Complex | MathCollection<any>>( this: MathJsChain<T>) => MathJsChain<T>;
Calculate the hyperbolic cotangent of a value, defined as coth(x) = 1 / tanh(x). For matrices, the function is evaluated element wise.
method count
count: { (this: MathJsChain<MathCollection>): MathJsChain<number>; (this: MathJsChain<string>): MathJsChain<number>;};
Count the number of elements of a matrix, array or string.
method createUnit
createUnit: { ( this: MathJsChain<string>, definition?: string | UnitDefinition | Unit, options?: CreateUnitOptions ): MathJsChain<Unit>; ( this: MathJsChain<Record<string, string | Unit | UnitDefinition>>, options?: CreateUnitOptions ): MathJsChain<Unit>;};
Create a user-defined unit and register it with the Unit type.
Parameter definition
Definition of the unit in terms of existing units. For example, ‘0.514444444 m / s’.
Parameter options
(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.
Create a user-defined unit and register it with the Unit type.
Parameter options
(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.
method cross
cross: ( this: MathJsChain<MathCollection>, y: MathCollection) => MathJsChain<MathCollection>;
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 * b2 - a2 * b1 ]
Parameter y
Second vector
method csc
csc: <T extends number | BigNumber | Complex | MathCollection<any>>( this: MathJsChain<T>) => MathJsChain<T>;
Calculate the cosecant of a value, defined as csc(x) = 1/sin(x). For matrices, the function is evaluated element wise.
method csch
csch: <T extends number | BigNumber | Complex | MathCollection<any>>( this: MathJsChain<T>) => MathJsChain<T>;
Calculate the hyperbolic cosecant of a value, defined as csch(x) = 1 / sinh(x). For matrices, the function is evaluated element wise.
method cube
cube: <T extends unknown>(this: MathJsChain<T>) => MathJsChain<T>;
Compute the cube of a value, x * x * x. For matrices, the function is evaluated element wise.
method deepEqual
deepEqual: (this: MathJsChain<MathType>, y: MathType) => MathJsChain<MathType>;
Test element wise whether two matrices are equal. The function accepts both matrices and scalar values.
Parameter y
Second amtrix to compare
method derivative
derivative: ( this: MathJsChain<MathNode | string>, variable: MathNode | string, options?: { simplify: boolean }) => MathJsChain<MathNode>;
Parameter variable
The variable over which to differentiate
Parameter options
There is one option available, simplify, which is true by default. When false, output will not be simplified.
method det
det: (this: MathJsChain<MathCollection>) => MathJsChain<number>;
Calculate the determinant of a matrix.
method diag
diag: { (this: MathJsChain<MathCollection>, format?: string): MathJsChain<Matrix>; ( this: MathJsChain<MathCollection<any>>, k: number | BigNumber, format?: string ): MathJsChain<MathCollection<any>>;};
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.
Parameter k
The diagonal where the vector will be filled in or retrieved. Default value: 0.
Parameter format
The matrix storage format. Default value: 'dense'.
method distance
distance: ( this: MathJsChain<MathCollection | object>, y: MathCollection | object) => MathJsChain<number | BigNumber>;
Calculates: The eucledian 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)
Parameter y
Coordinates of the second point
method divide
divide: { (this: MathJsChain<Unit>, y: Unit): MathJsChain<Unit | number>; (this: MathJsChain<Unit>, y: number): MathJsChain<Unit>; (this: MathJsChain<number>, y: number): MathJsChain<number>; (this: MathJsChain<any>, y: any): MathJsChain<any>;};
Divide two values, x / y. To divide matrices, x is multiplied with the inverse of y: x * inv(y).
Parameter y
Denominator
method done
done: () => TValue;
method dot
dot: ( this: MathJsChain<MathCollection>, y: MathCollection) => MathJsChain<number>;
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
Parameter y
Second vector
method dotDivide
dotDivide: { <T extends MathCollection<any>>( this: MathJsChain<T>, y: MathType ): MathJsChain<T>; <T extends MathCollection<any>>( this: MathJsChain<any>, y: T ): MathJsChain<T>; (this: MathJsChain<Unit>, y: any): MathJsChain<Unit>; (this: MathJsChain<any>, y: Unit): MathJsChain<Unit>; (this: MathJsChain<any>, y: any): MathJsChain<any>;};
Divide two matrices element wise. The function accepts both matrices and scalar values.
Parameter y
Denominator
method dotMultiply
dotMultiply: { <T extends MathCollection<any>>( this: MathJsChain<T>, y: MathType ): MathJsChain<T>; <T extends MathCollection<any>>( this: MathJsChain<any>, y: T ): MathJsChain<T>; (this: MathJsChain<Unit>, y: any): MathJsChain<Unit>; (this: MathJsChain<any>, y: Unit): MathJsChain<Unit>; (this: MathJsChain<any>, y: any): MathJsChain<any>;};
Multiply two matrices element wise. The function accepts both matrices and scalar values.
Parameter y
Right hand value
method dotPow
dotPow: <T extends unknown>(this: MathJsChain<T>, y: MathType) => MathJsChain<T>;
Calculates the power of x to y element wise.
Parameter y
The exponent
method equal
equal: ( this: MathJsChain<MathType | string>, y: MathType | string) => MathJsChain<boolean | MathCollection>;
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.
Parameter y
Second value to compare
method equalText
equalText: ( this: MathJsChain<string | MathCollection>, y: string | MathCollection) => MathJsChain<number | MathCollection>;
Check equality of two strings. Comparison is case sensitive. For matrices, the function is evaluated element wise.
Parameter y
Second string to compare
method erf
erf: <T extends number | MathCollection<any>>( this: MathJsChain<T>) => MathJsChain<NoLiteralType<T>>;
Compute the erf function of a value using a rational Chebyshev approximations for different intervals of x.
method evaluate
evaluate: { ( this: MathJsChain<MathExpression | Matrix>, scope?: object ): MathJsChain<any>; (this: MathJsChain<MathExpression[]>, scope?: object): MathJsChain<any[]>;};
Evaluate an expression.
Parameter scope
Scope to read/write variables
method exp
exp: <T extends number | BigNumber | Complex>( this: MathJsChain<T>) => MathJsChain<T>;
Calculate the exponent of a value. For matrices, the function is evaluated element wise.
method expm
expm: (this: MathJsChain<Matrix>) => MathJsChain<Matrix>;
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.
method expm1
expm1: <T extends number | BigNumber | Complex>( this: MathJsChain<T>) => MathJsChain<T>;
Calculate the value of subtracting 1 from the exponential value. For matrices, the function is evaluated element wise.
method factorial
factorial: <T extends number | BigNumber | MathCollection<any>>( n: MathJsChain<T>) => MathJsChain<NoLiteralType<T>>;
Compute the factorial of a value Factorial only supports an integer value as argument. For matrices, the function is evaluated element wise.
method filter
filter: ( this: MathJsChain<MathCollection | string[]>, test: | RegExp | (( value: any, index: number[], matrix: MathCollection | string[] ) => boolean)) => MathJsChain<MathCollection>;
Filter the items in an array or one dimensional matrix.
method fix
fix: { <T extends unknown>( this: MathJsChain<T>, n?: number | BigNumber | MathCollection ): MathJsChain<T>; <U extends MathCollection<any>>( this: MathJsChain<any>, n: U ): MathJsChain<U>; (this: MathJsChain<Unit>, unit: Unit): MathJsChain<Unit>; <U extends MathCollection<Unit>>( this: MathJsChain<U>, unit: Unit ): MathJsChain<U>; ( this: MathJsChain<Unit>, n: number | BigNumber, unit: Unit ): MathJsChain<Unit>; <U extends MathCollection<Unit>>( this: MathJsChain<U>, n: number | BigNumber, unit: Unit ): MathJsChain<U>;};
Round a value towards zero. For matrices, the function is evaluated element wise.
Parameter n
Number of decimals Default value: 0.
method flatten
flatten: <T extends MathCollection<any>>(x: MathJsChain<T>) => MathJsChain<T>;
Flatten a multi dimensional matrix into a single dimensional matrix.
method floor
floor: { <T extends unknown>( this: MathJsChain<T>, n?: number | BigNumber | MathCollection ): MathJsChain<T>; <U extends MathCollection<any>>( this: MathJsChain<any>, n: U ): MathJsChain<U>; (this: MathJsChain<Unit>, unit: Unit): MathJsChain<Unit>; <U extends MathCollection<Unit>>( this: MathJsChain<U>, unit: Unit ): MathJsChain<U>; ( this: MathJsChain<Unit>, n: number | BigNumber, unit: Unit ): MathJsChain<Unit>; <U extends MathCollection<Unit>>( this: MathJsChain<U>, n: number | BigNumber, unit: Unit ): MathJsChain<U>;};
Round a value towards minus infinity. For matrices, the function is evaluated element wise.
Parameter n
Number of decimals Default value: 0.
method forEach
forEach: <T extends MathCollection<any>>( this: MathJsChain<T>, callback: (value: any, index: number[], matrix: T) => void) => void;
Iterate over all elements of a matrix/array, and executes the given callback function.
method format
format: ( this: MathJsChain<any>, value: any, options?: number | FormatOptions | ((item: any) => string), callback?: (value: any) => string) => MathJsChain<string>;
Format a value of any type into a string.
Parameter options
An object with formatting options.
Parameter callback
A 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.
See Also
http://mathjs.org/docs/reference/functions/format.html
method fraction
fraction: { ( this: MathJsChain< | number | string | BigNumber | bigint | Unit | Fraction | FractionDefinition >, denominator?: number ): MathJsChain<Fraction>; (this: MathJsChain<MathCollection<any>>): MathJsChain<MathCollection<any>>;};
Create a fraction convert a value to a fraction.
Parameter denominator
Argument specifying the denominator of the fraction
method freqz
freqz: <T extends number | MathArray<any> | MathArray<any>[]>( this: MathJsChain<T>, a: T, w?: T | number) => MathJsChain<{ w: T; h: T }>;
Calculates the frequency response of a filter given its numerator and denominator coefficients.
method gamma
gamma: <T extends number | BigNumber | Complex | MathCollection<any>>( n: MathJsChain<T>) => MathJsChain<NoLiteralType<T>>;
Compute the gamma function of a value using Lanczos approximation for small values, and an extended Stirling approximation for large values. For matrices, the function is evaluated element wise.
method gcd
gcd: <T extends unknown>(this: MathJsChain<T[]>, ...args: T[]) => MathJsChain<T>;
Calculate the greatest common divisor for two or more values or arrays. For matrices, the function is evaluated element wise.
method help
help: (this: MathJsChain<unknown>) => MathJsChain<unknown>;
Retrieve help on a function or data type. Help files are retrieved from the documentation in math.expression.docs.
method hypot
hypot: <T extends number | BigNumber>(this: MathJsChain<T[]>) => MathJsChain<T>;
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.
method identity
identity: { ( this: MathJsChain<number | number[] | MathCollection>, format?: string ): MathJsChain<MathCollection | number>; (this: MathJsChain<number>, n: number, format?: string): MathJsChain< number | MathCollection<any> >;};
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.
Parameter format
The Matrix storage format
Parameter n
The y dimension for the matrix
Parameter format
The Matrix storage format
method im
im: { (this: MathJsChain<number | Complex>): MathJsChain<number>; (this: MathJsChain<BigNumber>): MathJsChain<BigNumber>; (this: MathJsChain<MathCollection<any>>): MathJsChain<MathCollection<any>>;};
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.
method index
index: (this: MathJsChain<any[]>) => MathJsChain<Index>;
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.
method intersect
intersect: ( this: MathJsChain<MathCollection>, x: MathCollection, y: MathCollection, z?: MathCollection) => MathJsChain<MathArray>;
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.
Parameter x
Co-ordinates of second end-point of first line
Parameter y
Co-ordinates of first end-point of second line OR Coefficients of the plane's equation
Parameter z
Co-ordinates of second end-point of second line OR null if the calculation is for line and plane
method inv
inv: <T extends number | Complex | MathCollection<any>>( this: MathJsChain<T>) => MathJsChain<NoLiteralType<T>>;
Calculate the inverse of a square matrix.
method isInteger
isInteger: ( this: MathJsChain<number | BigNumber | bigint | Fraction | MathCollection>) => MathJsChain<boolean>;
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.
method isNaN
isNaN: ( this: MathJsChain<number | BigNumber | Fraction | MathCollection | Unit>) => MathJsChain<boolean>;
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.
method isNegative
isNegative: ( this: MathJsChain<number | BigNumber | Fraction | MathCollection | Unit>) => MathJsChain<boolean>;
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.
method isNumeric
isNumeric: (this: MathJsChain<any>) => MathJsChain<boolean>;
Test whether a value is a numeric value. The function is evaluated element-wise in case of Array or Matrix input.
method isPositive
isPositive: ( this: MathJsChain< number | BigNumber | bigint | Fraction | MathCollection | Unit >) => MathJsChain<boolean>;
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.
method isPrime
isPrime: ( this: MathJsChain<number | BigNumber | bigint | MathCollection>) => MathJsChain<boolean>;
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.
method isZero
isZero: (this: MathJsChain<MathType>) => MathJsChain<boolean>;
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.
method kldivergence
kldivergence: ( this: MathJsChain<MathCollection>, p: MathCollection) => MathJsChain<number>;
Calculate the Kullback-Leibler (KL) divergence between two distributions
Parameter p
Second vector
method kron
kron: ( this: MathJsChain<MathCollection>, y: MathCollection) => MathJsChain<Matrix>;
Calculate the Kronecker product of two matrices or vectors
Parameter y
Second vector
method larger
larger: ( this: MathJsChain<MathType | string>, y: MathType | string) => MathJsChain<boolean | MathCollection>;
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.
Parameter y
Second value to compare
method largerEq
largerEq: ( this: MathJsChain<MathType | string>, y: MathType | string) => MathJsChain<boolean | MathCollection>;
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.
Parameter y
Second value to vcompare
method lcm
lcm: <T extends number | BigNumber | MathCollection<any>>( this: MathJsChain<T>, b: T) => MathJsChain<T>;
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.
Parameter b
An integer number
method leafCount
leafCount: (this: MathJsChain<MathNode>) => MathJsChain<number>;
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, the5
; the unary factorial operator does not add a leaf. On the other hand, function symbols do add leaves, sosin(x)/cos(x)
has four leaves.
method leftShift
leftShift: <T extends number | bigint | BigNumber | MathCollection<any>>( this: MathJsChain<T>, y: number | BigNumber | bigint) => MathJsChain<NoLiteralType<T>>;
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.
Parameter y
Amount of shifts
method log
log: <T extends number | BigNumber | Complex | MathCollection<any>>( this: MathJsChain<T>, base?: number | BigNumber | Complex) => MathJsChain<NoLiteralType<T>>;
Calculate the logarithm of a value. For matrices, the function is evaluated element wise.
Parameter base
Optional base for the logarithm. If not provided, the natural logarithm of x is calculated. Default value: e.
method log10
log10: <T extends number | BigNumber | Complex | MathCollection<any>>( this: MathJsChain<T>) => MathJsChain<T>;
Calculate the 10-base of a value. This is the same as calculating log(x, 10). For matrices, the function is evaluated element wise.
method log1p
log1p: { ( this: MathJsChain<number>, base?: number | BigNumber | Complex ): MathJsChain<number>; ( this: MathJsChain<BigNumber>, base?: number | BigNumber | Complex ): MathJsChain<BigNumber>; ( this: MathJsChain<Complex>, base?: number | BigNumber | Complex ): MathJsChain<Complex>; ( this: MathJsChain<MathArray<any>>, base?: number | BigNumber | Complex ): MathJsChain<MathArray<any>>; ( this: MathJsChain<Matrix<any>>, base?: number | BigNumber | Complex ): MathJsChain<Matrix<any>>;};
Calculate the logarithm of a value+1. For matrices, the function is evaluated element wise.
method log2
log2: <T extends number | BigNumber | Complex | MathCollection<any>>( this: MathJsChain<T>) => MathJsChain<T>;
Calculate the 2-base of a value. This is the same as calculating log(x, 2). For matrices, the function is evaluated element wise.
method lsolve
lsolve: { (this: MathJsChain<Matrix>, b: MathCollection): MathJsChain<Matrix>; (this: MathJsChain<MathArray<any>>, b: MathCollection<any>): MathJsChain< MathArray<any> >;};
Solves the linear equation system by forwards substitution. Matrix must be a lower triangular matrix.
Parameter b
A column vector with the b values
method lup
lup: (this: MathJsChain<MathCollection>) => MathJsChain<LUDecomposition>;
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
method lusolve
lusolve: { ( this: MathJsChain<Matrix>, b: MathCollection, order?: number, threshold?: number ): MathJsChain<Matrix>; ( this: MathJsChain<MathArray<any>>, b: MathCollection<any>, order?: number, threshold?: number ): MathJsChain<MathArray<any>>; (this: MathJsChain<LUDecomposition>, b: MathCollection<any>): MathJsChain< Matrix<any> >;};
Solves the linear system A * x = b where A is an [n x n] matrix and b is a [n] column vector.
Parameter b
Column Vector
Parameter order
The Symbolic Ordering and Analysis order, see slu for details. Matrix must be a SparseMatrix
Parameter threshold
Partial pivoting threshold (1 for partial pivoting), see slu for details. Matrix must be a SparseMatrix.
method lyap
lyap: ( this: MathJsChain<MathCollection>, Q: MathCollection) => MathJsChain<MathCollection>;
Solves the Continuous-time Lyapunov equation AP+PA'=Q for P, where Q is a positive semidefinite matrix. https://en.wikipedia.org/wiki/Lyapunov_equation
Parameter Q
Matrix Q
Returns
Matrix P solution to the Continuous-time Lyapunov equation AP+PA'=Q
method mad
mad: (this: MathJsChain<MathCollection>) => MathJsChain<any>;
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.
method map
map: <T extends MathCollection<any>>( this: MathJsChain<T>, callback: (value: any, index: number[], matrix: T) => MathType | string) => MathJsChain<T>;
Iterate over all elements of a matrix/array, and executes the given callback function.
Parameter callback
The callback function is invoked with three parameters: the value of the element, the index of the element, and the Matrix/array being traversed.
method mapSlices
mapSlices: <T extends MathCollection<any>>( this: MathJsChain<T>, dim: number, callback: (array: Array<MathType> | Matrix) => number) => MathJsChain<T>;
Apply a function that maps an array to a scalar along a given axis of the matrix or array. Returns a new matrix or array with one less dimension than the input.
Parameter dim
The dimension along which the callback is applied
Parameter callback
The callback function that is applied. This Function should take an array or 1-d matrix as an input and return a number.
Returns
The residual matrix with the function applied over some dimension.
method matrix
matrix: ( this: MathJsChain<MathCollection>, format?: 'sparse' | 'dense', dataType?: string) => MathJsChain<Matrix>;
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'.
method max
max: { (this: MathJsChain<MathType[]>, dim?: number): MathJsChain<any>; (this: MathJsChain<MathCollection<any>>, dim?: number): MathJsChain<any>;};
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.
Parameter dim
The maximum over the selected dimension
method mean
mean: { (this: MathJsChain<MathType[]>, dim?: number): MathJsChain<any>; (this: MathJsChain<MathCollection<any>>, dim?: number): MathJsChain<any>;};
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.
Parameter dim
The mean over the selected dimension
method median
median: { (this: MathJsChain<MathType[]>, dim?: number): MathJsChain<any>; (this: MathJsChain<MathCollection<any>>, dim?: number): MathJsChain<any>;};
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.
method min
min: { (this: MathJsChain<MathType[]>): MathJsChain<MathType[]>; (this: MathJsChain<MathCollection<any>>, dim?: number): MathJsChain<any>;};
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.
Parameter dim
The minimum over the selected dimension
method mod
mod: <T extends unknown>( this: MathJsChain<T>, y: number | BigNumber | bigint | Fraction | MathCollection) => MathJsChain<NoLiteralType<T>>;
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)
Parameter y
Divisor
See Also
http://en.wikipedia.org/wiki/Modulo_operation.
method mode
mode: (this: MathJsChain<MathType[]>) => MathJsChain<MathType[]>;
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.
method multinomial
multinomial: <T extends number | BigNumber>( a: MathJsChain<T[]>) => MathJsChain<NoLiteralType<T>>;
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
method multiply
multiply: { <T extends MathCollection<any>>( this: MathJsChain<T>, y: MathType ): MathJsChain<T>; (this: MathJsChain<Unit>, y: Unit): MathJsChain<Unit>; (this: MathJsChain<number>, y: number): MathJsChain<number>; (this: MathJsChain<any>, y: any): MathJsChain<any>;};
Multiply two values, x * y. The result is squeezed. For matrices, the matrix product is calculated.
Parameter y
The second value to multiply
method norm
norm: ( this: MathJsChain<number | BigNumber | Complex | MathCollection>, p?: number | BigNumber | string) => MathJsChain<number | BigNumber>;
Calculate the norm of a number, vector or matrix. The second parameter p is optional. If not provided, it defaults to 2.
Parameter p
Vector space. Supported numbers include Infinity and -Infinity. Supported strings are: 'inf', '-inf', and 'fro' (The Frobenius norm) Default value: 2.
method not
not: ( this: MathJsChain< number | BigNumber | bigint | Complex | Unit | MathCollection >) => MathJsChain<boolean | MathCollection>;
Logical not. Flips boolean value of a given parameter. For matrices, the function is evaluated element wise.
method nthRoot
nthRoot: ( this: MathJsChain<number | BigNumber | MathCollection | Complex>, root?: number | BigNumber) => MathJsChain<number | Complex | MathCollection>;
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.
Parameter root
The root. Default value: 2.
method number
number: { ( this: MathJsChain< | string | number | BigNumber | bigint | Fraction | boolean | Unit | null >, valuelessUnit?: Unit | string ): MathJsChain<number>; ( this: MathJsChain<MathCollection<any>>, valuelessUnit?: string | Unit ): MathJsChain<MathCollection<any>>;};
Create a number or convert a string, boolean, or unit to a number. When value is a matrix, all elements will be converted to number.
Parameter valuelessUnit
A valueless unit, used to convert a unit to a number
method numeric
numeric: { ( this: MathJsChain<string | number | BigNumber | bigint | Fraction>, outputType: 'number' ): MathJsChain<number>; (this: MathJsChain<any>, outputType: 'BigNumber'): MathJsChain<BigNumber>; (this: MathJsChain<any>, outputType: 'bigint'): MathJsChain<bigint>; (this: MathJsChain<any>, outputType: 'Fraction'): MathJsChain<Fraction>;};
Convert a numeric input to a specific numeric type: number, BigNumber, bigint, or Fraction.
Parameter outputType
The desired numeric output type
method ones
ones: ( this: MathJsChain<number | number[] | BigNumber | BigNumber[]>, format?: string) => MathJsChain<MathCollection>;
Create a matrix filled with ones. The created matrix can have one or multiple dimensions.
Parameter format
The matrix storage format
method or
or: ( this: MathJsChain< number | BigNumber | bigint | Complex | Unit | MathCollection >, y: number | BigNumber | bigint | Complex | Unit | MathCollection) => MathJsChain<boolean | MathCollection>;
Logical or. Test if at least one value is defined with a nonzero/nonempty value. For matrices, the function is evaluated element wise.
Parameter y
Second value to or
method parse
parse: { (this: MathJsChain<MathExpression[]>, options?: any): MathJsChain< MathNode[] >; (this: MathJsChain<MathExpression>, options?: any): MathJsChain<MathNode>;};
Parameter options
Available options: nodes - a set of custome nodes
Parse an expression. Returns a node tree, which can be evaluated by invoking node.evaluate();
Parameter options
Available options: nodes - a set of custome nodes
method partitionSelect
partitionSelect: ( this: MathJsChain<MathCollection>, k: number, compare?: 'asc' | 'desc' | ((a: any, b: any) => number)) => MathJsChain<MathCollection>;
Partition-based selection of an array or 1D matrix. Will find the kth smallest value, and mutates the input array. Uses Quickselect.
Parameter k
The kth smallest value to be retrieved; zero-based index
Parameter compare
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'.
method permutations
permutations: <T extends number | BigNumber>( n: MathJsChain<T>, k?: number | BigNumber) => MathJsChain<NoLiteralType<T>>;
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.
Parameter k
The number of objects in the subset
method pickRandom
pickRandom: { <T>(this: MathJsChain<T[]>): MathJsChain<T>; <T>(this: MathJsChain<T[]>, number: number): MathJsChain<T[]>; <T>(this: MathJsChain<T[]>, number: number, weights: number[]): MathJsChain< T[] >;};
Random pick a value from a one dimensional array. Array element is picked using a random function with uniform distribution.
Parameter number
An int or float
Parameter weights
An array of ints or floats
method pow
pow: ( this: MathJsChain<MathType>, y: number | BigNumber | bigint | Complex) => MathJsChain<MathType>;
Calculates the power of x to y, x ^ y. Matrix exponentiation is supported for square matrices x, and positive integer exponents y.
Parameter y
The exponent
method print
print: ( this: MathJsChain<string>, values: any, precision?: number, options?: number | object) => MathJsChain<string>;
Interpolate values into a string template.
Parameter values
An object containing variables which will be filled in in the template.
Parameter precision
Number of digits to format numbers. If not provided, the value will not be rounded.
Parameter options
Formatting options, or the number of digits to format numbers. See function math.format for a description of all options.
method prod
prod: (this: MathJsChain<MathType[]>) => MathJsChain<any>;
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.
method qr
qr: (this: MathJsChain<MathCollection>) => MathJsChain<QRDecomposition>;
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.
method quantileSeq
quantileSeq: ( A: MathJsChain<MathCollection>, prob: number | BigNumber | MathArray, sorted?: boolean) => MathJsChain<number | BigNumber | Unit | MathArray>;
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.
Parameter probOrN
prob is the order of the quantile, while N is the amount of evenly distributed steps of probabilities; only one of these options can be provided
Parameter sorted
=false is data sorted in ascending order
method random
random: { (this: MathJsChain<number>, max?: number): MathJsChain<number>; <T extends MathCollection<any>>( this: MathJsChain<T>, min?: number, max?: number ): MathJsChain<T>;};
Return a random number larger or equal to min and smaller than max using a uniform distribution.
Parameter min
Minimum boundary for the random value, included
Parameter max
Maximum boundary for the random value, excluded
method randomInt
randomInt: { <T extends MathCollection<any>>( this: MathJsChain<T>, max?: number ): MathJsChain<T>; <T extends MathCollection<any>>( this: MathJsChain<T>, max?: number ): MathJsChain<T>; <T extends MathCollection<any>>( this: MathJsChain<T>, min: number, max: number ): MathJsChain<T>;};
Return a random integer number larger or equal to min and smaller than max using a uniform distribution.
Parameter min
Minimum boundary for the random value, included
Parameter max
Maximum boundary for the random value, excluded
method range
range: { (this: MathJsChain<string>, includeEnd?: boolean): MathJsChain<Matrix>; ( this: MathJsChain<number | BigNumber>, end: number | BigNumber, includeEnd?: boolean ): MathJsChain<Matrix<any>>; ( this: MathJsChain<number | BigNumber | Unit>, end: number | BigNumber | Unit, step: number | BigNumber | Unit, includeEnd?: boolean ): MathJsChain<Matrix<any>>;};
Create an array from a range. By default, the range end is excluded. This can be customized by providing an extra parameter includeEnd.
Parameter end
End of the range, excluded by default, included when parameter includeEnd=true
Parameter step
Step size. Default value is 1.
Parameter includeEnd
: Option to specify whether to include the end or not. False by default
method rationalize
rationalize: ( this: MathJsChain<MathNode | string>, optional?: object | boolean, detailed?: boolean) => MathJsChain<MathNode>;
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.
Parameter optional
scope of expression or true for already evaluated rational expression at input
Parameter detailed
optional True if return an object, false if return expression node (default)
method re
re: { (this: MathJsChain<number | Complex>): MathJsChain<number>; (this: MathJsChain<BigNumber>): MathJsChain<BigNumber>; (this: MathJsChain<MathCollection<any>>): MathJsChain<MathCollection<any>>;};
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.
method reshape
reshape: <T extends MathCollection<any>>( this: MathJsChain<T>, sizes: number[]) => MathJsChain<T>;
Reshape a multi dimensional array to fit the specified dimensions
Parameter sizes
One dimensional array with integral sizes for each dimension
method resize
resize: <T extends MathCollection<any>>( this: MathJsChain<T>, size: MathCollection, defaultValue?: number | string) => MathJsChain<T>;
Resize a matrix
Parameter size
One dimensional array with numbers
Parameter defaultValue
Zero by default, except in case of a string, in that case defaultValue = ' ' Default value: 0.
method resolve
resolve: { ( this: MathJsChain<MathNode>, scope?: Record<string, any> ): MathJsChain<MathNode>; (this: MathJsChain<MathNode[]>, scope?: Record<string, any>): MathJsChain< MathNode[] >;};
Replaces variable nodes with their scoped values
Parameter scope
Scope to read/write variables
method rightArithShift
rightArithShift: <T extends number | bigint | BigNumber | MathCollection<any>>( this: MathJsChain<T>, y: number | BigNumber | bigint) => MathJsChain<NoLiteralType<T>>;
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.
Parameter y
Amount of shifts
method rightLogShift
rightLogShift: <T extends number | MathCollection<any>>( this: MathJsChain<T>, y: number) => MathJsChain<NoLiteralType<T>>;
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.
Parameter y
Amount of shifts
method round
round: { <T extends unknown>( this: MathJsChain<T>, n?: number | BigNumber | MathCollection ): MathJsChain<T>; <U extends MathCollection<any>>( this: MathJsChain<any>, n: U ): MathJsChain<U>; (this: MathJsChain<Unit>, unit: Unit): MathJsChain<Unit>; <U extends MathCollection<Unit>>( this: MathJsChain<U>, unit: Unit ): MathJsChain<U>; ( this: MathJsChain<Unit>, n: number | BigNumber, unit: Unit ): MathJsChain<Unit>; <U extends MathCollection<Unit>>( this: MathJsChain<U>, n: number | BigNumber, unit: Unit ): MathJsChain<U>;};
Round a value towards the nearest integer. For matrices, the function is evaluated element wise.
Parameter n
Number of decimals Default value: 0.
method schur
schur: (this: MathJsChain<MathCollection>) => SchurDecomposition;
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
Returns
Object containing both matrix U and T of the Schur Decomposition A=UTU'
method sec
sec: <T extends number | BigNumber | Complex | MathCollection<any>>( this: MathJsChain<T>) => MathJsChain<T>;
Calculate the secant of a value, defined as sec(x) = 1/cos(x). For matrices, the function is evaluated element wise.
method sech
sech: <T extends number | BigNumber | Complex | MathCollection<any>>( this: MathJsChain<T>) => MathJsChain<T>;
Calculate the hyperbolic secant of a value, defined as sech(x) = 1 / cosh(x). For matrices, the function is evaluated element wise.
method setCartesian
setCartesian: <T extends MathCollection<any>>( this: MathJsChain<T>, a2: MathCollection) => MathJsChain<T>;
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.
Parameter a2
A (multi)set
method setDifference
setDifference: <T extends MathCollection<any>>( this: MathJsChain<T>, a2: MathCollection) => MathJsChain<T>;
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
Parameter a2
A (multi)set
method setDistinct
setDistinct: <T extends MathCollection<any>>( a: MathJsChain<T>) => MathJsChain<T>;
Collect the distinct elements of a multiset. A multi-dimension array will be converted to a single-dimension array before the operation.
method setIntersect
setIntersect: <T extends MathCollection<any>>( this: MathJsChain<T>, a2: MathCollection) => MathJsChain<T>;
Create the intersection of two (multi)sets. Multi-dimension arrays will be converted to single-dimension arrays before the operation.
Parameter a2
A (multi)set
method setIsSubset
setIsSubset: ( this: MathJsChain<MathCollection>, a2: MathCollection) => MathJsChain<boolean>;
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.
Parameter a2
A (multi)set
method setMultiplicity
setMultiplicity: ( e: MathJsChain<MathNumericType>, a: MathCollection) => MathJsChain<number>;
Count the multiplicity of an element in a multiset. A multi-dimension array will be converted to a single-dimension array before the operation.
Parameter a
A multiset
method setPowerset
setPowerset: <T extends MathCollection<any>>( a: MathJsChain<T>) => MathJsChain<T>;
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.
method setSize
setSize: (this: MathJsChain<MathCollection>) => MathJsChain<number>;
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.
method setSymDifference
setSymDifference: <T extends MathCollection<any>>( this: MathJsChain<T>, a2: MathCollection) => MathJsChain<T>;
Create the symmetric difference of two (multi)sets. Multi-dimension arrays will be converted to single-dimension arrays before the operation.
Parameter a2
A (multi)set
method setUnion
setUnion: <T extends MathCollection<any>>( this: MathJsChain<T>, a2: MathCollection) => MathJsChain<T>;
Create the union of two (multi)sets. Multi-dimension arrays will be converted to single-dimension arrays before the operation.
Parameter a2
A (multi)set
method sign
sign: <T extends unknown>(this: MathJsChain<T>) => MathJsChain<T>;
Compute the sign of a value. The sign of a value x is: 1 when x > 1 -1 when x < 0 0 when x == 0 For matrices, the function is evaluated element wise.
Parameter x
The number for which to determine the sign
Returns
The sign of x
method simplify
simplify: ( this: MathJsChain<MathNode | string>, rules?: SimplifyRule[], scope?: Map<string, MathType> | object, options?: SimplifyOptions) => MathJsChain<MathNode>;
Simplify an expression tree.
Parameter rules
A list of rules are applied to an expression, repeating over the list until no further changes are made. It’s possible to pass a custom set of rules to the function as second argument. A rule can be specified as an object, string, or function.
Parameter scope
Scope to variables
Parameter options
Options to configure the behavior of simplify
method simplifyConstant
simplifyConstant: ( this: MathJsChain<MathNode | string>, options?: SimplifyOptions) => MathJsChain<MathNode>;
method simplifyCore
simplifyCore: ( this: MathJsChain<MathNode | string>, options?: SimplifyOptions) => MathJsChain<MathNode>;
method sin
sin: <T extends number | BigNumber | Complex | MathCollection<any>>( this: MathJsChain<T>) => MathJsChain<T>;
Calculate the sine of a value. For matrices, the function is evaluated element wise.
method sinh
sinh: <T extends number | BigNumber | Complex | MathCollection<any>>( this: MathJsChain<T>) => MathJsChain<T>;
Calculate the hyperbolic sine of a value, defined as sinh(x) = 1/2 * (exp(x) - exp(-x)). For matrices, the function is evaluated element wise.
method size
size: ( this: MathJsChain< boolean | number | Complex | Unit | string | MathCollection >) => MathJsChain<MathCollection>;
Calculate the size of a matrix or scalar.
method slu
slu: ( this: MathJsChain<Matrix>, order: number, threshold: number) => MathJsChain<SLUDecomposition>;
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
Parameter order
The Symbolic Ordering and Analysis order: 0 - Natural ordering, no permutation vector q is returned 1 - Matrix must be square, symbolic ordering and analisis 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.
Parameter threshold
Partial pivoting threshold (1 for partial pivoting)
method smaller
smaller: ( this: MathJsChain<MathType | string>, y: MathType | string) => MathJsChain<boolean | MathCollection>;
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.
Parameter y
Second value to vcompare
method smallerEq
smallerEq: ( this: MathJsChain<MathType | string>, y: MathType | string) => MathJsChain<boolean | MathCollection>;
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.
Parameter y
Second value to compare
method sort
sort: <T extends MathCollection<any>>( this: MathJsChain<T>, compare: 'asc' | 'desc' | 'natural' | ((a: any, b: any) => number)) => MathJsChain<T>;
Sort the items in a matrix
Parameter compare
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’
method sparse
sparse: ( this: MathJsChain<MathCollection>, dataType?: string) => MathJsChain<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.
Parameter dataType
Sparse Matrix data type
method splitUnit
splitUnit: (this: MathJsChain<Unit>, parts: Unit[]) => MathJsChain<Unit[]>;
Split a unit in an array of units whose sum is equal to the original unit.
Parameter parts
An array of strings or valueless units
method sqrt
sqrt: <T extends number | BigNumber | Complex | MathCollection<any> | Unit>( this: MathJsChain<T>) => MathJsChain<T>;
Calculate the square root of a value. For matrices, the function is evaluated element wise.
method sqrtm
sqrtm: <T extends MathCollection<any>>(A: MathJsChain<T>) => MathJsChain<T>;
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.
method square
square: <T extends unknown>(this: MathJsChain<T>) => MathJsChain<T>;
Compute the square of a value, x * x. For matrices, the function is evaluated element wise.
method squeeze
squeeze: <T extends MathCollection<any>>(x: MathJsChain<T>) => MathJsChain<T>;
Squeeze a matrix, remove inner and outer singleton dimensions from a matrix.
method std
std: { ( this: MathJsChain<number[]>, dim?: number, normalization?: 'unbiased' | 'uncorrected' | 'biased' ): MathJsChain<number>; ( this: MathJsChain<MathCollection<any>>, dimension?: number, normalization?: 'unbiased' | 'uncorrected' | 'biased' ): MathJsChain<number[]>; ( this: MathJsChain<MathCollection<any>>, normalization: 'unbiased' | 'uncorrected' | 'biased' ): MathJsChain<number>;};
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)
Parameter dim
A dimension to compute standard deviation.
Parameter normalization
Determines how to normalize the variance. Choose ‘unbiased’ (default), ‘uncorrected’, or ‘biased’. Default value: ‘unbiased’.
Returns
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)
Parameter normalization
Determines how to normalize the variance. Choose ‘unbiased’ (default), ‘uncorrected’, or ‘biased’. Default value: ‘unbiased’.
Returns
The standard deviation
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.
method stirlingS2
stirlingS2: <T extends number | BigNumber>( this: MathJsChain<T>, k: number | BigNumber) => MathJsChain<NoLiteralType<T>>;
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
Parameter k
Number of objects in the subset
method string
string: { ( this: MathJsChain<MathNumericType | string | Unit | null> ): MathJsChain<string>; (this: MathJsChain<MathCollection<any>>): MathJsChain<MathCollection<any>>;};
Create a string or convert any object into a string. Elements of Arrays and Matrices are processed element wise.
method subset
subset: <T extends string | MathCollection<any>>( this: MathJsChain<T>, index: Index, replacement?: any, defaultValue?: any) => MathJsChain<T>;
Get or set a subset of a matrix or string.
Parameter index
For each dimension, an index or list of indices to get or set
Parameter replacement
An array, matrix, or scalar. If provided, the subset is replaced with replacement. If not provided, the subset is returned
Parameter defaultValue
Default value, filled in on new entries when the matrix is resized. If not provided, math.matrix elements will be left undefined. Default value: undefined.
method subtract
subtract: <T extends unknown>(this: MathJsChain<T>, y: T) => MathJsChain<T>;
Subtract two values, x - y. For matrices, the function is evaluated element wise.
Parameter y
Value to subtract from x
method sum
sum: { ( this: MathJsChain<Array<number | BigNumber | Fraction>> ): MathJsChain<number>; (this: MathJsChain<MathCollection<any>>): MathJsChain<number>;};
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.
method symbolicEqual
symbolicEqual: ( this: MathJsChain<MathNode>, expr2: MathNode, options?: SimplifyOptions) => MathJsChain<boolean>;
Determines if two expressions are symbolically equal, i.e. one is the result of valid algebraic manipulations on the other.
Parameter expr2
The second expression to compare
Parameter options
Optional option object, passed to simplify
Returns
{boolean} Returns true if a valid manipulation making the expressions equal is found.
method tan
tan: <T extends number | BigNumber | Complex | MathCollection<any>>( this: MathJsChain<T>) => MathJsChain<T>;
Calculate the tangent of a value. tan(x) is equal to sin(x) / cos(x). For matrices, the function is evaluated element wise.
method tanh
tanh: <T extends number | BigNumber | Complex | MathCollection<any>>( this: MathJsChain<T>) => MathJsChain<T>;
Calculate the hyperbolic tangent of a value, defined as tanh(x) = (exp(2 * x) - 1) / (exp(2 * x) + 1). For matrices, the function is evaluated element wise.
method to
to: ( this: MathJsChain<Unit | MathCollection>, unit: Unit | string) => MathJsChain<Unit | MathCollection>;
Change the unit of a value. For matrices, the function is evaluated element wise.
Parameter unit
New unit. Can be a string like "cm" or a unit without value.
method trace
trace: (this: MathJsChain<MathCollection>) => MathJsChain<number>;
Calculate the trace of a matrix: the sum of the elements on the main diagonal of a square matrix.
method transpose
transpose: <T extends MathCollection<any>>(x: MathJsChain<T>) => MathJsChain<T>;
Transpose a matrix. All values of the matrix are reflected over its main diagonal. Only two dimensional matrices are supported.
method typeOf
typeOf: (this: MathJsChain<any>) => MathJsChain<string>;
Determine the type of a variable.
method unaryMinus
unaryMinus: <T extends unknown>(this: MathJsChain<T>) => MathJsChain<T>;
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.
method unaryPlus
unaryPlus: <T extends unknown>(this: MathJsChain<T>) => MathJsChain<T>;
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.
method unequal
unequal: ( this: MathJsChain<MathType | string>, y: MathType | string) => MathJsChain<boolean | MathCollection>;
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.
Parameter y
Second value to vcompare
method unit
unit: { (this: MathJsChain<string>, unit?: string): MathJsChain<Unit>; (this: MathJsChain<any>, unit?: string): MathJsChain<Unit>; (this: MathJsChain<MathCollection<any>>, unit?: string): MathJsChain<Unit[]>;};
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.
Parameter unit
The unit to be created
method usolve
usolve: { (this: MathJsChain<Matrix>, b: MathCollection): MathJsChain<Matrix>; (this: MathJsChain<MathArray<any>>, b: MathCollection<any>): MathJsChain< MathArray<any> >;};
Solves the linear equation system by backward substitution. Matrix must be an upper triangular matrix. U * x = b
Parameter b
A column vector with the b values
method variance
variance: { ( this: MathJsChain<Array<Array<number | BigNumber | Fraction>>> ): MathJsChain<number>; ( this: MathJsChain<MathCollection<any>>, dimension?: number, normalization?: 'unbiased' | 'uncorrected' | 'biased' ): MathJsChain<number[]>; ( this: MathJsChain<MathCollection<any>>, normalization: 'unbiased' | 'uncorrected' | 'biased' ): MathJsChain<number>;};
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 + 1) Note that older browser may not like the variable name var. In that case, the function can be called as math['var'](...) instead of math.variance(...).
Parameter dim
a dimension to compute variance.
Parameter normalization
normalization Determines how to normalize the variance. Choose ‘unbiased’ (default), ‘uncorrected’, or ‘biased’. Default value: ‘unbiased’.
Returns
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 + 1) Note that older browser may not like the variable name var. In that case, the function can be called as math['var'](...) instead of math.variance(...).
Parameter normalization
normalization Determines how to normalize the variance. Choose ‘unbiased’ (default), ‘uncorrected’, or ‘biased’. Default value: ‘unbiased’.
Returns
The variance
method xgcd
xgcd: ( this: MathJsChain<number | BigNumber>, b: number | BigNumber) => MathJsChain<MathArray>;
Calculate the extended greatest common divisor for two values. See http://en.wikipedia.org/wiki/Extended_Euclidean_algorithm.
Parameter b
An integer number
method xor
xor: ( this: MathJsChain< number | BigNumber | bigint | Complex | Unit | MathCollection >, y: number | BigNumber | bigint | Complex | Unit | MathCollection) => MathJsChain<boolean | MathCollection>;
Logical xor. Test whether one and only one value is defined with a nonzero/nonempty value. For matrices, the function is evaluated element wise.
Parameter y
Second value to xor
method zeros
zeros: ( this: MathJsChain<number | number[] | BigNumber | BigNumber[]>, format?: string) => MathJsChain<MathCollection>;
Create a matrix filled with zeros. The created matrix can have one or multiple dimensions.
Parameter format
The matrix storage format
Returns
A matrix filled with zeros
method zeta
zeta: <T extends number | BigNumber | Complex>( this: MathJsChain<T>) => MathJsChain<T>;
Compute the Riemann Zeta function of a value using an infinite series and Riemann's Functional equation.
method zpk2tf
zpk2tf: <T extends MathCollection<any>>( this: MathJsChain<T>, p: T, k?: number) => MathJsChain<T>;
Compute the transfer function of a zero-pole-gain model.
interface MathJsFactory
interface MathJsFactory {}
*********************************************************************** Factory and Dependencies **********************************************************************
property create
create: ( factories: FactoryFunctionMap, config?: ConfigOptions) => MathJsInstance;
property factory
factory: <T, TDeps extends readonly MathJsFunctionName[]>( name: string, dependencies: TDeps, create: ( injected: Pick< MathJsInstance, Extract<MathJsFunctionName, TDeps[number]> > ) => T, // eslint-disable-next-line @typescript-eslint/no-explicit-any meta?: any) => FactoryFunction<T>;
interface MathJsInstance
interface MathJsInstance extends MathJsFactory {}
property AccessorNode
AccessorNode: AccessorNodeCtor;
property apply
apply: MathJsInstance['mapSlices'];
Deprecated
backwards-compatibility old name of mapSlices
property ArrayNode
ArrayNode: ArrayNodeCtor;
property AssignmentNode
AssignmentNode: AssignmentNodeCtor;
property BlockNode
BlockNode: BlockNodeCtor;
property ConditionalNode
ConditionalNode: ConditionalNodeCtor;
property config
config: (options: ConfigOptions) => ConfigOptions;
Set configuration options for math.js, and get current options. Will emit a ‘config’ event, with arguments (curr, prev, changes).
Parameter options
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
Returns the current configuration
property ConstantNode
ConstantNode: ConstantNodeCtor;
property e
e: number;
property expression
expression: MathNode;
property FunctionAssignmentNode
FunctionAssignmentNode: FunctionAssignmentNodeCtor;
property FunctionNode
FunctionNode: FunctionNodeCtor;
property i
i: number;
property IndexNode
IndexNode: IndexNodeCtor;
property Infinity
Infinity: number;
property isArray
isArray: ArrayConstructor['isArray'];
property LN10
LN10: number;
property LN2
LN2: number;
property LOG10E
LOG10E: number;
property LOG2E
LOG2E: number;
property Matrix
Matrix: MatrixCtor;
property NaN
NaN: number;
property Node
Node: NodeCtor;
property ObjectNode
ObjectNode: ObjectNodeCtor;
property OperatorNode
OperatorNode: OperatorNodeCtor;
property ParenthesisNode
ParenthesisNode: ParenthesisNodeCtor;
property parse
parse: ParseFunction;
Parse an expression. Returns a node tree, which can be evaluated by invoking node.evaluate();
property phi
phi: number;
property pi
pi: number;
property RangeNode
RangeNode: RangeNodeCtor;
property RelationalNode
RelationalNode: RelationalNodeCtor;
property simplify
simplify: Simplify;
Simplify an expression tree.
Parameter expr
The expression to be simplified
Parameter rules
(optional) A list of rules are applied to an expression, repeating over the list until no further changes are made. It’s possible to pass a custom set of rules to the function as second argument. A rule can be specified as an object, string, or function.
Parameter scope
(optional) Scope to variables
Parameter options
(optional) An object with simplify options
Returns
Returns the simplified form of expr
property SQRT1_2
SQRT1_2: number;
property SQRT2
SQRT2: number;
property SymbolNode
SymbolNode: SymbolNodeCtor;
property tau
tau: number;
property typed
typed: ( name: string, // eslint-disable-next-line @typescript-eslint/no-explicit-any signatures: Record<string, (...args: any[]) => any> // eslint-disable-next-line @typescript-eslint/no-explicit-any) => (...args: any[]) => any;
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.
Parameter name
Optional name for the typed-function
Parameter signatures
Object with one or multiple function signatures
Returns
The created typed-function.
property uninitialized
uninitialized: any;
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.See Also
https://github.com/josdejong/mathjs/issues/2019
property Unit
Unit: UnitCtor;
property version
version: string;
method abs
abs: <T extends unknown>(x: T) => T;
Calculate the absolute value of a number. For matrices, the function is evaluated element wise.
Parameter x
A number or matrix for which to get the absolute value
Returns
Absolute value of x
method acos
acos: { (x: number): number | Complex; <T extends BigNumber | Complex>(x: T): T;};
Calculate the inverse cosine of a value.
Parameter x
Function input
Returns
The arc cosine of x
method acosh
acosh: { (x: number): number | Complex; <T extends BigNumber | Complex>(x: T): T;};
Calculate the hyperbolic arccos of a value, defined as acosh(x) = ln(sqrt(x^2 - 1) + x).
Parameter x
Function input
Returns
The hyperbolic arccosine of x
method acot
acot: { (x: number): number; <T extends BigNumber | Complex>(x: T): T };
Calculate the inverse cotangent of a value.
Parameter x
Function input
Returns
The arc cotangent of x
method acoth
acoth: { (x: number): number; <T extends BigNumber | Complex>(x: T): T };
Calculate the inverse hyperbolic tangent of a value, defined as acoth(x) = (ln((x+1)/x) + ln(x/(x-1))) / 2.
Parameter x
Function input
Returns
The inverse hyperbolic tangent of x
method acsc
acsc: { (x: number): number | Complex; <T extends BigNumber | Complex>(x: T): T;};
Calculate the inverse cosecant of a value.
Parameter x
Function input
Returns
The arc cosecant of x
method acsch
acsch: { (x: number): number; <T extends BigNumber | Complex>(x: T): T };
Calculate the inverse hyperbolic cosecant of a value, defined as acsch(x) = ln(1/x + sqrt(1/x^2 + 1)).
Parameter x
Function input
Returns
The inverse hyperbolic cosecant of x
method add
add: { <T extends unknown>(x: T, y: T): T; <T extends unknown>(...values: T[]): T; (x: any, y: any): any; (...values: any[]): any;};
Add two values, x + y. For matrices, the function is evaluated element wise.
Parameter x
First value to add
Parameter y
Second value to add
Returns
Sum of x and y
method and
and: ( x: number | BigNumber | bigint | Complex | Unit | MathCollection, y: number | BigNumber | bigint | Complex | Unit | MathCollection) => boolean | MathCollection;
Logical and. Test whether two values are both defined with a nonzero/nonempty value. For matrices, the function is evaluated element wise.
Parameter x
First value to and
Parameter y
Second value to and
Returns
Returns true when both inputs are defined with a nonzero/nonempty value.
method arg
arg: { (x: number | Complex): number; (x: BigNumber | Complex): BigNumber; <T extends MathCollection<any>>(x: T): T;};
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.
Parameter x
A complex number or array with complex numbers
Returns
The argument of x
method asec
asec: { (x: number): number | Complex; <T extends BigNumber | Complex>(x: T): T;};
Calculate the inverse secant of a value.
Parameter x
Function input
Returns
The arc secant of x
method asech
asech: { (x: number): number | Complex; <T extends BigNumber | Complex>(x: T): T;};
Calculate the hyperbolic arcsecant of a value, defined as asech(x) = ln(sqrt(1/x^2 - 1) + 1/x).
Parameter x
Function input
Returns
The hyperbolic arcsecant of x
method asin
asin: { (x: number): number | Complex; <T extends BigNumber | Complex>(x: T): T;};
Calculate the inverse sine of a value.
Parameter x
Function input
Returns
The arc sine of x
method asinh
asinh: <T extends number | BigNumber | Complex>(x: T) => T;
Calculate the hyperbolic arcsine of a value, defined as asinh(x) = ln(x + sqrt(x^2 + 1)).
Parameter x
Function input
Returns
The hyperbolic arcsine of x
method atan
atan: <T extends number | BigNumber | Complex>(x: T) => T;
Calculate the inverse tangent of a value.
Parameter x
Function input
Returns
The arc tangent of x
method atan2
atan2: <T extends number | MathCollection<any>>(y: T, x: T) => T;
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.
Parameter x
Function input
Returns
Four quadrant inverse tangent
method atanh
atanh: { (x: number): number | Complex; <T extends BigNumber | Complex>(x: T): T;};
Calculate the hyperbolic arctangent of a value, defined as atanh(x) = ln((1 + x)/(1 - x)) / 2.
Parameter x
Function input
Returns
The hyperbolic arctangent of x
method bellNumbers
bellNumbers: <T extends number | BigNumber>(n: T) => T;
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
Parameter n
Total number of objects in the set
Returns
B(n)
method bigint
bigint: { ( x?: number | string | Fraction | BigNumber | bigint | boolean | null ): bigint; <T extends MathCollection<any>>(x: T): T;};
Create a bigint, which can store integers with arbitrary precision. When a matrix is provided, all elements will be converted to bigint.
Parameter x
Value for the integer, 0 by default.
Returns
The created bigint
method bignumber
bignumber: { ( x?: | number | string | Fraction | BigNumber | bigint | Unit | boolean | null ): BigNumber; <T extends MathCollection<any>>(x: T): T;};
Create a BigNumber, which can store numbers with arbitrary precision. When a matrix is provided, all elements will be converted to BigNumber.
Parameter x
Value for the big number, 0 by default.
Returns
The created bignumber
method bitAnd
bitAnd: <T extends number | bigint | BigNumber | MathCollection<any>>( x: T, y: number | BigNumber | bigint | MathCollection) => NoLiteralType<T>;
Bitwise AND two values, x & y. For matrices, the function is evaluated element wise.
Parameter x
First value to and
Parameter y
Second value to and
Returns
AND of x and y
method bitNot
bitNot: <T extends number | bigint | BigNumber | MathCollection<any>>(x: T) => T;
Bitwise NOT value, ~x. For matrices, the function is evaluated element wise. For units, the function is evaluated on the best prefix base.
Parameter x
Value to not
Returns
NOT of x
method bitOr
bitOr: <T extends number | bigint | BigNumber | MathCollection<any>>( x: T, y: T) => T;
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.
Parameter x
First value to or
Parameter y
Second value to or
Returns
OR of x and y
method bitXor
bitXor: <T extends number | bigint | BigNumber | MathCollection<any>>( x: T, y: number | BigNumber | bigint | MathCollection) => NoLiteralType<T>;
Bitwise XOR two values, x ^ y. For matrices, the function is evaluated element wise.
Parameter x
First value to xor
Parameter y
Second value to xor
Returns
XOR of x and y
method boolean
boolean: { (x: string | number | boolean | null): boolean; (x: MathCollection<any>): MathCollection<any>;};
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.
Parameter x
A value of any type
Returns
The boolean value
method catalan
catalan: <T extends number | BigNumber>(n: T) => T;
The Catalan Numbers enumerate combinatorial structures of many different types. catalan only takes integer arguments. The following condition must be enforced: n >= 0
Parameter n
nth Catalan number
Returns
Cn(n)
method cbrt
cbrt: { (x: Complex, allRoots?: boolean): Complex; <T extends number | BigNumber | Unit>(x: T): T;};
Calculate the cubic root of a value.
Parameter x
Value for which to calculate the cubic root.
Parameter allRoots
Optional, 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
Returns the cubic root of x
method ceil
ceil: { <T extends unknown>(x: T, n?: number | BigNumber): NoLiteralType<T>; <U extends MathCollection<any>>(x: any, n: U): U; <U extends MathCollection<Unit>>(x: U, unit: Unit): U; (x: Unit, unit: Unit): Unit; (x: Unit, n: number | BigNumber, unit: Unit): Unit; <U extends MathCollection<Unit>>(x: U, n: number | BigNumber, unit: Unit): U;};
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.
Parameter x
Number to be rounded
Parameter n
Number of decimals Default value: 0.
Returns
Rounded value
method chain
chain: <TValue>(value?: TValue) => MathJsChain<TValue>;
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.
Parameter value
A value of any type on which to start a chained operation.
Returns
The created chain
method clone
clone: <TType>(x: TType) => TType;
Clone an object.
Parameter x
Object to be cloned
Returns
A clone of object x
method column
column: <T extends MathCollection<any>>(value: T, column: number) => T;
Return a column from a Matrix.
Parameter value
An array or matrix
Parameter column
The index of the column
Returns
The retrieved column
method combinations
combinations: <T extends number | BigNumber>( n: T, k: number | BigNumber) => NoLiteralType<T>;
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.
Parameter n
Total number of objects in the set
Parameter k
Number of objects in the subset
Returns
Number of possible combinations
method compare
compare: ( x: MathType | string, y: MathType | string) => number | BigNumber | Fraction | MathCollection;
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.
Parameter x
First value to compare
Parameter y
Second value to compare
Returns
Returns the result of the comparison: 1 when x > y, -1 when x < y, and 0 when x == y.
method compareNatural
compareNatural: (x: any, y: any) => number;
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.
Parameter x
First value to compare
Parameter y
Second value to compare
Returns
Returns the result of the comparison: 1 when x > y, -1 when x < y, and 0 when x == y.
method compareText
compareText: ( x: string | MathCollection, y: string | MathCollection) => number | MathCollection;
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.
Parameter x
First string to compare
Parameter y
Second string to compare
Returns
Returns the result of the comparison: 1 when x > y, -1 when x < y, and 0 when x == y.
method compile
compile: { (expr: MathExpression): EvalFunction; (exprs: MathExpression[]): EvalFunction[];};
Parse and compile an expression. Returns a an object with a function evaluate([scope]) to evaluate the compiled expression.
Parameter expr
The expression to be compiled
Returns
An object with the compiled expression
Parameter exprs
The expressions to be compiled
Returns
An array of objects with the compiled expressions
method complex
complex: { (arg?: MathNumericType | string | PolarCoordinates): Complex; (arg?: MathCollection<any>): MathCollection<any>; (re: number, im: number): Complex;};
Create a complex value or convert a value to a complex value.
Parameter args
Arguments specifying the real and imaginary part of the complex number
Returns
Returns a complex value
Parameter re
Argument specifying the real part of the complex number
Parameter im
Argument specifying the imaginary part of the complex number
Returns
Returns a complex value
method composition
composition: <T extends number | BigNumber>( n: T, k: number | BigNumber) => NoLiteralType<T>;
The composition counts of n into k parts. Composition only takes integer arguments. The following condition must be enforced: k <= n.
Parameter n
Total number of objects in the set
Parameter k
Number of objects in the subset
Returns
Returns the composition counts of n into k parts.
method concat
concat: (...args: Array<MathCollection | number | BigNumber>) => MathCollection;
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.
Parameter args
Two or more matrices
Returns
Concatenated matrix
method conj
conj: <T extends number | BigNumber | Complex | MathCollection<any>>( x: T) => NoLiteralType<T>;
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.
Parameter x
A complex number or array with complex numbers
Returns
The complex conjugate of x
method corr
corr: (x: MathCollection, y: MathCollection) => MathType;
Calculate the correlation coefficient between two matrix.
Parameter x
The first array or matrix to compute correlation coefficient
Parameter y
The second array or matrix to compute correlation coefficient
Returns
correlation coefficient
method cos
cos: { (x: number | Unit): number; <T extends BigNumber | Complex>(x: T): T };
Calculate the cosine of a value.
Parameter x
Function input
Returns
The cosine of x
method cosh
cosh: { (x: number | Unit): number; <T extends BigNumber | Complex>(x: T): T };
Calculate the hyperbolic cosine of a value, defined as cosh(x) = 1/2 * (exp(x) + exp(-x)).
Parameter x
Function input
Returns
The hyperbolic cosine of x
method cot
cot: { (x: number | Unit): number; <T extends BigNumber | Complex>(x: T): T };
Calculate the cotangent of a value. cot(x) is defined as 1 / tan(x).
Parameter x
Function input
Returns
The cotangent of x
method coth
coth: { (x: number | Unit): number; <T extends BigNumber | Complex>(x: T): T };
Calculate the hyperbolic cotangent of a value, defined as coth(x) = 1 / tanh(x).
Parameter x
Function input
Returns
The hyperbolic cotangent of x
method count
count: (x: MathCollection | string) => number;
Count the number of elements of a matrix, array or string.
Parameter x
A matrix, array or string.
Returns
The number of members passed in parameters
method createUnit
createUnit: { ( name: string, definition?: string | UnitDefinition | Unit, options?: CreateUnitOptions ): Unit; ( units: Record<string, string | Unit | UnitDefinition>, options?: CreateUnitOptions ): Unit;};
Create a user-defined unit and register it with the Unit type.
Parameter name
The name of the new unit. Must be unique. Example: ‘knot’
Parameter definition
Definition of the unit in terms of existing units. For example, ‘0.514444444 m / s’.
Parameter options
(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.
Returns
The new unit
Create a user-defined unit and register it with the Unit type.
Parameter units
Definition of the unit
Parameter options
Returns
The new unit
method cross
cross: (x: MathCollection, y: MathCollection) => MathCollection;
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 * b2 - a2 * b1 ]
Parameter x
First vector
Parameter y
Second vector
Returns
Returns the cross product of x and y
method csc
csc: { (x: number | Unit): number; <T extends BigNumber | Complex>(x: T): T };
Calculate the cosecant of a value, defined as csc(x) = 1/sin(x).
Parameter x
Function input
Returns
The cosecant hof x
method csch
csch: { (x: number | Unit): number; <T extends BigNumber | Complex>(x: T): T };
Calculate the hyperbolic cosecant of a value, defined as csch(x) = 1 / sinh(x).
Parameter x
Function input
Returns
The hyperbolic cosecant of x
method cube
cube: <T extends unknown>(x: T) => T;
Compute the cube of a value, x * x * x. For matrices, the function is evaluated element wise.
Parameter x
Number for which to calculate the cube
Returns
Cube of x
method cumsum
cumsum: { (...args: MathType[]): MathType[]; (array: MathCollection<any>, dim?: number): MathCollection<any>;};
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.
Parameter args
A single matrix or multiple scalar values
Returns
The cumulative sums of the the values.
Parameter array
A single matrix
Parameter dim
The dimension along which to sum (defaults to 0)
Returns
The cumulative sums along the given dimension
method deepEqual
deepEqual: (x: MathType, y: MathType) => MathType;
Test element wise whether two matrices are equal. The function accepts both matrices and scalar values.
Parameter x
First matrix to compare
Parameter y
Second amtrix to compare
Returns
Returns true when the input matrices have the same size and each of their elements is equal.
method derivative
derivative: ( expr: MathNode | string, variable: MathNode | string, options?: { simplify: boolean }) => MathNode;
Parameter expr
The expression to differentiate
Parameter variable
The variable over which to differentiate
Parameter options
There is one option available, simplify, which is true by default. When false, output will not be simplified.
Returns
The derivative of expr
method det
det: (x: MathCollection) => number;
Calculate the determinant of a matrix.
Parameter x
A Matrix
Returns
the determinant of x
method diag
diag: { (X: MathCollection, format?: string): Matrix; ( X: MathCollection<any>, k: number | BigNumber, format?: string ): MathCollection<any>;};
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.
Parameter X
A two dimensional matrix or a vector
Parameter k
The diagonal where the vector will be filled in or retrieved. Default value: 0.
Parameter format
The matrix storage format. Default value: 'dense'.
Returns
Diagonal matrix from input vector, or diagonal from input matrix
method distance
distance: ( x: MathCollection | object, y: MathCollection | object, z?: MathCollection | object) => number | BigNumber;
Calculates: The eucledian 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)
Parameter x
Coordinates of the first point
Parameter y
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
Parameter z
Coordinates of second end-point of a line if the calculation is for distance between point and a line in 2D
Returns
Returns the distance from two/three points
method divide
divide: { (x: Unit, y: Unit): Unit | number; (x: Unit, y: number): Unit; (x: number, y: number): number; (x: any, y: any): any;};
Divide two values, x / y. To divide matrices, x is multiplied with the inverse of y: x * inv(y).
Parameter x
Numerator
Parameter y
Denominator
Returns
Quotient, x / y
method dot
dot: (x: MathCollection, y: MathCollection) => number;
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
Parameter x
First vector
Parameter y
Second vector
Returns
Returns the dot product of x and y
method dotDivide
dotDivide: { <T extends MathCollection<any>>(x: T, y: MathType): T; <T extends MathCollection<any>>(x: any, y: T): T; (x: Unit, y: any): Unit; (x: any, y: Unit): Unit; (x: any, y: any): any;};
Divide two matrices element wise. The function accepts both matrices and scalar values.
Parameter x
Numerator
Parameter y
Denominator
Returns
Quotient, x ./ y
method dotMultiply
dotMultiply: { <T extends MathCollection<any>>(x: T, y: MathType): T; <T extends MathCollection<any>>(x: any, y: T): T; (x: Unit, y: any): Unit; (x: any, y: Unit): Unit; (x: any, y: any): any;};
Multiply two matrices element wise. The function accepts both matrices and scalar values.
Parameter x
Left hand value
Parameter y
Right hand value
Returns
Multiplication of x and y
method dotPow
dotPow: <T extends unknown>(x: T, y: MathType) => T;
Calculates the power of x to y element wise.
Parameter x
The base
Parameter y
The exponent
Returns
The value of x to the power y
method eigs
eigs: { ( x: MathCollection, opts?: | number | BigNumber | { precision?: number | BigNumber; eigenvectors?: true } ): { values: MathCollection; eigenvectors: { value: number | BigNumber; vector: MathCollection }[]; }; ( x: MathCollection<any>, opts: { eigenvectors: false; precision?: number | BigNumber } ): { values: MathCollection<any> };};
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 avector
. 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.vectorsParameter x
Matrix to be diagonalized
Parameter prec
Precision, default value: 1e-15
Returns
Object containing an array of eigenvalues and a matrix with eigenvectors as columns.
method equal
equal: (x: MathType | string, y: MathType | string) => boolean | MathCollection;
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.
Parameter x
First value to compare
Parameter y
Second value to compare
Returns
Returns true when the compared values are equal, else returns false
method equalText
equalText: ( x: string | MathCollection, y: string | MathCollection) => number | MathCollection;
Check equality of two strings. Comparison is case sensitive. For matrices, the function is evaluated element wise.
Parameter x
First string to compare
Parameter y
Second string to compare
Returns
Returns true if the values are equal, and false if not.
method erf
erf: <T extends number | MathCollection<any>>(x: T) => NoLiteralType<T>;
Compute the erf function of a value using a rational Chebyshev approximations for different intervals of x.
Parameter x
A real number
Returns
The erf of x
method evaluate
evaluate: { (expr: MathExpression | Matrix, scope?: object): any; (expr: MathExpression[], scope?: object): any[];};
Evaluate an expression.
Parameter expr
The expression to be evaluated
Parameter scope
Scope to read/write variables
Returns
The result of the expression
method exp
exp: <T extends number | BigNumber | Complex>(x: T) => T;
Calculate the exponent of a value. For matrices, the function is evaluated element wise.
Parameter x
A number or matrix to exponentiate
Returns
Exponent of x
method expm
expm: (x: Matrix) => Matrix;
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.
Parameter x
A square matrix
Returns
The exponential of x
method expm1
expm1: <T extends number | BigNumber | Complex>(x: T) => T;
Calculate the value of subtracting 1 from the exponential value. For matrices, the function is evaluated element wise.
Parameter x
A number or matrix to apply expm1
Returns
Exponent of x
method factorial
factorial: <T extends number | BigNumber | MathCollection<any>>( n: T) => NoLiteralType<T>;
Compute the factorial of a value Factorial only supports an integer value as argument. For matrices, the function is evaluated element wise.
Parameter n
An integer number
Returns
The factorial of n
method fft
fft: <T extends MathCollection<any>>(arr: T) => T;
Calculate N-dimensional Fourier transform
Parameter arr
An array or matrix {Array | Matrix} N-dimensional Fourier transformation of the array
method filter
filter: ( x: MathCollection | string[], test: | RegExp | (( value: any, index: number[], matrix: MathCollection | string[] ) => boolean)) => MathCollection;
Filter the items in an array or one dimensional matrix.
Parameter x
A one dimensional matrix or array to filter
Parameter test
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.
method fix
fix: { <T extends unknown>(x: T, n?: number | BigNumber): NoLiteralType<T>; <U extends MathCollection<any>>(x: any, n: U): U; <U extends MathCollection<Unit>>(x: U, unit: Unit): U; (x: Unit, unit: Unit): Unit; (x: Unit, n: number | BigNumber, unit: Unit): Unit; <U extends MathCollection<Unit>>(x: U, n: number | BigNumber, unit: Unit): U;};
Round a value towards zero. For matrices, the function is evaluated element wise.
Parameter x
Number to be rounded
Parameter n
Number of decimals Default value: 0.
Returns
Rounded value
method flatten
flatten: <T extends MathCollection<any>>(x: T) => T;
Flatten a multi dimensional matrix into a single dimensional matrix.
Parameter x
Matrix to be flattened
Returns
Returns the flattened matrix
method floor
floor: { <T extends unknown>(x: T, n?: number | BigNumber): NoLiteralType<T>; <U extends MathCollection<any>>(x: any, n: U): U; <U extends MathCollection<Unit>>(x: U, unit: Unit): U; (x: Unit, unit: Unit): Unit; (x: Unit, n: number | BigNumber, unit: Unit): Unit; <U extends MathCollection<Unit>>(x: U, n: number | BigNumber, unit: Unit): U;};
Round a value towards minus infinity. For matrices, the function is evaluated element wise.
Parameter x
Number to be rounded
Parameter n
Number of decimals Default value: 0.
Returns
Rounded value
method forEach
forEach: <T extends MathCollection<any>>( x: T, callback: (value: any, index: number[], matrix: T) => void) => void;
Iterate over all elements of a matrix/array, and executes the given callback function.
Parameter x
The matrix to iterate on.
Parameter callback
The callback function is invoked with three parameters: the value of the element, the index of the element, and the Matrix/array being traversed.
method format
format: ( value: any, options?: number | BigNumber | FormatOptions | ((item: any) => string), callback?: (value: any) => string) => string;
Format a value of any type into a string.
Parameter value
The value to be formatted
Parameter options
An object with formatting options.
Parameter callback
A 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.
Returns
The formatted value
See Also
http://mathjs.org/docs/reference/functions/format.html
method fraction
fraction: { ( value: | number | string | BigNumber | bigint | Unit | Fraction | FractionDefinition ): Fraction; (values: MathCollection<any>): MathCollection<any>; (numerator: bigint, denominator: bigint): Fraction; (numerator: number, denominator: number): Fraction;};
Create a fraction convert a value to a fraction.
Parameter value
Arguments specifying the numerator and denominator of the fraction
Returns
Returns a fraction
Parameter numerator
Argument specifying the numerator of the fraction
Parameter denominator
Argument specifying the denominator of the fraction
Returns
Returns a fraction
method freqz
freqz: <T extends MathCollection<any>>( b: T, a: T, w?: number | T) => { w: T; h: T };
Calculates the frequency response of a filter given its numerator and denominator coefficients.
Parameter b
The numerator polynomial of the filter
Parameter a
The denominator polynomial of the filter
Parameter w
The range of frequencies in which the response is to be calculated
Returns
The frequency response
method gamma
gamma: <T extends number | BigNumber | Complex>(n: T) => NoLiteralType<T>;
Compute the gamma function of a value using Lanczos approximation for small values, and an extended Stirling approximation for large values.
Parameter n
A real or complex number
Returns
The gamma of n
method gcd
gcd: { <T extends unknown>(...args: T[]): T; <T extends unknown>(args: T[]): T };
Calculate the greatest common divisor for two or more values or arrays. For matrices, the function is evaluated element wise.
Parameter args
Two or more integer numbers
Returns
The greatest common divisor
method hasNumericValue
hasNumericValue: (x: any) => boolean | boolean[];
Test whether a value is an numeric value. In case of a string, true is returned if the string contains a numeric value.
Parameter x
Value to be tested
Returns
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.
method help
help: (search: () => any) => Help;
Retrieve help on a function or data type. Help files are retrieved from the documentation in math.expression.docs.
Parameter search
A function or function name for which to get help
Returns
A help object
method hypot
hypot: { <T extends number | BigNumber>(...args: T[]): T; <T extends number | BigNumber>(args: T[]): T;};
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.
Parameter args
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
Returns the hypothenuse of the input values.
method identity
identity: { (size: number | number[] | MathCollection, format?: string): | MathCollection | number; (m: number, n: number, format?: string): number | MathCollection<any>;};
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.
Parameter size
The size for the matrix
Parameter format
The Matrix storage format
Returns
A matrix with ones on the diagonal
Parameter m
The x dimension for the matrix
Parameter n
The y dimension for the matrix
Parameter format
The Matrix storage format
Returns
A matrix with ones on the diagonal
method ifft
ifft: <T extends MathCollection<any>>(arr: T) => T;
Calculate N-dimensional inverse Fourier transform
Parameter arr
An array or matrix {Array | Matrix} N-dimensional Fourier transformation of the array
method im
im: { (x: MathJsChain<number | Complex>): MathJsChain<number>; <T extends BigNumber | MathCollection<any>>( x: MathJsChain<T> ): MathJsChain<T>;};
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.
Parameter x
A complex number or array with complex numbers
Returns
The imaginary part of x
method import
import: (object: ImportObject | ImportObject[], options?: ImportOptions) => void;
Import functions from an object or a module To avoid errors when using one of the imported functions extend module like this:
Parameter object
An object with functions to be imported.
Parameter options
An object with import options.
Example 1
// imported_math_functions.ts declare module 'mathjs' { interface MathJsInterface { hello(a: number): number; } }
method index
index: (...ranges: any[]) => Index;
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.
Parameter ranges
Zero or more ranges or numbers.
Returns
Returns the created index
method intersect
intersect: ( w: MathCollection, x: MathCollection, y: MathCollection, z?: MathCollection) => MathArray;
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.
Parameter w
Co-ordinates of first end-point of first line
Parameter x
Co-ordinates of second end-point of first line
Parameter y
Co-ordinates of first end-point of second line OR Coefficients of the plane's equation
Parameter z
Co-ordinates of second end-point of second line OR null if the calculation is for line and plane
Returns
Returns the point of intersection of lines/lines-planes
method inv
inv: <T extends number | Complex | MathCollection<any>>( x: T) => NoLiteralType<T>;
Calculate the inverse of a square matrix.
Parameter x
Matrix to be inversed
Returns
The inverse of x
method isAccessorNode
isAccessorNode: (x: unknown) => x is AccessorNode<MathNode>;
method isArrayNode
isArrayNode: (x: unknown) => x is ArrayNode<MathNode[]>;
method isAssignmentNode
isAssignmentNode: (x: unknown) => x is AssignmentNode<MathNode>;
method isBigInt
isBigInt: (x: unknown) => x is bigint;
method isBigNumber
isBigNumber: (x: unknown) => x is BigNumber;
method isBlockNode
isBlockNode: (x: unknown) => x is BlockNode<MathNode>;
method isBoolean
isBoolean: (x: unknown) => x is boolean;
method isChain
isChain: (x: unknown) => x is MathJsChain<unknown>;
method isCollection
isCollection: (x: unknown) => x is any[] | Matrix<any>;
method isComplex
isComplex: (x: unknown) => x is Complex;
method isConditionalNode
isConditionalNode: ( x: unknown) => x is ConditionalNode<MathNode, MathNode, MathNode>;
method isConstantNode
isConstantNode: (x: unknown) => x is ConstantNode<number>;
method isDate
isDate: (x: unknown) => x is Date;
method isDenseMatrix
isDenseMatrix: (x: unknown) => x is Matrix<any>;
method isFraction
isFraction: (x: unknown) => x is Fraction;
method isFunction
isFunction: (x: unknown) => boolean;
method isFunctionAssignmentNode
isFunctionAssignmentNode: (x: unknown) => x is FunctionAssignmentNode<MathNode>;
method isFunctionNode
isFunctionNode: (x: unknown) => x is FunctionNode<SymbolNode, MathNode[]>;
method isHelp
isHelp: (x: unknown) => x is Help;
method isIndex
isIndex: (x: unknown) => x is Index;
method isIndexNode
isIndexNode: (x: unknown) => x is IndexNode<MathNode[]>;
method isInteger
isInteger: (x: number | BigNumber | Fraction | MathCollection) => boolean;
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.
Parameter x
Value to be tested
Returns
Returns true when x contains a numeric, integer value. Throws an error in case of an unknown data type.
method isMap
isMap: <T, U>(x: unknown) => x is Map<T, U>;
method isMatrix
isMatrix: (x: unknown) => x is Matrix<any>;
method isNaN
isNaN: ( x: number | BigNumber | bigint | Fraction | MathCollection | Unit) => boolean;
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.
Parameter x
Value to be tested
Returns
Returns true when x is NaN. Throws an error in case of an unknown data type.
method isNegative
isNegative: ( x: number | BigNumber | bigint | Fraction | MathCollection | Unit) => boolean;
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.
Parameter x
Value to be tested
Returns
Returns true when x is larger than zero. Throws an error in case of an unknown data type.
method isNode
isNode: (x: unknown) => x is MathNode;
method isNull
isNull: (x: unknown) => x is null;
method isNumber
isNumber: (x: unknown) => x is number;
*********************************************************************** Utils **********************************************************************
method isNumeric
isNumeric: (x: any) => x is any;
Test whether a value is an numeric value. The function is evaluated element-wise in case of Array or Matrix input.
Parameter x
Value to be tested
Returns
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.
method isObject
isObject: (x: unknown) => boolean;
method isObjectNode
isObjectNode: (x: unknown) => x is ObjectNode<Record<string, MathNode>>;
method isObjectWrappingMap
isObjectWrappingMap: <T extends string | number | symbol, U>( x: unknown) => x is ObjectWrappingMap<T, U>;
method isOperatorNode
isOperatorNode: ( x: unknown) => x is OperatorNode<OperatorNodeOp, keyof OperatorNodeMap, MathNode[]>;
method isParenthesisNode
isParenthesisNode: (x: unknown) => x is ParenthesisNode<MathNode>;
method isPartitionedMap
isPartitionedMap: <T, U>(x: unknown) => x is PartitionedMap<T, U>;
method isPositive
isPositive: ( x: number | BigNumber | bigint | Fraction | MathCollection | Unit) => boolean;
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.
Parameter x
Value to be tested
Returns
Returns true when x is larger than zero. Throws an error in case of an unknown data type.
method isPrime
isPrime: (x: number | BigNumber | MathCollection) => boolean;
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.
Parameter x
Value to be tested
Returns
Returns true when x is larger than zero. Throws an error in case of an unknown data type.
method isRange
isRange: (x: unknown) => boolean;
method isRangeNode
isRangeNode: (x: unknown) => x is RangeNode<MathNode, MathNode, MathNode>;
method isRegExp
isRegExp: (x: unknown) => x is RegExp;
method isRelationalNode
isRelationalNode: (x: unknown) => x is RelationalNode<MathNode[]>;
method isResultSet
isResultSet: (x: unknown) => boolean;
method isSparseMatrix
isSparseMatrix: (x: unknown) => x is Matrix<any>;
method isString
isString: (x: unknown) => x is string;
method isSymbolNode
isSymbolNode: (x: unknown) => x is SymbolNode;
method isUndefined
isUndefined: (x: unknown) => x is undefined;
method isUnit
isUnit: (x: unknown) => x is Unit;
method isZero
isZero: (x: MathType) => boolean;
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.
Parameter x
Value to be tested
Returns
Returns true when x is zero. Throws an error in case of an unknown data type.
method kldivergence
kldivergence: (q: MathCollection, p: MathCollection) => number;
Calculate the Kullback-Leibler (KL) divergence between two distributions
Parameter q
First vector
Parameter p
Second vector
Returns
Returns disance between q and p
method kron
kron: (x: MathCollection, y: MathCollection) => Matrix;
Calculate the Kronecker product of two matrices or vectors
Parameter x
First vector
Parameter y
Second vector
Returns
Returns the Kronecker product of x and y
method larger
larger: (x: MathType | string, y: MathType | string) => boolean | MathCollection;
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.
Parameter x
First value to compare
Parameter y
Second value to vcompare
Returns
Returns true when x is larger than y, else returns false
method largerEq
largerEq: ( x: MathType | string, y: MathType | string) => boolean | MathCollection;
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.
Parameter x
First value to compare
Parameter y
Second value to vcompare
Returns
Returns true when x is larger than or equal to y, else returns false
method lcm
lcm: <T extends number | BigNumber | MathCollection<any>>(a: T, b: T) => T;
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.
Parameter a
An integer number
Parameter b
An integer number
Returns
The least common multiple
method leafCount
leafCount: (expr: MathNode) => number;
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, the5
; the unary factorial operator does not add a leaf. On the other hand, function symbols do add leaves, sosin(x)/cos(x)
has four leaves.
method leftShift
leftShift: <T extends number | bigint | BigNumber | MathCollection<any>>( x: T, y: number | BigNumber | bigint) => NoLiteralType<T>;
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.
Parameter x
Value to be shifted
Parameter y
Amount of shifts
Returns
x shifted left y times
method lgamma
lgamma: <T extends number | Complex>(n: T) => NoLiteralType<T>;
Compute the log gamma function of a value, using Lanczos approximation for numbers and Stirling series for complex numbers.
Parameter n
A real or complex number
Returns
The log gamma of
n
method log
log: <T extends number | BigNumber | Complex>( x: T, base?: number | BigNumber | Complex) => NoLiteralType<T>;
Calculate the logarithm of a value.
Parameter x
Value for which to calculate the logarithm.
Parameter base
Optional base for the logarithm. If not provided, the natural logarithm of x is calculated. Default value: e.
Returns
Returns the logarithm of x
method log10
log10: <T extends number | BigNumber | Complex | MathCollection<any>>(x: T) => T;
Calculate the 10-base of a value. This is the same as calculating log(x, 10). For matrices, the function is evaluated element wise.
Parameter x
Value for which to calculate the logarithm.
Returns
Returns the 10-base logarithm of x
method log1p
log1p: <T extends number | BigNumber | Complex | MathCollection<any>>( x: T, base?: number | BigNumber | Complex) => T;
Calculate the logarithm of a value+1. For matrices, the function is evaluated element wise.
Parameter x
Value for which to calculate the logarithm.
Returns
Returns the logarithm of x+1
method log2
log2: <T extends number | BigNumber | Complex | MathCollection<any>>(x: T) => T;
Calculate the 2-base of a value. This is the same as calculating log(x, 2). For matrices, the function is evaluated element wise.
Parameter x
Value for which to calculate the logarithm.
Returns
Returns the 2-base logarithm of x
method lsolve
lsolve: { (L: Matrix, b: MathCollection): Matrix; (L: MathArray<any>, b: MathCollection<any>): MathArray<any>;};
Solves the linear equation system by forwards substitution. Matrix must be a lower triangular matrix.
Parameter L
A N x N matrix or array (L)
Parameter b
A column vector with the b values
Returns
A column vector with the linear system solution (x)
method lup
lup: (A?: MathCollection) => LUDecomposition;
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
Parameter A
A two dimensional matrix or array for which to get the LUP decomposition.
Returns
The lower triangular matrix, the upper triangular matrix and the permutation matrix.
method lusolve
lusolve: { (A: Matrix, b: MathCollection, order?: number, threshold?: number): Matrix; ( A: MathArray<any>, b: MathCollection<any>, order?: number, threshold?: number ): MathArray<any>; (A: LUDecomposition, b: MathCollection<any>): Matrix<any>;};
Solves the linear system A * x = b where A is an [n x n] matrix and b is a [n] column vector.
Parameter A
Invertible Matrix or the Matrix LU decomposition
Parameter b
Column Vector
Parameter order
The Symbolic Ordering and Analysis order, see slu for details. Matrix must be a SparseMatrix
Parameter threshold
Partial pivoting threshold (1 for partial pivoting), see slu for details. Matrix must be a SparseMatrix.
Returns
Column vector with the solution to the linear system A * x = b
method lyap
lyap: (A: MathCollection, Q: MathCollection) => MathCollection;
Solves the Continuous-time Lyapunov equation AP+PA'=Q for P, where Q is a positive semidefinite matrix. https://en.wikipedia.org/wiki/Lyapunov_equation
Parameter A
Matrix A
Parameter Q
Matrix Q
Returns
Matrix P solution to the Continuous-time Lyapunov equation AP+PA'=Q
method mad
mad: (array: MathCollection) => any;
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.
Parameter array
A single matrix or multiple scalar values.
Returns
The median absolute deviation
method map
map: { <T extends MathCollection<any>>( x: T, callback: (value: any, index: number[], matrix: T) => MathType | string ): T; <T extends MathCollection<any>>( x: T, ...args: (T | ((value: any, ...args: any[]) => any))[] ): T;};
Iterate over all elements of a matrix/array, and executes the given callback function.
Parameter x
The matrix to iterate on.
Parameter callback
The callback function is invoked with three parameters: the value of the element, the index of the element, and the Matrix/array being traversed.
Returns
Transformed map of x
Iterate over all elements of multiple matrices/arrays, and executes the given callback function.
Parameter x
The first matrix to iterate on.
Parameter args
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.
Returns
Transformed map of matrices
method mapSlices
mapSlices: <T extends MathCollection<any>>( array: T, dim: number, callback: (array: MathCollection) => number) => T;
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.
Parameter array
The input Matrix
Parameter dim
The dimension along which the callback is applied
Parameter callback
The callback function that is applied. This Function should take an array or 1-d matrix as an input and return a number.
Returns
The residual matrix with the function applied over some dimension.
method matrix
matrix: { (format?: MatrixStorageFormat): Matrix; ( data: string[] | MathCollection<any>, format?: MatrixStorageFormat, dataType?: string ): Matrix<any>; <T extends unknown>( data: MathCollection<T>, format?: MatrixStorageFormat, dataType?: string ): Matrix<T>;};
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'.
Parameter format
The Matrix storage format
Returns
The created Matrix
Parameter data
A multi dimensional array
Parameter format
The Matrix storage format
Parameter dataType
The Matrix data type
Returns
The created Matrix
method matrixFromColumns
matrixFromColumns: { (...cols: Matrix[]): Matrix; <T extends unknown>(...cols: (Matrix<any> | T[] | [T][])[]): T[][];};
Create a dense matrix from vectors as individual columns. If you pass row vectors, they will be transposed (but not conjugated!)
Parameter cols
a multi-dimensional number array or matrix
method matrixFromFunction
matrixFromFunction: { <T extends unknown>(size: [number], fn: MatrixFromFunctionCallback<T>): T[]; <T extends unknown>( size: [number, number], fn: MatrixFromFunctionCallback<T> ): T[][]; <T extends unknown>( size: number[], fn: MatrixFromFunctionCallback<T> ): MathArray<T>; (size: Matrix<number>, fn: MatrixFromFunctionCallback<any>): Matrix<any>; ( size: number[] | Matrix<number>, fn: MatrixFromFunctionCallback<any>, format: MatrixStorageFormat, datatype?: string ): Matrix<any>; ( size: number[] | Matrix<number>, format: MatrixStorageFormat, fn: MatrixFromFunctionCallback<any>, datatype?: string ): Matrix<any>;};
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.
Parameter size
the size of the matrix to be created
Parameter fn
Callback function invoked for every entry in the matrix
Parameter format
The Matrix storage format, either 'dense' or 'sparse'
Parameter datatype
Type of the values
method matrixFromRows
matrixFromRows: { (...rows: Matrix[]): Matrix; <T extends unknown>(...rows: (Matrix<any> | T[] | [T][])[]): T[][];};
Create a dense matrix from vectors as individual rows. If you pass column vectors, they will be transposed (but not conjugated!)
Parameter rows
a multi-dimensional number array or matrix
method max
max: { <T extends unknown>(...args: T[]): T; (...args: any[]): any; <T extends unknown>(A: T[] | T[][], dimension?: number | BigNumber): T; (A: MathCollection<any>, dimension?: number | BigNumber): any;};
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.
Parameter args
Multiple scalar values
Returns
The maximum value
Parameter args
Multiple scalar values
Returns
The maximum value
Parameter A
A single matrix
Parameter dimension
The maximum over the selected dimension
Returns
The maximum value
method mean
mean: { <T extends unknown>(...args: T[]): T; (...args: any[]): any; <T extends unknown>(A: T[] | T[][], dimension?: number | BigNumber): T; (A: MathCollection<any>, dimension?: number | BigNumber): any;};
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.
Parameter args
Multiple scalar values
Returns
The mean of all values
Parameter args
Multiple scalar values
Returns
The mean value
Parameter A
A single matrix
Parameter dimension
The mean over the selected dimension
Returns
The mean value
method median
median: { <T extends unknown>(...args: T[]): T; (...args: any[]): any; <T extends unknown>(A: T[] | T[][]): T; (A: MathCollection<any>): any;};
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.
Parameter args
Multiple scalar values
Returns
The median value
Parameter args
Multiple scalar values
Returns
The median value
Parameter A
A single matrix
Returns
The median value
method min
min: { <T extends unknown>(...args: T[]): T; (...args: any[]): any; <T extends unknown>(A: T[] | T[][], dimension?: number | BigNumber): T; (A: MathCollection<any>, dimension?: number | BigNumber): any;};
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.
Parameter args
multiple scalar values
Returns
The minimum value
Parameter args
Multiple scalar values
Returns
The minimum value
Parameter A
A single matrix
Parameter dimension
The minimum over the selected dimension
Returns
The minimum value
method mod
mod: <T extends unknown>( x: T, y: number | BigNumber | bigint | Fraction | MathCollection) => NoLiteralType<T>;
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)
Parameter x
Dividend
Parameter y
Divisor
Returns
Returns the remainder of x divided by y
See Also
http://en.wikipedia.org/wiki/Modulo_operation.
method mode
mode: { <T extends unknown>(...args: T[]): T[]; (...args: any[]): any[]; <T extends unknown>(A: T[] | T[][]): T[]; (A: MathCollection<any>): any[];};
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.
Parameter args
Multiple scalar values
Returns
The mode of all values
Parameter args
Multiple scalar values
Returns
The mode of all values
Parameter A
A single matrix
Returns
The mode value
Parameter A
A single matrix
Returns
The mode of all values
method multinomial
multinomial: <T extends number | BigNumber>(a: T[]) => NoLiteralType<T>;
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
Parameter a
Integer number of objects in the subset
Returns
multinomial coefficent
method multiply
multiply: { <T extends Matrix<any>>(x: T, y: MathType): Matrix; <T extends Matrix<any>>(x: any, y: T): Matrix<any>; <T extends MathArray<any>>(x: T, y: T[]): T; <T extends MathArray<any>>(x: T[], y: T): T; <T extends MathArray<any>>(x: T[], y: T[]): T[]; <T extends MathArray<any>>(x: T, y: T): any; (x: Unit, y: Unit): Unit; (x: number, y: number): number; (x: any, y: any): any; <T extends unknown>(...values: T[]): T; (...values: any[]): any;};
Multiply two values, x * y. The result is squeezed. For matrices, the matrix product is calculated.
Parameter x
The first value to multiply
Parameter y
The second value to multiply
Returns
Multiplication of x and y
method norm
norm: ( x: number | BigNumber | Complex | MathCollection, p?: number | BigNumber | string) => number | BigNumber;
Calculate the norm of a number, vector or matrix. The second parameter p is optional. If not provided, it defaults to 2.
Parameter x
Value for which to calculate the norm
Parameter p
Vector space. Supported numbers include Infinity and -Infinity. Supported strings are: 'inf', '-inf', and 'fro' (The Frobenius norm) Default value: 2.
Returns
the p-norm
method not
not: ( x: number | BigNumber | bigint | Complex | Unit | MathCollection) => boolean | MathCollection;
Logical not. Flips boolean value of a given parameter. For matrices, the function is evaluated element wise.
Parameter x
First value to not
Returns
Returns true when input is a zero or empty value.
method nthRoot
nthRoot: ( a: number | BigNumber | MathCollection | Complex, root?: number | BigNumber) => number | Complex | MathCollection;
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.
Parameter a
Value for which to calculate the nth root
Parameter root
The root. Default value: 2. The nth root of a
method number
number: { ( value?: | string | number | BigNumber | bigint | Fraction | boolean | Unit | null ): number; (value?: MathCollection<any>): number | MathCollection<any>; (unit: Unit, valuelessUnit: string | Unit): number;};
Create a number or convert a string, boolean, or unit to a number. When value is a matrix, all elements will be converted to number.
Parameter value
Value to be converted
Returns
The created number
Parameter value
Value to be converted
Parameter valuelessUnit
A valueless unit, used to convert a unit to a number
Returns
The created number
method numeric
numeric: { ( value: string | number | BigNumber | bigint | Fraction, outputType: 'number' ): number; (value: any, outputType: 'BigNumber'): BigNumber; (value: any, outputType: 'bigint'): bigint; (value: any, outputType: 'Fraction'): Fraction;};
Convert a numeric input to a specific numeric type: number, BigNumber, bigint, or Fraction.
Parameter value
The value to be converted
Parameter outputType
The desired numeric output type
method ones
ones: { ( size?: number | number[] | BigNumber | BigNumber[], format?: string ): MathCollection; ( m: number | BigNumber, n: number | BigNumber, format?: string ): MathCollection<any>; ( m: number | BigNumber, n: number | BigNumber, p: number | BigNumber, format?: string ): MathCollection<any>;};
Create a matrix filled with ones. The created matrix can have one or multiple dimensions.
Parameter size
The size of each dimension of the matrix
Parameter format
The matrix storage format
Returns
A matrix filled with ones
Parameter m
The x dimension of the matrix
Parameter n
The y dimension of the matrix
Parameter format
The matrix storage format
Returns
A matrix filled with ones
Parameter m
The x dimension of the matrix
Parameter n
The y dimension of the matrix
Parameter p
The z dimension of the matrix
Parameter format
The matrix storage format
Returns
A matrix filled with ones
method or
or: ( x: number | BigNumber | bigint | Complex | Unit | MathCollection, y: number | BigNumber | bigint | Complex | Unit | MathCollection) => boolean | MathCollection;
Logical or. Test if at least one value is defined with a nonzero/nonempty value. For matrices, the function is evaluated element wise.
Parameter x
First value to or
Parameter y
Second value to or
Returns
Returns true when one of the inputs is defined with a nonzero/nonempty value.
method parser
parser: () => Parser;
Create a parser. The function creates a new math.expression.Parser object.
Returns
A Parser object
method partitionSelect
partitionSelect: ( x: MathCollection, k: number, compare?: 'asc' | 'desc' | ((a: any, b: any) => number)) => any;
Partition-based selection of an array or 1D matrix. Will find the kth smallest value, and mutates the input array. Uses Quickselect.
Parameter x
A one dimensional matrix or array to sort
Parameter k
The kth smallest value to be retrieved; zero-based index
Parameter compare
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
Returns the kth lowest value.
method permutations
permutations: <T extends number | BigNumber>( n: T, k?: number | BigNumber) => NoLiteralType<T>;
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.
Parameter n
The number of objects in total
Parameter k
The number of objects in the subset
Returns
The number of permutations
method pickRandom
pickRandom: { <T>(array: T[]): T; <T>(array: T[], number: number): T[]; <T>(array: T[], number: number, weights: number[]): T[];};
Random pick a value from a one dimensional array. Array element is picked using a random function with uniform distribution.
Parameter array
A one dimensional array
Parameter number
An int or float
Parameter weights
An array of ints or floats
Returns
Returns a single random value from array when number is undefined. Returns an array with the configured number of elements when number is defined.
method pinv
pinv: <T extends unknown>(x: T) => T;
Calculate the Moore–Penrose inverse of a matrix.
Parameter x
Matrix to be inversed The inverse of
x
.
method polynomialRoot
polynomialRoot: ( constantCoeff: number | Complex, linearCoeff: number | Complex, quadraticCoeff?: number | Complex, cubicCoeff?: number | Complex) => (number | Complex)[];
method pow
pow: (x: MathType, y: number | BigNumber | bigint | Complex) => MathType;
Calculates the power of x to y, x ^ y. Matrix exponentiation is supported for square matrices x, and positive integer exponents y.
Parameter x
The base
Parameter y
The exponent
Returns
x to the power y
method print
print: ( template: string, values: any, precision?: number, options?: number | object) => void;
Interpolate values into a string template.
Parameter template
A string containing variable placeholders.
Parameter values
An object containing variables which will be filled in in the template.
Parameter precision
Number of digits to format numbers. If not provided, the value will not be rounded.
Parameter options
Formatting options, or the number of digits to format numbers. See function math.format for a description of all options.
Returns
Interpolated string
method prod
prod: { <T extends unknown>(...args: T[]): T; (...args: any[]): any; <T extends unknown>(A: T[] | T[][]): T; (A: MathCollection<any>): any;};
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.
Parameter args
Multiple scalar values
Returns
The product of all values
Parameter args
Multiple scalar values
Returns
The product of all values
Parameter A
A single matrix
Returns
The product of all values
method qr
qr: (A: MathCollection) => QRDecomposition;
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.
Parameter A
A two dimensional matrix or array for which to get the QR decomposition.
Returns
Q: the orthogonal matrix and R: the upper triangular matrix
method quantileSeq
quantileSeq: { <T extends unknown>( A: T[] | T[][], prob: number | BigNumber, sorted?: boolean ): T; ( A: MathCollection<any>, prob: number | BigNumber | MathArray<any>, sorted?: boolean ): any;};
Parameter A
A single matrix
Parameter probOrN
prob is the order of the quantile, while N is the amount of evenly distributed steps of probabilities; only one of these options can be provided
Parameter sorted
=false is data sorted in ascending order
Returns
Quantile(s)
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.
Parameter A
A single matrix or array
Parameter probOrN
prob is the order of the quantile, while N is the amount of evenly distributed steps of probabilities; only one of these options can be provided
Parameter sorted
=false is data sorted in ascending order
Returns
Quantile(s)
method random
random: { (min?: number, max?: number): number; <T extends MathCollection<any>>(size: T, min?: number, max?: number): T;};
Return a random number larger or equal to min and smaller than max using a uniform distribution.
Parameter size
If provided, an array or matrix with given size and filled with random values is returned
Parameter min
Minimum boundary for the random value, included
Parameter max
Maximum boundary for the random value, excluded
Returns
A random number
method randomInt
randomInt: { (min: number, max?: number): number; <T extends MathCollection<any>>(size: T, min?: number, max?: number): T;};
Return a random integer number larger or equal to min and smaller than max using a uniform distribution.
Parameter size
If provided, an array or matrix with given size and filled with random values is returned
Parameter min
Minimum boundary for the random value, included
Parameter max
Maximum boundary for the random value, excluded
Returns
A random number
method range
range: { (str: string, includeEnd?: boolean): Matrix; ( start: number | BigNumber, end: number | BigNumber, includeEnd?: boolean ): Matrix<any>; ( start: number | BigNumber | Unit, end: number | BigNumber | Unit, step: number | BigNumber | Unit, includeEnd?: boolean ): Matrix<any>;};
Create an array from a range. By default, the range end is excluded. This can be customized by providing an extra parameter includeEnd.
Parameter str
A string 'start:end' or 'start:step:end'
Parameter start
Start of the range
Parameter end
End of the range, excluded by default, included when parameter includeEnd=true
Parameter step
Step size. Default value is 1.
Parameter includeEnd
: Option to specify whether to include the end or not. False by default
Returns
Parameters describing the ranges start, end, and optional step.
method rationalize
rationalize: { ( expr: MathNode | string, optional?: object | boolean, detailed?: false ): MathNode; (expr: string | MathNode, optional?: boolean | object, detailed?: true): { expression: string | MathNode; variables: string[]; coefficients: any[]; };};
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.
Parameter expr
The expression to check if is a polynomial expression
Parameter optional
scope of expression or true for already evaluated rational expression at input
Parameter detailed
optional True if return an object, false if return expression node (default)
Returns
The rational polynomial of expr
method re
re: { (x: MathJsChain<number | Complex>): MathJsChain<number>; <T extends BigNumber | MathCollection<any>>( x: MathJsChain<T> ): MathJsChain<T>;};
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.
Parameter x
A complex number or array of complex numbers
Returns
The real part of x
method replacer
replacer: () => (key: any, value: any) => any;
Returns replacer function that can be used as replacer in JSON.stringify function.
method reshape
reshape: <T extends MathCollection<any>>(x: T, sizes: number[]) => T;
Reshape a multi dimensional array to fit the specified dimensions
Parameter x
Matrix to be reshaped
Parameter sizes
One dimensional array with integral sizes for each dimension
Returns
A reshaped clone of matrix x
method resize
resize: <T extends MathCollection<any>>( x: T, size: MathCollection, defaultValue?: number | string) => T;
Resize a matrix
Parameter x
Matrix to be resized
Parameter size
One dimensional array with numbers
Parameter defaultValue
Zero by default, except in case of a string, in that case defaultValue = ' ' Default value: 0.
Returns
A resized clone of matrix x
method resolve
resolve: { (node: MathNode | string, scope?: Record<string, any>): MathNode; (node: (string | MathNode)[], scope?: Record<string, any>): MathNode[]; (node: Matrix<any>, scope?: Record<string, any>): Matrix<any>;};
Replaces variable nodes with their scoped values
Parameter node
Tree to replace variable nodes in
Parameter scope
Scope to read/write variables
method reviver
reviver: () => (key: any, value: any) => any;
Returns reviver function that can be used as reviver in JSON.parse function.
method rightArithShift
rightArithShift: <T extends number | bigint | BigNumber | MathCollection<any>>( x: T, y: number | BigNumber | bigint) => NoLiteralType<T>;
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.
Parameter x
Value to be shifted
Parameter y
Amount of shifts
Returns
x sign-filled shifted right y times
method rightLogShift
rightLogShift: <T extends number | MathCollection<any>>( x: T, y: number) => NoLiteralType<T>;
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.
Parameter x
Value to be shifted
Parameter y
Amount of shifts
Returns
x zero-filled shifted right y times
method rotate
rotate: <T extends MathCollection<any>>( w: T, theta: number | BigNumber | Complex | Unit, v?: T) => T;
Return a rotated matrix.
Parameter w
Vector to rotate
Parameter theta
Rotation angle
Parameter v
Rotation axis {Array | Matrix} Multiplication of the rotation matrix and w
method rotationMatrix
rotationMatrix: <T extends MathCollection<any>>( theta?: number | BigNumber | Complex | Unit, axis?: T, format?: 'sparse' | 'dense') => T;
Return a Rotation Matrix for a given angle in radians
Parameter theta
Rotation angle
Parameter v
Rotation axis
Parameter format
Result Matrix storage format. Default value: 'dense'. {Matrix} Rotation Matrix
method round
round: { <T extends unknown>(x: T, n?: number | BigNumber): NoLiteralType<T>; <U extends MathCollection<any>>(x: any, n: U): U; <U extends MathCollection<Unit>>(x: U, unit: Unit): U; (x: Unit, unit: Unit): Unit; (x: Unit, n: number | BigNumber, unit: Unit): Unit; <U extends MathCollection<Unit>>(x: U, n: number | BigNumber, unit: Unit): U;};
Round a value towards the nearest integer. For matrices, the function is evaluated element wise.
Parameter x
Number to be rounded
Parameter n
Number of decimals Default value: 0.
Returns
Rounded value of x
method row
row: <T extends MathCollection<any>>(value: T, row: number) => T;
Return a row from a Matrix.
Parameter value
An array or matrix
Parameter row
The index of the row
Returns
The retrieved row
method schur
schur: (A: MathCollection) => SchurDecomposition;
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
Parameter A
Matrix A
Returns
Object containing both matrix U and T of the Schur Decomposition A=UTU'
method sec
sec: { (x: number | Unit): number; <T extends BigNumber | Complex>(x: T): T };
Calculate the secant of a value, defined as sec(x) = 1/cos(x).
Parameter x
Function input
Returns
The secant of x
method sech
sech: { (x: number | Unit): number; <T extends BigNumber | Complex>(x: T): T };
Calculate the hyperbolic secant of a value, defined as sech(x) = 1 / cosh(x).
Parameter x
Function input
Returns
The hyperbolic secant of x
method setCartesian
setCartesian: <T extends MathCollection<any>>(a1: T, a2: MathCollection) => T;
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.
Parameter a1
A (multi)set
Parameter a2
A (multi)set
Returns
The cartesian product of two (multi)sets
method setDifference
setDifference: <T extends MathCollection<any>>(a1: T, a2: MathCollection) => T;
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
Parameter a1
A (multi)set
Parameter a2
A (multi)set
Returns
The difference of two (multi)sets
method setDistinct
setDistinct: <T extends MathCollection<any>>(a: T) => T;
Collect the distinct elements of a multiset. A multi-dimension array will be converted to a single-dimension array before the operation.
Parameter a
A multiset
Returns
A set containing the distinct elements of the multiset
method setIntersect
setIntersect: <T extends MathCollection<any>>(a1: T, a2: MathCollection) => T;
Create the intersection of two (multi)sets. Multi-dimension arrays will be converted to single-dimension arrays before the operation.
Parameter a1
A (multi)set
Parameter a2
A (multi)set
Returns
The intersection of two (multi)sets
method setIsSubset
setIsSubset: (a1: MathCollection, a2: MathCollection) => boolean;
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.
Parameter a1
A (multi)set
Parameter a2
A (multi)set
Returns
True if a1 is subset of a2, else false
method setMultiplicity
setMultiplicity: (e: MathNumericType, a: MathCollection) => number;
Count the multiplicity of an element in a multiset. A multi-dimension array will be converted to a single-dimension array before the operation.
Parameter e
An element in the multiset
Parameter a
A multiset
Returns
The number of how many times the multiset contains the element
method setPowerset
setPowerset: <T extends MathCollection<any>>(a: T) => T;
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.
Parameter a
A multiset
Returns
The powerset of the (multi)set
method setSize
setSize: (a: MathCollection) => number;
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.
Parameter a
A multiset
Returns
The number of elements of the (multi)set
method setSymDifference
setSymDifference: <T extends MathCollection<any>>( a1: T, a2: MathCollection) => T;
Create the symmetric difference of two (multi)sets. Multi-dimension arrays will be converted to single-dimension arrays before the operation.
Parameter a1
A (multi)set
Parameter a2
A (multi)set
Returns
The symmetric difference of two (multi)sets
method setUnion
setUnion: <T extends MathCollection<any>>(a1: T, a2: MathCollection) => T;
Create the union of two (multi)sets. Multi-dimension arrays will be converted to single-dimension arrays before the operation.
Parameter a1
A (multi)set
Parameter a2
A (multi)set
Returns
The union of two (multi)sets
method sign
sign: <T extends unknown>(x: T) => T;
Compute the sign of a value. The sign of a value x is: 1 when x > 1 -1 when x < 0 0 when x == 0 For matrices, the function is evaluated element wise.
Parameter x
The number for which to determine the sign
Returns
The sign of x
method simplifyConstant
simplifyConstant: ( expr: MathNode | string, options?: SimplifyOptions) => MathNode;
method simplifyCore
simplifyCore: (expr: MathNode | string, options?: SimplifyOptions) => MathNode;
method sin
sin: { (x: number | Unit): number; <T extends BigNumber | Complex>(x: T): T };
Calculate the sine of a value.
Parameter x
Function input
Returns
The sine of x
method sinh
sinh: { (x: number | Unit): number; <T extends BigNumber | Complex>(x: T): T };
Calculate the hyperbolic sine of a value, defined as sinh(x) = 1/2 * (exp(x) - exp(-x)).
Parameter x
Function input
Returns
The hyperbolic sine of x
method size
size: ( x: boolean | number | Complex | Unit | string | MathCollection) => MathCollection;
Calculate the size of a matrix or scalar.
Parameter A
matrix
Returns
A vector with the size of x
method slu
slu: (A: Matrix, order: number, threshold: number) => SLUDecomposition;
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
Parameter A
A two dimensional sparse matrix for which to get the LU decomposition.
Parameter order
The Symbolic Ordering and Analysis order: 0 - Natural ordering, no permutation vector q is returned 1 - Matrix must be square, symbolic ordering and analisis 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.
Parameter threshold
Partial pivoting threshold (1 for partial pivoting)
Returns
The lower triangular matrix, the upper triangular matrix and the permutation vectors.
method smaller
smaller: ( x: MathType | string, y: MathType | string) => boolean | MathCollection;
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.
Parameter x
First value to compare
Parameter y
Second value to vcompare
Returns
Returns true when x is smaller than y, else returns false
method smallerEq
smallerEq: ( x: MathType | string, y: MathType | string) => boolean | MathCollection;
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.
Parameter x
First value to compare
Parameter y
Second value to vcompare
Returns
Returns true when x is smaller than or equal to y, else returns false
method sort
sort: <T extends MathCollection<any>>( x: T, compare: 'asc' | 'desc' | ((a: any, b: any) => number) | 'natural') => T;
Sort the items in a matrix
Parameter x
A one dimensional matrix or array to sort
Parameter compare
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
Returns the sorted matrix
method sparse
sparse: (data?: MathCollection, dataType?: string) => 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.
Parameter data
A two dimensional array
Parameter dataType
Sparse Matrix data type
Returns
The created matrix
method splitUnit
splitUnit: (unit: Unit, parts: Unit[]) => Unit[];
Split a unit in an array of units whose sum is equal to the original unit.
Parameter unit
A unit to be split
Parameter parts
An array of strings or valueless units
Returns
An array of units
method sqrt
sqrt: { (x: number): number | Complex; <T extends BigNumber | Complex | Unit>(x: T): T;};
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.
Parameter x
Value for which to calculate the square root
Returns
Returns the square root of x
method sqrtm
sqrtm: <T extends MathCollection<any>>(A: T) => T;
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.
Parameter A
The square matrix A
Returns
The principal square root of matrix A
method square
square: <T extends unknown>(x: T) => T;
Compute the square of a value, x * x.
Parameter x
Number for which to calculate the square
Returns
Squared value
method squeeze
squeeze: <T extends MathCollection<any>>(x: T) => T;
Squeeze a matrix, remove inner and outer singleton dimensions from a matrix.
Parameter x
Matrix to be squeezed
Returns
Squeezed matrix
method std
std: { <T extends unknown>(...args: T[]): T; (...args: any[]): any; ( array: MathCollection<any>, dimension?: number, normalization?: 'unbiased' | 'uncorrected' | 'biased' ): any[]; ( array: MathCollection<any>, normalization: 'unbiased' | 'uncorrected' | 'biased' ): any;};
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)
Parameter args
variadic argument of number to calculate standard deviation
Returns
The standard deviation
Parameter args
Multiple scalar values
Returns
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)
Parameter array
A single matrix to compute standard deviation.
Parameter dimension
A dimension to calculate standard deviation
Parameter normalization
Determines how to normalize the variance. Choose ‘unbiased’ (default), ‘uncorrected’, or ‘biased’. Default value: ‘unbiased’.
Returns
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)
Parameter array
A single matrix or multiple scalar values
Parameter normalization
Determines how to normalize the variance. Choose ‘unbiased’ (default), ‘uncorrected’, or ‘biased’. Default value: ‘unbiased’.
Returns
The standard deviation
method stirlingS2
stirlingS2: <T extends number | BigNumber>( n: T, k: number | BigNumber) => NoLiteralType<T>;
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
Parameter n
Total number of objects in the set
Parameter k
Number of objects in the subset
Returns
S(n,k)
method string
string: { (value: MathNumericType | string | Unit | null): string; (value: MathCollection<any>): MathCollection<any>;};
Create a string or convert any object into a string. Elements of Arrays and Matrices are processed element wise.
Parameter value
A value to convert to a string
Returns
The created string
method subset
subset: <T extends string | MathCollection<any>>( value: T, index: Index, replacement?: any, defaultValue?: any) => T;
Get or set a subset of a matrix or string.
Parameter value
An array, matrix, or string
Parameter index
For each dimension, an index or list of indices to get or set.
Parameter replacement
An array, matrix, or scalar. If provided, the subset is replaced with replacement. If not provided, the subset is returned
Parameter defaultValue
Default value, filled in on new entries when the matrix is resized. If not provided, math.matrix elements will be left undefined. Default value: undefined.
Returns
Either the retrieved subset or the updated matrix
method subtract
subtract: { <T extends unknown>(x: T, y: T): T; (x: any, y: any): any };
Subtract two values, x - y. For matrices, the function is evaluated element wise.
Parameter x
Initial value
Parameter y
Value to subtract from x
Returns
Subtraction of x and y
method sum
sum: { <T extends unknown>(...args: T[]): T; (...args: any[]): any; <T extends unknown>(A: T[] | T[][], dimension?: number | BigNumber): T; (A: MathCollection<any>, dimension?: number | BigNumber): any;};
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.
Parameter args
A single matrix or multiple scalar values
Returns
The sum of all values
Parameter args
Multiple scalar values
Returns
The sum of all values
Parameter A
A single matrix
Parameter dimension
The sum over the selected dimension
Returns
The sum of all values
method sylvester
sylvester: ( A: MathCollection, B: MathCollection, C: MathCollection) => MathCollection;
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
Parameter A
Matrix A
Parameter B
Matrix B
Parameter C
Matrix C
Returns
Matrix X, solving the Sylvester equation
method symbolicEqual
symbolicEqual: ( expr1: MathNode, expr2: MathNode, options?: SimplifyOptions) => boolean;
Determines if two expressions are symbolically equal, i.e. one is the result of valid algebraic manipulations on the other.
Parameter expr1
The first expression to compare
Parameter expr2
The second expression to compare
Parameter options
Optional option object, passed to simplify
Returns
{boolean} Returns true if a valid manipulation making the expressions equal is found.
method tan
tan: { (x: number | Unit): number; <T extends BigNumber | Complex>(x: T): T };
Calculate the tangent of a value. tan(x) is equal to sin(x) / cos(x).
Parameter x
Function input
Returns
The tangent of x
method tanh
tanh: { (x: number | Unit): number; <T extends BigNumber | Complex>(x: T): T };
Calculate the hyperbolic tangent of a value, defined as tanh(x) = (exp(2 * x) - 1) / (exp(2 * x) + 1).
Parameter x
Function input
Returns
The hyperbolic tangent of x
method to
to: (x: Unit | MathCollection, unit: Unit | string) => Unit | MathCollection;
Change the unit of a value. For matrices, the function is evaluated element wise.
Parameter x
The unit to be converted.
Parameter unit
New unit. Can be a string like "cm" or a unit without value.
Returns
Value with changed, fixed unit
method trace
trace: (x: MathCollection) => number;
Calculate the trace of a matrix: the sum of the elements on the main diagonal of a square matrix.
Parameter x
A matrix
Returns
The trace of x
method transpose
transpose: <T extends MathCollection<any>>(x: T) => T;
Transpose a matrix. All values of the matrix are reflected over its main diagonal. Only two dimensional matrices are supported.
Parameter x
Matrix to be transposed
Returns
The transposed matrix
method typeOf
typeOf: (x: any) => string;
Determine the type of a variable.
Parameter x
The variable for which to test the type
Returns
Returns the name of the type. Primitive types are lower case, non-primitive types are upper-camel-case. For example ‘number’, ‘string’, ‘Array’, ‘Date’.
method unaryMinus
unaryMinus: <T extends unknown>(x: T) => T;
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.
Parameter x
Number to be inverted
Returns
Retursn the value with inverted sign
method unaryPlus
unaryPlus: <T extends unknown>(x: T) => T;
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.
Parameter x
Input value
Returns
Returns the input value when numeric, converts to a number when input is non-numeric.
method unequal
unequal: ( x: MathType | string, y: MathType | string) => boolean | MathCollection;
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.
Parameter x
First value to compare
Parameter y
Second value to vcompare
Returns
Returns true when the compared values are unequal, else returns false
method unit
unit: { (unit: string): Unit; (unit: Unit): Unit; (value: any, unit: string): Unit; (value: MathCollection<any>, unit: string): Unit[];};
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.
Parameter unit
The unit to be created
Returns
The created unit
Parameter unit
The unit to be created
Returns
The created unit
Parameter value
The value of the unit to be created
Parameter unit
The unit to be created
Returns
The created unit
method usolve
usolve: { (U: Matrix, b: MathCollection): Matrix; (U: MathArray<any>, b: MathCollection<any>): MathArray<any>;};
Solves the linear equation system by backward substitution. Matrix must be an upper triangular matrix. U * x = b
Parameter U
A N x N matrix or array (U)
Parameter b
A column vector with the b values
Returns
A column vector with the linear system solution (x)
method variance
variance: { (...args: MathNumericType[]): MathNumericType; ( array: MathCollection<any>, dimension?: number, normalization?: 'unbiased' | 'uncorrected' | 'biased' ): any[]; ( array: MathCollection<any>, normalization: 'unbiased' | 'uncorrected' | 'biased' ): any;};
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 + 1) Note that older browser may not like the variable name var. In that case, the function can be called as math['var'](...) instead of math.variance(...).
Parameter args
A single matrix or multiple scalar values
Returns
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 + 1) Note that older browser may not like the variable name var. In that case, the function can be called as math['var'](...) instead of math.variance(...).
Parameter array
A matrix to compute variance.
Parameter dimension
A dimension to compute variance on
Parameter normalization
normalization Determines how to normalize the variance. Choose ‘unbiased’ (default), ‘uncorrected’, or ‘biased’. Default value: ‘unbiased’.
Returns
variance matrix.
Parameter array
A single matrix
Parameter normalization
normalization Determines how to normalize the variance. Choose ‘unbiased’ (default), ‘uncorrected’, or ‘biased’. Default value: ‘unbiased’.
Returns
The variance
method xgcd
xgcd: (a: number | BigNumber, b: number | BigNumber) => MathArray;
Calculate the extended greatest common divisor for two values. See http://en.wikipedia.org/wiki/Extended_Euclidean_algorithm.
Parameter a
An integer number
Parameter b
An integer number
Returns
Returns an array containing 3 integers [div, m, n] where div = gcd(a, b) and a*m + b*n = div
method xor
xor: ( x: number | BigNumber | bigint | Complex | Unit | MathCollection, y: number | BigNumber | bigint | Complex | Unit | MathCollection) => boolean | MathCollection;
Logical xor. Test whether one and only one value is defined with a nonzero/nonempty value. For matrices, the function is evaluated element wise.
Parameter x
First value to xor
Parameter y
Second value to xor
Returns
Returns true when one and only one input is defined with a nonzero/nonempty value.
method zeros
zeros: { ( size?: number | number[] | BigNumber | BigNumber[], format?: string ): MathCollection; ( m: number | BigNumber, n: number | BigNumber, format?: string ): MathCollection<any>; ( m: number | BigNumber, n: number | BigNumber, p: number | BigNumber, format?: string ): MathCollection<any>;};
Create a matrix filled with zeros. The created matrix can have one or multiple dimensions.
Parameter size
The size of each dimension of the matrix
Parameter format
The matrix storage format
Returns
A matrix filled with zeros
Parameter m
The x dimension of the matrix
Parameter n
The y dimension of the matrix
Parameter format
The matrix storage format
Returns
A matrix filled with zeros
Parameter m
The x dimension of the matrix
Parameter n
The y dimension of the matrix
Parameter p
The z dimension of the matrix
Parameter format
The matrix storage format
Returns
A matrix filled with zeros
method zeta
zeta: <T extends number | BigNumber | Complex>(s: T) => T;
Compute the Riemann Zeta function of a value using an infinite series and Riemann's Functional equation.
Parameter s
A real, complex or BigNumber
Returns
The Riemann Zeta of s
method zpk2tf
zpk2tf: <T extends MathCollection<any>>(z: T, p: T, k?: number) => T;
Compute the transfer function of a zero-pole-gain model.
Parameter z
Zeroes of the model
Parameter p
Poles of the model
Parameter k
Gain of the model
Returns
The transfer function as array of numerator and denominator
interface MathJSON
interface MathJSON {}
interface MathNode
interface MathNode {}
property comment
comment: string;
property isNode
isNode: true;
property isUpdateNode
isUpdateNode?: boolean;
property type
type: string;
method clone
clone: () => this;
Create a shallow clone of the node. The node itself is cloned, its childs are not cloned.
method cloneDeep
cloneDeep: () => this;
Create a deep clone of the node. Both the node as well as all its childs are cloned recursively.
method compile
compile: () => EvalFunction;
Compile an expression into optimized JavaScript code. compile returns an object with a function evaluate([scope]) to evaluate. Example:
method equals
equals: (other: MathNode) => boolean;
Test whether this node equals an other node. Does a deep comparison of the values of both nodes.
method evaluate
evaluate: (expr?: any) => any;
Compile and eval an expression, this is the equivalent of doing node.compile().evaluate(scope). Example:
method filter
filter: ( callback: (node: MathNode, path: string, parent: MathNode) => any) => MathNode[];
Filter nodes in an expression tree. The callback function is called as callback(node: MathNode, path: string, parent: MathNode) : boolean for every node in the tree, and must return a boolean. The function filter returns an array with nodes for which the test returned true. Parameter path is a string containing a relative JSON Path.
Example:
var node = math.parse('x^2 + x/4 + 3*y');var filtered = node.filter(function (node) {return node.isSymbolMathNode && node.name == 'x';});// returns an array with two entries: two SymbolMathNodes 'x'The callback function is called as callback(node: MathNode, path: string, parent: MathNode) : boolean for every node in the tree, and must return a boolean. The function filter returns an array with nodes for which the test returned true. Parameter path is a string containing a relative JSON Path. Returns an array with nodes for which test returned true
method forEach
forEach: ( callback: (node: MathNode, path: string, parent: MathNode) => void) => void;
[forEach description]
method map
map: ( callback: (node: MathNode, path: string, parent: MathNode) => MathNode) => MathNode;
Transform a node. Creates a new MathNode having it’s child's be the results of calling the provided callback function for each of the child's of the original node. The callback function is called as
callback(child: MathNode, path: string, parent: MathNode)
and must return a MathNode. Parameter path is a string containing a relative JSON Path.See also transform, which is a recursive version of map.
method toHTML
toHTML: (options?: object) => string;
Get a HTML representation of the parsed expression.
method toString
toString: (options?: object) => string;
Get a string representation of the parsed expression. This is not exactly the same as the original input.
method toTex
toTex: (options?: object) => string;
Get a LaTeX representation of the expression.
method transform
transform: <TResult>( callback: (node: this, path: string, parent: MathNode) => TResult) => TResult;
Recursively transform an expression tree via a transform function. Similar to Array.map, but recursively executed on all nodes in the expression tree. The callback function is a mapping function accepting a node, and returning a replacement for the node or the original node. Function callback is called as callback(node: MathNode, path: string, parent: MathNode) for every node in the tree, and must return a MathNode. Parameter path is a string containing a relative JSON Path.
For example, to replace all nodes of type SymbolMathNode having name ‘x’ with a ConstantMathNode with value 3:
var node = math.parse('x^2 + 5*x');var transformed = node.transform(function (node, path, parent) {if (node.SymbolMathNode && node.name == 'x') {return new math.expression.node.ConstantMathNode(3);}else {return node;}});transformed.toString(); // returns '(3 ^ 2) + (5 * 3)'
method traverse
traverse: ( callback: (node: MathNode, path: string, parent: MathNode) => void) => void;
traverse(callback)
Recursively traverse all nodes in a node tree. Executes given callback for this node and each of its child nodes. Similar to Array.forEach, except recursive. The callback function is a mapping function accepting a node, and returning a replacement for the node or the original node. Function callback is called as callback(node: MathNode, path: string, parent: MathNode) for every node in the tree. Parameter path is a string containing a relative JSON Path. Example:
var node = math.parse('3 * x + 2');node.traverse(function (node, path, parent) {switch (node.type) {case 'OperatorMathNode': console.log(node.type, node.op); break;case 'ConstantMathNode': console.log(node.type, node.value); break;case 'SymbolMathNode': console.log(node.type, node.name); break;default: console.log(node.type);}});// outputs:// OperatorMathNode +// OperatorMathNode *// ConstantMathNode 3// SymbolMathNode x// ConstantMathNode 2
interface Matrix
interface Matrix<T = MathGeneric> {}
property type
type: string;
method clone
clone: () => Matrix<T>;
method create
create: (data: MathArray, datatype?: string) => void;
method datatype
datatype: () => string;
method density
density: () => number;
method diagonal
diagonal: (k?: number | BigNumber) => any[];
method forEach
forEach: ( callback: (a: any, b: number[], c: Matrix) => void, skipZeros?: boolean) => void;
method format
format: ( options?: number | BigNumber | FormatOptions | ((value: any) => string)) => string;
method get
get: (index: number[]) => any;
method map
map: ( callback: (a: any, b: number[], c: Matrix) => any, skipZeros?: boolean) => Matrix;
method resize
resize: (size: MathCollection, defaultValue?: number | string) => Matrix;
method set
set: (index: number[], value: any, defaultValue?: number | string) => Matrix;
method size
size: () => number[];
method storage
storage: () => string;
method subset
subset: (index: Index, replacement?: any, defaultValue?: any) => Matrix;
method swapRows
swapRows: (i: number, j: number) => Matrix<T>;
method toArray
toArray: () => MathArray<T>;
method toJSON
toJSON: () => any;
method toString
toString: () => string;
method valueOf
valueOf: () => MathArray<T>;
interface MatrixCtor
interface MatrixCtor {}
construct signature
new (): Matrix;
interface NodeCtor
interface NodeCtor {}
construct signature
new (): MathNode;
interface ObjectNode
interface ObjectNode< TProps extends Record<string, MathNode> = Record<string, MathNode>> extends MathNode {}
property isObjectNode
isObjectNode: true;
property properties
properties: TProps;
property type
type: 'ObjectNode';
interface ObjectNodeCtor
interface ObjectNodeCtor {}
construct signature
new <TProps extends Record<string, MathNode> = Record<string, MathNode>>( properties: TProps): ObjectNode<TProps>;
interface ObjectWrappingMap
interface ObjectWrappingMap<T extends string | number | symbol, U> {}
property wrappedObject
wrappedObject: Record<T, U>;
interface OperatorNode
interface OperatorNode< TOp extends OperatorNodeMap[TFn] = never, TFn extends OperatorNodeFn = never, TArgs extends MathNode[] = MathNode[]> extends MathNode {}
interface OperatorNodeCtor
interface OperatorNodeCtor extends MathNode {}
construct signature
new < TOp extends OperatorNodeMap[TFn], TFn extends OperatorNodeFn, TArgs extends MathNode[]>( op: TOp, fn: TFn, args: [...TArgs], implicit?: boolean): OperatorNode<TOp, TFn, TArgs>;
interface ParenthesisNode
interface ParenthesisNode<TContent extends MathNode = MathNode> extends MathNode {}
property content
content: TContent;
property isParenthesisNode
isParenthesisNode: true;
property type
type: 'ParenthesisNode';
interface ParenthesisNodeCtor
interface ParenthesisNodeCtor {}
construct signature
new <TContent extends MathNode>(content: TContent): ParenthesisNode<TContent>;
interface ParseFunction
interface ParseFunction {}
Parse an expression. Returns a node tree, which can be evaluated by invoking node.evaluate().
Note the evaluating arbitrary expressions may involve security risks, see [https://mathjs.org/docs/expressions/security.html](https://mathjs.org/docs/expressions/security.html) for more information.
Syntax:
math.parse(expr) math.parse(expr, options) math.parse([expr1, expr2, expr3, ...]) math.parse([expr1, expr2, expr3, ...], options)
Example:
const node1 = math.parse('sqrt(3^2 + 4^2)') node1.compile().evaluate() // 5
let scope = {a:3, b:4} const node2 = math.parse('a * b') // 12 const code2 = node2.compile() code2.evaluate(scope) // 12 scope.a = 5 code2.evaluate(scope) // 20
const nodes = math.parse(['a = 3', 'b = 4', 'a * b']) nodes[2].compile().evaluate() // 12
See also:
evaluate, compile
method isAlpha
isAlpha: (c: string, cPrev: string, cNext: string) => boolean;
Checks whether the current character
c
is a valid alpha character:- A latin letter (upper or lower case) Ascii: a-z, A-Z - An underscore Ascii: _ - A dollar sign Ascii: $ - A latin letter with accents Unicode: \u00C0 - \u02AF - A greek letter Unicode: \u0370 - \u03FF - A mathematical alphanumeric symbol Unicode: \u{1D400} - \u{1D7FF} excluding invalid code points
The previous and next characters are needed to determine whether this character is part of a unicode surrogate pair.
Parameter c
Current character in the expression
Parameter cPrev
Previous character
Parameter cNext
Next character
method isDecimalMark
isDecimalMark: (c: string, cNext: string) => boolean;
Test whether the character c is a decimal mark (dot). This is the case when it's not the start of a delimiter '.*', './', or '.^'
Parameter c
Parameter cNext
method isDigit
isDigit: (c: string) => boolean;
checks if the given char c is a digit
Parameter c
a string with one character
method isDigitDot
isDigitDot: (c: string) => boolean;
checks if the given char c is a digit or dot
Parameter c
a string with one character
method isHexDigit
isHexDigit: (c: string) => boolean;
checks if the given char c is a hex digit
Parameter c
a string with one character
method isValidLatinOrGreek
isValidLatinOrGreek: (c: string) => boolean;
Test whether a character is a valid latin, greek, or letter-like character
Parameter c
method isValidMathSymbol
isValidMathSymbol: (high: string, low: string) => boolean;
Test whether two given 16 bit characters form a surrogate pair of a unicode math symbol.
https://unicode-table.com/en/ https://www.wikiwand.com/en/Mathematical_operators_and_symbols_in_Unicode
Note: In ES6 will be unicode aware: https://stackoverflow.com/questions/280712/javascript-unicode-regexes https://mathiasbynens.be/notes/es6-unicode-regex
Parameter high
Parameter low
method isWhitespace
isWhitespace: (c: string, nestingLevel: number) => boolean;
Check whether given character c is a white space character: space, tab, or enter
Parameter c
Parameter nestingLevel
call signature
(expr: MathExpression, options?: ParseOptions): MathNode;
Parse an expression. Returns a node tree, which can be evaluated by invoking node.evaluate();
Parameter expr
Expression to be parsed
Parameter options
Available options
Returns
A node
call signature
(exprs: MathExpression[], options?: ParseOptions): MathNode[];
Parse an expression. Returns a node tree, which can be evaluated by invoking node.evaluate();
Parameter exprs
Expressions to be parsed
Parameter options
Available options
Returns
An array of nodes
interface ParseOptions
interface ParseOptions {}
Available options for parse
property nodes
nodes?: Record<string, MathNode>;
a set of custom nodes
interface Parser
interface Parser {}
property clear
clear: () => void;
Completely clear the parser’s scope.
property remove
remove: (name: string) => void;
Remove a variable or function from the parser’s scope.
Parameter name
The name of the variable or function to be removed
property set
set: (name: string, value: any) => void;
Set a variable or function in the parser’s scope.
Parameter name
The name of the variable or function to be set
Parameter value
The value of the variable or function to be set
method evaluate
evaluate: (expr: string | string[]) => any;
Evaluate an expression. Returns the result of the expression.
Parameter expr
The expression to evaluate
method get
get: (name: string) => any;
Retrieve a variable or function from the parser’s scope.
Parameter name
The name of the variable or function to be retrieved
method getAll
getAll: () => { [key: string]: any };
Retrieve an object with all defined variables in the parser’s scope.
Returns
An object with all defined variables
method getAllAsMap
getAllAsMap: () => Map<string, any>;
Retrieve a map with all defined variables in the parser’s scope.
interface PartitionedMap
interface PartitionedMap<T, U> {}
interface PolarCoordinates
interface PolarCoordinates {}
interface QRDecomposition
interface QRDecomposition {}
interface RangeNode
interface RangeNode< TStart extends MathNode = MathNode, TEnd extends MathNode = MathNode, TStep extends MathNode = MathNode> extends MathNode {}
property end
end: TEnd;
property isRangeNode
isRangeNode: true;
property start
start: TStart;
property step
step: TStep | null;
property type
type: 'RangeNode';
interface RangeNodeCtor
interface RangeNodeCtor {}
construct signature
new < TStart extends MathNode = MathNode, TEnd extends MathNode = MathNode, TStep extends MathNode = MathNode>( start: TStart, end: TEnd, step?: TStep): RangeNode<TStart, TEnd, TStep>;
interface RelationalNode
interface RelationalNode<TParams extends MathNode[] = MathNode[]> extends MathNode {}
property conditionals
conditionals: string[];
property isRelationalNode
isRelationalNode: true;
property params
params: [...TParams];
property type
type: 'RelationalNode';
interface RelationalNodeCtor
interface RelationalNodeCtor {}
construct signature
new <TParams extends MathNode[] = MathNode[]>( conditionals: string[], params: [...TParams]): RelationalNode<TParams>;
interface SchurDecomposition
interface SchurDecomposition {}
interface Simplify
interface Simplify {}
property rules
rules: SimplifyRule[];
call signature
(expr: MathNode | string): MathNode;
call signature
( expr: MathNode | string, rules: SimplifyRule[], scope?: object, options?: SimplifyOptions): MathNode;
call signature
(expr: MathNode | string, scope: object, options?: SimplifyOptions): MathNode;
interface SimplifyOptions
interface SimplifyOptions {}
property consoleDebug
consoleDebug?: boolean;
A boolean which is
false
by default.
property context
context?: SimplifyContext;
gives properties of each operator, which determine what simplifications are allowed. Properties are commutative, associative, total (whether the operation is defined for all arguments), and trivial (whether the operation applied to a single argument leaves that argument unchanged).
property exactFractions
exactFractions?: boolean;
A boolean which is
true
by default.
property fractionsLimit
fractionsLimit?: number;
When
exactFractions
is true, a fraction will be returned only when both numerator and denominator are smaller thanfractionsLimit
. Default value is 10000.
interface SLUDecomposition
interface SLUDecomposition extends LUDecomposition {}
property q
q: number[];
interface SymbolNode
interface SymbolNode extends MathNode {}
interface SymbolNodeCtor
interface SymbolNodeCtor {}
property onUndefinedSymbol
onUndefinedSymbol: (name: string) => any;
construct signature
new (name: string): SymbolNode;
interface Unit
interface Unit {}
property dimensions
dimensions: number[];
property fixPrefix
fixPrefix: boolean;
property skipAutomaticSimplification
skipAutomaticSimplification: true;
property units
units: UnitComponent[];
property value
value: number;
method abs
abs: (unit: Unit) => Unit;
method clone
clone: () => Unit;
method divide
divide: (unit: Unit) => Unit | number;
method equalBase
equalBase: (unit: Unit) => boolean;
method equals
equals: (unit: Unit) => boolean;
method format
format: (options: FormatOptions) => string;
method formatUnits
formatUnits: () => string;
method hasBase
hasBase: (base: BaseUnit | string | undefined) => boolean;
method multiply
multiply: (unit: Unit) => Unit;
method pow
pow: (unit: Unit) => Unit;
method simplify
simplify: () => Unit;
method splitUnit
splitUnit: (parts: ReadonlyArray<string | Unit>) => Unit[];
method to
to: (unit: string) => Unit;
method toJSON
toJSON: () => MathJSON;
method toNumber
toNumber: (unit?: string) => number;
method toNumeric
toNumeric: (unit?: string) => number | Fraction | BigNumber;
method toSI
toSI: () => Unit;
method toString
toString: () => string;
method valueOf
valueOf: () => string;
interface UnitComponent
interface UnitComponent {}
interface UnitCtor
interface UnitCtor extends UnitStatic {}
construct signature
new ( value: number | BigNumber | Fraction | Complex | boolean, name: string): Unit;
interface UnitDefinition
interface UnitDefinition {}
property aliases
aliases?: string[];
property baseName
baseName?: string;
property definition
definition?: string | Unit;
property offset
offset?: number;
property prefixes
prefixes?: string;
interface UnitPrefix
interface UnitPrefix {}
interface UnitStatic
interface UnitStatic {}
property BASE_DIMENSIONS
BASE_DIMENSIONS: string[];
property BASE_UNITS
BASE_UNITS: Record<string, BaseUnit>;
property PREFIXES
PREFIXES: Record<string, UnitPrefix>;
property UNIT_SYSTEMS
UNIT_SYSTEMS: Record< UnitSystemName, Record<string, { unit: Unit; prefix: UnitPrefix }>>;
property UNITS
UNITS: Record<string, Unit>;
method createUnit
createUnit: ( obj: Record<string, string | Unit | UnitDefinition>, options?: { override: boolean }) => Unit;
method createUnitSingle
createUnitSingle: ( name: string, definition: string | Unit | UnitDefinition) => Unit;
method fromJSON
fromJSON: (json: MathJSON) => Unit;
method getUnitSystem
getUnitSystem: () => UnitSystemName;
method isValidAlpha
isValidAlpha: (c: string) => boolean;
method isValuelessUnit
isValuelessUnit: (name: string) => boolean;
method parse
parse: (str: string) => Unit;
method setUnitSystem
setUnitSystem: (name: UnitSystemName) => void;
Type Aliases
type FactoryDependencies
type FactoryDependencies = void;
Deprecated
since v12.0.0. Use MathJsFactory instead and import dependency maps directly from the library
type FactoryFunction
type FactoryFunction<T> = (scope: any) => T;
type MathArray
type MathArray<T = MathGeneric> = T[] | Array<MathArray<T>>;
type MathCollection
type MathCollection<T = MathGeneric> = MathArray<T> | Matrix<T>;
type MathExpression
type MathExpression = string | string[] | MathCollection;
type MathGeneric
type MathGeneric<T extends MathScalarType = MathNumericType> = T;
type MathJsFunctionName
type MathJsFunctionName = keyof MathJsInstance;
type MathJsStatic
type MathJsStatic = MathJsInstance;
Deprecated
since v12.0.0. The interface MathJsStatic has been renamed to MathJsInstance
type MathNodeCommon
type MathNodeCommon = MathNode;
Deprecated
since version 11.3. Prefer
MathNode
instead
type MathNumericType
type MathNumericType = number | BigNumber | bigint | Fraction | Complex;
type MathScalarType
type MathScalarType = MathNumericType | Unit;
type MathType
type MathType = MathScalarType | MathCollection;
type MatrixFromFunctionCallback
type MatrixFromFunctionCallback<T extends MathScalarType> = (index: number[]) => T;
type MatrixStorageFormat
type MatrixStorageFormat = 'dense' | 'sparse';
type NoLiteralType
type NoLiteralType<T> = T extends number ? number : T extends string ? string : T extends boolean ? boolean : T;
type OperatorNodeFn
type OperatorNodeFn = keyof OperatorNodeMap;
type OperatorNodeMap
type OperatorNodeMap = { xor: 'xor'; and: 'and'; or: 'or'; bitOr: '|'; bitXor: '^|'; bitAnd: '&'; equal: '=='; unequal: '!='; smaller: '<'; larger: '>'; smallerEq: '<='; largerEq: '>='; leftShift: '<<'; rightArithShift: '>>'; rightLogShift: '>>>'; to: 'to'; add: '+'; subtract: '-'; multiply: '*'; divide: '/'; dotMultiply: '.*'; dotDivide: './'; mod: 'mod'; unaryPlus: '+'; unaryMinus: '-'; bitNot: '~'; not: 'not'; pow: '^'; dotPow: '.^'; factorial: '!';};
type OperatorNodeOp
type OperatorNodeOp = OperatorNodeMap[keyof OperatorNodeMap];
type SimplifyContext
type SimplifyContext = Partial< Record< OperatorNodeFn, { trivial: boolean; total: boolean; commutative: boolean; associative: boolean; } >>;
type SimplifyRule
type SimplifyRule = | { l: string; r: string; repeat?: boolean; assuming?: SimplifyContext; imposeContext?: SimplifyContext; } | { s: string; repeat?: boolean; assuming?: SimplifyContext; imposeContext?: SimplifyContext; } | string | ((node: MathNode) => MathNode);
type UnitSystemName
type UnitSystemName = 'si' | 'cgs' | 'us' | 'auto';
Package Files (1)
Dependencies (9)
Dev Dependencies (59)
- @babel/core
- @babel/plugin-transform-object-assign
- @babel/plugin-transform-optional-catch-binding
- @babel/plugin-transform-runtime
- @babel/preset-env
- @babel/register
- @types/assert
- @types/mocha
- @typescript-eslint/eslint-plugin
- @typescript-eslint/parser
- assert
- babel-loader
- c8
- codecov
- core-js
- del
- dtslint
- eigen
- eslint
- eslint-config-prettier
- eslint-config-standard
- eslint-plugin-import
- eslint-plugin-mocha
- eslint-plugin-n
- eslint-plugin-prettier
- eslint-plugin-promise
- expect-type
- expr-eval
- fancy-log
- glob
- gulp
- gulp-babel
- handlebars
- jsep
- karma
- karma-firefox-launcher
- karma-mocha
- karma-mocha-reporter
- karma-spec-reporter
- karma-webdriver-launcher
- karma-webpack
- mkdirp
- mocha
- mocha-junit-reporter
- ndarray
- ndarray-determinant
- ndarray-gemm
- ndarray-ops
- ndarray-pack
- numericjs
- prettier
- process
- sinon
- sylvester
- tinybench
- ts-node
- typescript
- webpack
- zeros
Peer Dependencies (0)
No peer dependencies.
Badge
To add a badge like this oneto your package's README, use the codes available below.
You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/mathjs
.
- Markdown[](https://www.jsdocs.io/package/mathjs)
- HTML<a href="https://www.jsdocs.io/package/mathjs"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>
- Updated .
Package analyzed in 15437 ms. - Missing or incorrect documentation? Open an issue for this package.