mathjs
- Version 14.0.1
- Published
- 9.43 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()
- 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()
- matrix()
- Matrix
- 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
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> {}
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 apply
apply: <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 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 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 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