Math

Namespace

Namespace JXG.Math. Contains mathematics-related methods which are specific to JSXGraph or which extend the JavaScript Math class.

Members

Own

(private, static) Interval

Description

Interval for interval arithmetics. Consists of the properties

  • lo
  • hi
See
Source
math/ia.js, line 175

(static) eps : Number

Description

eps defines the closeness to zero. If the absolute value of a given number is smaller than eps, it is considered to be equal to zero.

Type
Number
Source
math/math.js, line 84

Inherited

none

Methods

Own

(static) Vieta(x) → {Array}

Theorem of Vieta: Given a set of simple zeroes x_0, ..., x_n of a polynomial f, compute the coefficients s_k, (k=0,...,n-1) of the polynomial of the form. See https://de.wikipedia.org/wiki/Elementarsymmetrisches_Polynom.

f(x) = (x-x_0)...(x-x_n) = x^n + sum_{k=1}^{n} (-1)^(k) s_{k-1} x^(n-k)

Parameters

Name Type Description
x Array

Simple zeroes of the polynomial.

Returns

Coefficients of the polynomial.

Type
Array

Details

Source
math/math.js, line 1445

(static) acosh(x) → {Number}

Hyperbolic arc-cosine of a number.

Parameters

Name Type Description
x Number

Returns

Type
Number

Details

Source
math/math.js, line 714

(static) acot(x) → {Number}

Computes the inverse cotangent of x.

Parameters

Name Type Description
x Number

The number the inverse cotangent will be calculated of.

Returns

Inverse cotangent of the given value.

Type
Number

Details

Source
math/math.js, line 754

(static) and(a, b) → {Boolean}

Logical operator: a && b?

Parameters

Name Type Description
a Boolean
b Boolean

Returns

Type
Boolean

Details

Source
math/math.js, line 1258

(static) asinh(x) → {Number}

Hyperbolic arcsine of a number

Parameters

Name Type Description
x Number

Returns

Type
Number

Details

Source
math/math.js, line 726

(static) axpy(a, x, y) → {Array}

Compute a * x + y for a scalar a and vectors x and y.

Parameters

Name Type Description
a Number
x Array
y Array

Returns

Type
Array

Details

Source
math/math.js, line 622

(static) binomial(n, k) → {Number}

Computes the binomial coefficient n over k.

Parameters

Name Type Description
n Number

Fraction will be ignored

k Number

Fraction will be ignored

Returns

The binomial coefficient n over k

Type
Number

Details

Source
math/math.js, line 660

(static) cbrt(x) → {Number}

Computes cube root of real number Polyfill for Math.cbrt().

Parameters

Name Type Description
x Number

Radicand

Returns

Cube root of x.

Type
Number

Details

Source
math/math.js, line 805

(static) clamp()

Clamp x within the interval [a, b]. If x is below a, increase it to a. If it's above b, decrease it to b.

Details

Source
math/math.js, line 128

(static) cosh(x) → {Number}

Calculates the cosine hyperbolicus of x.

Parameters

Name Type Description
x Number

The number the cosine hyperbolicus will be calculated of.

Returns

Cosine hyperbolicus of the given value.

Type
Number

Details

Source
math/math.js, line 690

(static) cot(x) → {Number}

Computes the cotangent of x.

Parameters

Name Type Description
x Number

The number the cotangent will be calculated of.

Returns

Cotangent of the given value.

Type
Number

Details

Source
math/math.js, line 741

(static) crossProduct(c1, c2) → {Array}

Calculates the cross product of two vectors both of length three. In case of homogeneous coordinates this is either

  • the intersection of two lines
  • the line through two points

Parameters

Name Type Description
c1 Array

Homogeneous coordinates of line or point 1

c2 Array

Homogeneous coordinates of line or point 2

Returns

vector of length 3: homogeneous coordinates of the resulting point / line.

Type
Array

Details

Source
math/math.js, line 584

(static) decToFraction(x, orderopt) → {Array}

Convert a floating point number to sign + integer + fraction. fraction is given as nominator and denominator.

Algorithm: approximate the floating point number by a continued fraction and simultaneously keep track of its convergents. Inspired by https://kevinboone.me/rationalize.html.

Example

JXG.Math.decToFraction(0.33333333);
// Result: [ 1, 0, 1, 3 ]

JXG.Math.decToFraction(0);
// Result: [ 1, 0, 0, 1 ]

JXG.Math.decToFraction(-10.66666666666667);
// Result: [-1, 10, 2, 3 ]

Parameters

Name Type Attributes Default Description
x Number

Number which is to be converted

order Number <optional>
0.001

Small number determining the approximation precision.

Returns

[sign, leading, nominator, denominator] where sign is 1 or -1.

Type
Array

Details

See
Source
math/math.js, line 1319

(static) eq(a, b) → {Boolean}

Logical test: a === b?

Parameters

Name Type Description
a Number
b Number

Returns

Type
Boolean

Details

Source
math/math.js, line 1236

(static) erf(x) → {Number}

Error function, see https://en.wikipedia.org/wiki/Error_function.

Parameters

Name Type Description
x Number

Returns

Type
Number

Details

See
Source
math/math.js, line 1064

(static) erfc(x) → {Number}

Complementary error function, i.e. 1 - erf(x).

Parameters

Name Type Description
x Number

Returns

Type
Number

Details

See
Source
math/math.js, line 1076

(static) erfi(x) → {Number}

Inverse of error function

Parameters

Name Type Description
x Number

Returns

Type
Number

Details

See
Source
math/math.js, line 1088

(static) factorial(n) → {Number}

Compute the factorial of a positive integer. If a non-integer value is given, the fraction will be ignored.

Parameters

Name Type Description
n Number

Returns

n! = n*(n-1)*...21

Type
Number

Details

Source
math/math.js, line 639

(static) frustum(l, r, t, b, n, f) → {Array}

Generates a 4x4 matrix for 3D to 2D projections.

Parameters

Name Type Description
l Number

Left

r Number

Right

t Number

Top

b Number

Bottom

n Number

Near

f Number

Far

Returns

4x4 Matrix

Type
Array

Details

Source
math/math.js, line 233

(static) gamma(z)

Gamma function for real parameters by Lanczos approximation. Implementation straight from https://en.wikipedia.org/wiki/Lanczos_approximation.

Parameters

Name Type Description
z Number

Returns

Number

Details

Source
math/math.js, line 1152

(static) gcd(a, b) → {Number}

Greatest common divisor (gcd) of two numbers. See href="https:\\/\\/rosettacode.org/wiki/Greatest_common_divisor#JavaScript">rosettacode.org.

Parameters

Name Type Description
a Number

First number

b Number

Second number

Returns

gcd(a, b) if a and b are numbers, NaN else.

Type
Number

Details

Source
math/math.js, line 960

(static) geq(a, b) → {Boolean}

Logical test: a >= b?

Parameters

Name Type Description
a Number
b Number

Returns

Type
Boolean

Details

Source
math/math.js, line 1225

(static) gt(a, b) → {Boolean}

Logical test: a > b?

Parameters

Name Type Description
a Number
b Number

Returns

Type
Boolean

Details

Source
math/math.js, line 1214

(static) hstep(x)

Heaviside unit step function. Returns 0 for x <, 1 for x > 0, and 0.5 for x == 0.

Parameters

Name Type Description
x Number

Returns

Number

Details

Source
math/math.js, line 1140

(static) hypot(a)

Returns sqrt(a * a + b * b) for a variable number of arguments. This is a naive implementation which might be faster than Math.hypot. The latter is numerically more stable.

Parameters

Name Type Description
a Number

Variable number of arguments.

Returns

Number

Details

Source
math/math.js, line 1123

(static) identity(n, mopt) → {Array}

Generates an identity matrix. If n is a number and m is undefined or not a number, a square matrix is generated, if n and m are both numbers, an nxm matrix is generated.

Parameters

Name Type Attributes Default Description
n Number

Number of rows

m Number <optional>
n

Number of columns

Returns

A square matrix of length n with all coefficients equal to 0 except a_(i,i), i out of (1, ..., n), if m is undefined or not a number or a n times m-matrix with a_(i,j) = 0 and a_(i,i) = 1 if m is a number.

Type
Array

Details

Source
math/math.js, line 207

(static) innerProduct(a, b, nopt) → {Number}

Inner product of two vectors a and b. n is the length of the vectors.

Parameters

Name Type Attributes Description
a Array

Vector

b Array

Vector

n Number <optional>

Length of the Vectors. If not given the length of the first vector is taken.

Returns

The inner product of a and b.

Type
Number

Details

Source
math/math.js, line 558

(static) inverse(A) → {Array}

Compute the inverse of an \((n \times n)\)-matrix by Gauss elimination.

Parameters

Name Type Description
A Array

matrix

Returns

Inverse matrix of A or empty array (i.e. []) in case A is singular.

Type
Array

Details

Source
math/math.js, line 448

(static) lcm(a, b) → {Number}

Least common multiple (lcm) of two numbers.

Parameters

Name Type Description
a Number

First number

b Number

Second number

Returns

lcm(a, b) if a and b are numbers, NaN else.

Type
Number

Details

Source
math/math.js, line 995

(static) leq(a, b) → {Boolean}

Logical test: a <= b?

Parameters

Name Type Description
a Number
b Number

Returns

Type
Boolean

Details

Source
math/math.js, line 1203

(static) log(x, b) → {Number}

Logarithm to arbitrary base b. If b is not given, natural log is taken, i.e. b = e.

Parameters

Name Type Description
x Number
b Number

base

Returns

log(x, b) Logarithm of x to base b, that is log(x)/log(b).

Type
Number

Details

Source
math/math.js, line 887

(static) log10(x) → {Number}

Logarithm to base 10.

Parameters

Name Type Description
x Number

Returns

log10(x) Logarithm of x to base 10.

Type
Number

Details

Source
math/math.js, line 868

(static) log2(x) → {Number}

Logarithm to base 2.

Parameters

Name Type Description
x Number

Returns

log2(x) Logarithm of x to base 2.

Type
Number

Details

Source
math/math.js, line 877

(static) lt(a, b) → {Boolean}

Logical test: a < b?

Parameters

Name Type Description
a Number
b Number

Returns

Type
Boolean

Details

Source
math/math.js, line 1192

(static) matMatAdd(mat1, mat2) → {Array}

Compute the sum of two matrices: mat1 + mat2. Returns a new matrix object.

Parameters

Name Type Description
mat1 Array

Two-dimensional array of numbers

mat2 Array

Two-dimensional array of numbers

Returns

Two-dimensional Array of numbers containing result

Type
Array

Details

Source
math/math.js, line 405

(static) matMatMult(mat1, mat2) → {Array}

Computes the product of the two matrices: mat1 * mat2. Returns a new matrix array.

Parameters

Name Type Description
mat1 Array

Two-dimensional array of numbers

mat2 Array

Two-dimensional array of numbers

Returns

Two-dimensional Array of numbers containing result

Type
Array

Details

Source
math/math.js, line 357

(static) matNumberMult(mat, alpha) → {Array}

Multiply a matrix mat by a scalar alpha: mat * scalar

Parameters

Name Type Description
mat Array

Two-dimensional array of numbers

alpha Number

Scalar

Returns

Two-dimensional Array of numbers containing result

Type
Array

Details

Source
math/math.js, line 383

(static) matVecMult(mat, vec) → {Array}

Multiplies a vector vec to a matrix mat: mat * vec. The matrix is interpreted by this function as an array of rows. Please note: This function does not check if the dimensions match.

Example

var A = [[2, 1],
         [2, 3]],
    b = [4, 5],
    c;
c = JXG.Math.matVecMult(A, b);
// c === [13, 23];

Parameters

Name Type Description
mat Array

Two-dimensional array of numbers. The inner arrays describe the columns, the outer ones the matrix' rows.

vec Array

Array of numbers

Returns

Array of numbers containing the result

Type
Array

Details

Source
math/math.js, line 289

(static) matrix(n, mopt, initopt) → {Array}

Initializes a matrix as an array of rows with the given value.

Parameters

Name Type Attributes Default Description
n Number

Number of rows

m Number <optional>
n

Number of columns

init Number <optional>
0

Initial value for each coefficient

Returns

A n times m-matrix represented by a two-dimensional array. The inner arrays hold the columns, the outer array holds the rows.

Type
Array

Details

Source
math/math.js, line 181

(static) mod(a, m) → {Number}

The JavaScript implementation of the % operator returns the symmetric modulo. mod and "%" are both identical if a >= 0 and m >= 0 but the results differ if a or m < 0.

Parameters

Name Type Description
a Number
m Number

Returns

Mathematical modulo \(a \bmod m\)

Type
Number

Details

Source
math/math.js, line 108

(static) ndtr(x) → {Number}

Normal distribution function

Parameters

Name Type Description
x Number

Returns

Type
Number

Details

See
Source
math/math.js, line 1099

(static) ndtri(x) → {Number}

Inverse of normal distribution function

Parameters

Name Type Description
x Number

Returns

Type
Number

Details

See
Source
math/math.js, line 1111

(static) neq(a, b) → {Boolean}

Logical test: a !== b?

Parameters

Name Type Description
a Number
b Number

Returns

Type
Boolean

Details

Source
math/math.js, line 1247

(static) norm(a, n) → {Number}

Euclidean norm of a vector.

Parameters

Name Type Description
a Array

Array containing a vector.

n Number

(Optional) length of the array.

Returns

Euclidean norm of the vector.

Type
Number

Details

Source
math/math.js, line 599

(private, static) normalize(stdform) → {Array}

Normalize the standard form [c, b0, b1, a, k, r, q0, q1].

Parameters

Name Type Description
stdform Array

The standard form to be normalized.

Returns

The normalized standard form.

Type
Array

Details

Source
math/math.js, line 1368

(static) not(a) → {Boolean}

Logical operator: !a?

Parameters

Name Type Description
a Boolean

Returns

Type
Boolean

Details

Source
math/math.js, line 1268

(static) nthroot(x, n) → {Number}

Compute n-th real root of a real number. n must be strictly positive integer. If n is odd, the real n-th root exists and is negative. For n even, for negative valuees of x NaN is returned

Example

nthroot(16, 4): 2
nthroot(-27, 3): -3
nthroot(-4, 2): NaN

Parameters

Name Type Description
x Number

radicand. Must be non-negative, if n even.

n Number

index of the root. must be strictly positive integer.

Returns

returns real root or NaN

Type
Number

Details

Source
math/math.js, line 771

(static) or(a, b) → {Boolean}

Logical operator: a || b?

Parameters

Name Type Description
a Boolean
b Boolean

Returns

Type
Boolean

Details

Source
math/math.js, line 1279

(static) pow(base, exponent) → {Number}

Compute base to the power of exponent.

Parameters

Name Type Description
base Number
exponent Number

Returns

base to the power of exponent.

Type
Number

Details

Source
math/math.js, line 817

(static) projection(fov, ratio, n, f) → {Array}

Generates a 4x4 matrix for 3D to 2D projections.

Parameters

Name Type Description
fov Number

Field of view in vertical direction, given in rad.

ratio Number

Aspect ratio of the projection plane.

n Number

Near

f Number

Far

Returns

4x4 Projection Matrix

Type
Array

Details

Source
math/math.js, line 267

(static) ratpow(base, m, n) → {Number}

Compute base to the power of the rational exponent m / n. This function first reduces the fraction m/n and then computes JXG.Math.pow(base, m/n).

This function is necessary to have the same results for e.g. (-8)^(1/3) = (-8)^(2/6) = -2

Parameters

Name Type Description
base Number
m Number

numerator of exponent

n Number

denominator of exponent

Returns

base to the power of exponent.

Type
Number

Details

Source
math/math.js, line 850

(static) relDif(a, b) → {Number}

Determine the relative difference between two numbers.

Parameters

Name Type Description
a Number

First number

b Number

Second number

Returns

Relative difference between a and b: |a-b| / max(|a|, |b|)

Type
Number

Details

Source
math/math.js, line 92

(static) roundToStep(value, step, minopt, maxopt) → {Number}

Special use of Math.round function to round not only to integers but also to chosen decimal values.

Parameters

Name Type Attributes Description
value Number

Value to be rounded.

step Number

Distance between the values to be rounded to. (default: 1.0)

min Number <optional>

If set, it will be returned the maximum of value and min.

max Number <optional>

If set, it will be returned the minimum of value and max.

Returns

Fitted value.

Type
Number

Details

Source
math/math.js, line 1019

(static) sign(x) → {Number}

The sign() function returns the sign of a number, indicating whether the number is positive, negative or zero.

Parameters

Name Type Description
x Number

A Number

Returns

This function has 5 kinds of return values, 1, -1, 0, -0, NaN, which represent "positive number", "negative number", "positive zero", "negative zero" and NaN respectively.

Type
Number

Details

Source
math/math.js, line 907

(static) sinh(x) → {Number}

Sine hyperbolicus of x.

Parameters

Name Type Description
x Number

The number the sine hyperbolicus will be calculated of.

Returns

Sine hyperbolicus of the given value.

Type
Number

Details

Source
math/math.js, line 702

(static) squampow(base, exponent) → {Number}

A square & multiply algorithm to compute base to the power of exponent. Implementated by Wolfgang Riedl.

Parameters

Name Type Description
base Number
exponent Number

Returns

Base to the power of exponent

Type
Number

Details

Source
math/math.js, line 925

(static) toGL(m) → {Float32Array}

Converts a two-dimensional array to a one-dimensional Float32Array that can be processed by WebGL.

Parameters

Name Type Description
m Array

A matrix in a two-dimensional array.

Returns

A one-dimensional array containing the matrix in column wise notation. Provides a fall back to the default JavaScript Array if Float32Array is not available.

Type
Float32Array

Details

Source
math/math.js, line 1411

(static) trace(M) → {Number}

Trace of a square matrix, given as a two-dimensional array.

Parameters

Name Type Description
M Array

Square matrix

Returns

The trace of M, NaN if M is not square.

Type
Number

Details

Source
math/math.js, line 533

(static) transpose(M) → {Array}

Transposes a matrix given as a two-dimensional array.

Parameters

Name Type Description
M Array

The matrix to be transposed

Returns

The transpose of M

Type
Array

Details

Source
math/math.js, line 424

(static) vecMatMult(vec, mat) → {Array}

Multiplies a vector vec to a matrix mat from the left: vec * mat. The matrix is interpreted by this function as an array of rows. Please note: This function does not check if the dimensions match.

Example

var A = [[2, 1],
         [2, 3]],
    b = [4, 5],
    c;
c = JXG.Math.vecMatMult(b, A);
// c === [18, 16];

Parameters

Name Type Description
vec Array

Array of numbers

mat Array

Two-dimensional array of numbers. The inner arrays describe the columns, the outer ones the matrix' rows.

Returns

Array of numbers containing the result

Type
Array

Details

Source
math/math.js, line 327

(static) vector(n, initopt) → {Array}

Initializes a vector of size n wih coefficients set to the init value (default 0)

Parameters

Name Type Attributes Default Description
n Number

Length of the vector

init Number <optional>
0

Initial value for each coefficient

Returns

An array of length n

Type
Array

Details

Source
math/math.js, line 160

(static) wrap(x, a, b)

Translate x into the interval [a, b) by adding a multiple of b - a.

Parameters

Name Type Description
x Number
a Number
b Number

Details

Source
math/math.js, line 119

(static) wrapAndClamp()

A way of clamping a periodic variable. If x is congruent mod period to a point in [a, b], return that point. Otherwise, wrap it into [mid - period/2, mid + period/2], where mid is the mean of a and b, and then clamp it to [a, b] from there.

Details

Source
math/math.js, line 139

(static) xor(a, b) → {Boolean}

Logical operator: either a or b?

Parameters

Name Type Description
a Boolean
b Boolean

Returns

Type
Boolean

Details

Source
math/math.js, line 1290

Inherited

none

Details

Math

Source
math/math.js, line 78

Classes

BoxQuadtree
Instantiate a new box quadtree.
ImplicitPlot
Quadtree
Instantiate a new quadtree.

Namespaces

Clip
JXG.Math.Clip namespace.
Extrapolate
JXG.Math.Extrapolate namespace.
Geometry
JXG.Math.Geometry namespace.
IntervalArithmetic
JXG.Math.IntervalArithmetic namespace.
Metapost
The JXG.Math.Metapost namespace holds algorithms converted from Metapost by D.E.
Nlp
The JXG.Math.Nlp namespace holds numerical algorithms for non-linear optimization, mainly the port of COBYLA.
Numerics
The JXG.Math.Numerics namespace holds numerical algorithms, constants, and variables.
Plot
The JXG.Math.Plot namespace holds various functions for plotting of curves.
Poly
The JXG.Math.Poly namespace holds algorithms to create and manipulate polynomials.
ProbFuncs
The JXG.Math.ProbFuncs namespace bundles various probability functions, e.g.
Statistics
JXG.Math.Statistics namespace with functions for mathematical statistics.
Tiling
The JXG.Math.Tiling namespace.