Namespace JXG.Math
↳ JXG.Math
Defined in: math.js.
Constructor Attributes | Constructor Name and Description |
---|---|
Math namespace.
|
Field Attributes | Field Name and Description |
---|---|
<static> |
JXG.Math.acosh
Hyperbolic arc-cosine of a number.
|
<static> |
JXG.Math.asinh
Hyperbolic arcsine of a number
|
<static> |
JXG.Math.eps
eps defines the closeness to zero.
|
<static> |
JXG.Math.Interval
Interval for interval arithmetics.
|
Method Attributes | Method Name and Description |
---|---|
<static> |
JXG.Math.acot(x)
Computes the inverse cotangent of x.
|
<static> |
JXG.Math.and(a, b)
Logical operator: a && b?
|
<static> |
JXG.Math.axpy(a, x, y)
Compute a * x + y for a scalar a and vectors x and y.
|
<static> |
JXG.Math.binomial(n, k)
Computes the binomial coefficient n over k.
|
<static> |
JXG.Math.cbrt(x)
Computes cube root of real number
Polyfill for Math.cbrt().
|
<static> |
JXG.Math.clamp(x, a, b)
Clamp
x within the interval [a, b] . |
<static> |
JXG.Math.cosh(x)
Calculates the cosine hyperbolicus of x.
|
<static> |
JXG.Math.cot(x)
Computes the cotangent of x.
|
<static> |
JXG.Math.crossProduct(c1, c2)
Calculates the cross product of two vectors both of length three.
|
<static> |
JXG.Math.decToFraction(x, order)
Convert a floating point number to sign + integer + fraction.
|
<static> |
JXG.Math.eq(a, b)
Logical test: a === b?
|
<static> |
JXG.Math.erf(x)
Error function, see https://en.wikipedia.org/wiki/Error_function.
|
<static> |
JXG.Math.erfc(x)
Complementary error function, i.e.
|
<static> |
JXG.Math.erfi(x)
Inverse of error function
|
<static> |
JXG.Math.factorial(n)
Compute the factorial of a positive integer.
|
<static> |
JXG.Math.frustum(l, r, t, b, n, f)
Generates a 4x4 matrix for 3D to 2D projections.
|
<static> |
JXG.Math.gamma(z)
Gamma function for real parameters by Lanczos approximation.
|
<static> |
JXG.Math.gcd(a, b)
Greatest common divisor (gcd) of two numbers.
|
<static> |
JXG.Math.geq(a, b)
Logical test: a >= b?
|
<static> |
JXG.Math.gt(a, b)
Logical test: a > b?
|
<static> |
JXG.Math.hstep(x)
Heaviside unit step function.
|
<static> |
JXG.Math.hypot(a)
Returns sqrt(a * a + b * b) for a variable number of arguments.
|
<static> |
JXG.Math.identity(n, m)
Generates an identity matrix.
|
<static> |
JXG.Math.innerProduct(a, b, n)
Inner product of two vectors a and b.
|
<static> |
JXG.Math.inverse(Ain)
Compute the inverse of an nxn matrix with Gauss elimination.
|
<static> |
JXG.Math.lcm(a, b)
Least common multiple (lcm) of two numbers.
|
<static> |
JXG.Math.leq(a, b)
Logical test: a <= b?
|
<static> |
JXG.Math.log(x, b)
Logarithm to arbitrary base b.
|
<static> |
JXG.Math.log10(x)
Logarithm to base 10.
|
<static> |
JXG.Math.log2(x)
Logarithm to base 2.
|
<static> |
JXG.Math.lt(a, b)
Logical test: a < b?
|
<static> |
JXG.Math.matMatMult(mat1, mat2)
Computes the product of the two matrices mat1*mat2.
|
<static> |
JXG.Math.matrix(n, m, init)
Initializes a matrix as an array of rows with the given value.
|
<static> |
JXG.Math.matVecMult(mat, vec)
Multiplies a vector vec to a matrix mat: mat * vec.
|
<static> |
JXG.Math.mod(a, m)
The JavaScript implementation of the % operator returns the symmetric modulo.
|
<static> |
JXG.Math.ndtr(x)
Normal distribution function
|
<static> |
JXG.Math.ndtri(x)
Inverse of normal distribution function
|
<static> |
JXG.Math.neq(a, b)
Logical test: a !== b?
|
<static> |
JXG.Math.norm(a, n)
Euclidean norm of a vector.
|
<private> <static> |
JXG.Math.normalize(stdform)
Normalize the standard form [c, b0, b1, a, k, r, q0, q1].
|
<static> |
JXG.Math.not(a)
Logical operator: !a?
|
<static> |
JXG.Math.nthroot(x, n)
Compute n-th real root of a real number.
|
<static> |
JXG.Math.or(a, b)
Logical operator: a || b?
|
<static> |
JXG.Math.pow(base, exponent)
Compute base to the power of exponent.
|
<static> |
JXG.Math.projection(fov, ratio, n, f)
Generates a 4x4 matrix for 3D to 2D projections.
|
<static> |
JXG.Math.ratpow(base, m, n)
Compute base to the power of the rational exponent m / n.
|
<static> |
JXG.Math.relDif(a, b)
Determine the relative difference between two numbers.
|
<static> |
JXG.Math.roundToStep(value, step, min, max)
Special use of Math.round function to round not only to integers but also to chosen decimal values.
|
<static> |
JXG.Math.sign(x)
The sign() function returns the sign of a number, indicating whether the number is positive, negative or zero.
|
<static> |
JXG.Math.sinh(x)
Sine hyperbolicus of x.
|
<static> |
JXG.Math.squampow(base, exponent)
A square & multiply algorithm to compute base to the power of exponent.
|
<static> |
JXG.Math.toGL(m)
Converts a two dimensional array to a one dimensional Float32Array that can be processed by WebGL.
|
<static> |
JXG.Math.transpose(M)
Transposes a matrix given as a two dimensional array.
|
<static> |
JXG.Math.vector(n, init)
Initializes a vector of size n wih coefficients set to the init value (default 0)
|
<static> |
JXG.Math.Vieta(x)
Theorem of Vieta: Given a set of simple zeroes x_0, .
|
<static> |
JXG.Math.wrap(x, a, b)
Translate
x into the interval [a, b) by adding
a multiple of b - a . |
<static> |
JXG.Math.wrapAndClamp(x, a, b, period)
A way of clamping a periodic variable.
|
<static> |
JXG.Math.xor(a, b)
Logical operator: either a or b?
|
Namespace Detail
JXG.Math
Math namespace. Contains mathematics related methods which are
specific to JSXGraph or which extend the JavaScript Math class.
Field Detail
<static>
{Number}
JXG.Math.acosh
Hyperbolic arc-cosine of a number.
<static>
{Number}
JXG.Math.asinh
Hyperbolic arcsine of a number
<static>
{Number}
JXG.Math.eps
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.
<static>
{Object}
JXG.Math.Interval
Method Detail
<static>
{Number}
JXG.Math.acot(x)
Computes the inverse cotangent of x.
- Parameters:
- {Number} x
- The number the inverse cotangent will be calculated of.
- Returns:
- {Number} Inverse cotangent of the given value.
<static>
{Boolean}
JXG.Math.and(a, b)
Logical operator: a && b?
- Parameters:
- {Boolean} a
- {Boolean} b
- Returns:
- {Boolean}
<static>
JXG.Math.axpy(a, x, y)
Compute a * x + y for a scalar a and vectors x and y.
- Parameters:
- {Number} a
- {Array} x
- {Array} y
- Returns:
<static>
{Number}
JXG.Math.binomial(n, k)
Computes the binomial coefficient n over k.
- Parameters:
- {Number} n
- Fraction will be ignored
- {Number} k
- Fraction will be ignored
- Returns:
- {Number} The binomial coefficient n over k
<static>
{Number}
JXG.Math.cbrt(x)
Computes cube root of real number
Polyfill for Math.cbrt().
- Parameters:
- {Number} x
- Radicand
- Returns:
- {Number} Cube root of x.
<static>
JXG.Math.clamp(x, a, b)
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
.
- Parameters:
- x
- a
- b
<static>
{Number}
JXG.Math.cosh(x)
Calculates the cosine hyperbolicus of x.
- Parameters:
- {Number} x
- The number the cosine hyperbolicus will be calculated of.
- Returns:
- {Number} Cosine hyperbolicus of the given value.
<static>
{Number}
JXG.Math.cot(x)
Computes the cotangent of x.
- Parameters:
- {Number} x
- The number the cotangent will be calculated of.
- Returns:
- {Number} Cotangent of the given value.
<static>
{Array}
JXG.Math.crossProduct(c1, c2)
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:
- {Array} c1
- Homogeneous coordinates of line or point 1
- {Array} c2
- Homogeneous coordinates of line or point 2
- Returns:
- {Array} vector of length 3: homogeneous coordinates of the resulting point / line.
<static>
{Array}
JXG.Math.decToFraction(x, order)
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.
- Parameters:
- {Number} x
- Number which is to be converted
- {Number} order Optional, Default: 0.001
- Small number determining the approximation precision.
- Returns:
- {Array} [sign, leading, nominator, denominator] where sign is 1 or -1.
- See:
- JXG#toFraction
- Examples:
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 ]
<static>
{Boolean}
JXG.Math.eq(a, b)
Logical test: a === b?
- Parameters:
- {Number} a
- {Number} b
- Returns:
- {Boolean}
<static>
{Number}
JXG.Math.erf(x)
Error function, see https://en.wikipedia.org/wiki/Error_function.
- Parameters:
- {Number} x
- Returns:
- {Number}
- See:
- JXG.Math.PropFunc.erf
<static>
{Number}
JXG.Math.erfc(x)
Complementary error function, i.e. 1 - erf(x).
- Parameters:
- {Number} x
- Returns:
- {Number}
- See:
- JXG.Math.erf
- JXG.Math.PropFunc.erfc
<static>
{Number}
JXG.Math.erfi(x)
Inverse of error function
- Parameters:
- {Number} x
- Returns:
- {Number}
- See:
- JXG.Math.erf
- JXG.Math.PropFunc.erfi
<static>
{Number}
JXG.Math.factorial(n)
Compute the factorial of a positive integer. If a non-integer value
is given, the fraction will be ignored.
- Parameters:
- {Number} n
- Returns:
- {Number} n! = n*(n-1)*...*2*1
<static>
{Array}
JXG.Math.frustum(l, r, t, b, n, f)
Generates a 4x4 matrix for 3D to 2D projections.
- Parameters:
- {Number} l
- Left
- {Number} r
- Right
- {Number} t
- Top
- {Number} b
- Bottom
- {Number} n
- Near
- {Number} f
- Far
- Returns:
- {Array} 4x4 Matrix
<static>
JXG.Math.gamma(z)
Gamma function for real parameters by Lanczos approximation.
Implementation straight from https://en.wikipedia.org/wiki/Lanczos_approximation.
- Parameters:
- {Number} z
- Returns:
- Number
<static>
{Number}
JXG.Math.gcd(a, b)
Greatest common divisor (gcd) of two numbers.
- Parameters:
- {Number} a
- First number
- {Number} b
- Second number
- Returns:
- {Number} gcd(a, b) if a and b are numbers, NaN else.
- See:
- rosettacode.org
<static>
{Boolean}
JXG.Math.geq(a, b)
Logical test: a >= b?
- Parameters:
- {Number} a
- {Number} b
- Returns:
- {Boolean}
<static>
{Boolean}
JXG.Math.gt(a, b)
Logical test: a > b?
- Parameters:
- {Number} a
- {Number} b
- Returns:
- {Boolean}
<static>
JXG.Math.hstep(x)
Heaviside unit step function. Returns 0 for x <, 1 for x > 0, and 0.5 for x == 0.
- Parameters:
- {Number} x
- Returns:
- Number
<static>
JXG.Math.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:
- {Number} a
- Variable number of arguments.
- Returns:
- Number
<static>
{Array}
JXG.Math.identity(n, m)
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:
- {Number} n
- Number of rows
- {Number} m Optional, Default: n
- Number of columns
- Returns:
- {Array} 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.
<static>
{Number}
JXG.Math.innerProduct(a, b, n)
Inner product of two vectors a and b. n is the length of the vectors.
- Parameters:
- {Array} a
- Vector
- {Array} b
- Vector
- {Number} n Optional
- Length of the Vectors. If not given the length of the first vector is taken.
- Returns:
- {Number} The inner product of a and b.
<static>
{Array}
JXG.Math.inverse(Ain)
Compute the inverse of an nxn matrix with Gauss elimination.
- Parameters:
- {Array} Ain
- Returns:
- {Array} Inverse matrix of Ain
<static>
{Number}
JXG.Math.lcm(a, b)
Least common multiple (lcm) of two numbers.
- Parameters:
- {Number} a
- First number
- {Number} b
- Second number
- Returns:
- {Number} lcm(a, b) if a and b are numbers, NaN else.
<static>
{Boolean}
JXG.Math.leq(a, b)
Logical test: a <= b?
- Parameters:
- {Number} a
- {Number} b
- Returns:
- {Boolean}
<static>
{Number}
JXG.Math.log(x, b)
Logarithm to arbitrary base b. If b is not given, natural log is taken, i.e. b = e.
- Parameters:
- {Number} x
- {Number} b
- base
- Returns:
- {Number} log(x, b) Logarithm of x to base b, that is log(x)/log(b).
<static>
{Number}
JXG.Math.log10(x)
Logarithm to base 10.
- Parameters:
- {Number} x
- Returns:
- {Number} log10(x) Logarithm of x to base 10.
<static>
{Number}
JXG.Math.log2(x)
Logarithm to base 2.
- Parameters:
- {Number} x
- Returns:
- {Number} log2(x) Logarithm of x to base 2.
<static>
{Boolean}
JXG.Math.lt(a, b)
Logical test: a < b?
- Parameters:
- {Number} a
- {Number} b
- Returns:
- {Boolean}
<static>
{Array}
JXG.Math.matMatMult(mat1, mat2)
Computes the product of the two matrices mat1*mat2.
- Parameters:
- {Array} mat1
- Two dimensional array of numbers
- {Array} mat2
- Two dimensional array of numbers
- Returns:
- {Array} Two dimensional Array of numbers containing result
<static>
{Array}
JXG.Math.matrix(n, m, init)
Initializes a matrix as an array of rows with the given value.
- Parameters:
- {Number} n
- Number of rows
- {Number} m Optional, Default: n
- Number of columns
- {Number} init Optional, Default: 0
- Initial value for each coefficient
- Returns:
- {Array} A n times m-matrix represented by a two-dimensional array. The inner arrays hold the columns, the outer array holds the rows.
<static>
{Array}
JXG.Math.matVecMult(mat, vec)
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.
- Parameters:
- {Array} mat
- Two dimensional array of numbers. The inner arrays describe the columns, the outer ones the matrix' rows.
- {Array} vec
- Array of numbers
- Returns:
- {Array} Array of numbers containing the result
- Examples:
var A = [[2, 1], [1, 3]], b = [4, 5], c; c = JXG.Math.matVecMult(A, b) // c === [13, 19];
<static>
{Number}
JXG.Math.mod(a, m)
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:
- {Number} a
- {Number} m
- Returns:
- {Number} Mathematical modulo a mod m
<static>
{Number}
JXG.Math.ndtr(x)
Normal distribution function
- Parameters:
- {Number} x
- Returns:
- {Number}
- See:
- JXG.Math.PropFunc.ndtr
<static>
{Number}
JXG.Math.ndtri(x)
Inverse of normal distribution function
- Parameters:
- {Number} x
- Returns:
- {Number}
- See:
- JXG.Math.ndtr
- JXG.Math.PropFunc.ndtri
<static>
{Boolean}
JXG.Math.neq(a, b)
Logical test: a !== b?
- Parameters:
- {Number} a
- {Number} b
- Returns:
- {Boolean}
<static>
{Number}
JXG.Math.norm(a, n)
Euclidean norm of a vector.
- Parameters:
- {Array} a
- Array containing a vector.
- {Number} n
- (Optional) length of the array.
- Returns:
- {Number} Euclidean norm of the vector.
<private> <static>
{Array}
JXG.Math.normalize(stdform)
Normalize the standard form [c, b0, b1, a, k, r, q0, q1].
- Parameters:
- {Array} stdform
- The standard form to be normalized.
- Returns:
- {Array} The normalized standard form.
<static>
{Boolean}
JXG.Math.not(a)
Logical operator: !a?
- Parameters:
- {Boolean} a
- Returns:
- {Boolean}
<static>
{Number}
JXG.Math.nthroot(x, n)
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
- Parameters:
- {Number} x
- radicand. Must be non-negative, if n even.
- {Number} n
- index of the root. must be strictly positive integer.
- Returns:
- {Number} returns real root or NaN
- Examples:
nthroot(16, 4): 2 nthroot(-27, 3): -3 nthroot(-4, 2): NaN
<static>
{Boolean}
JXG.Math.or(a, b)
Logical operator: a || b?
- Parameters:
- {Boolean} a
- {Boolean} b
- Returns:
- {Boolean}
<static>
{Number}
JXG.Math.pow(base, exponent)
Compute base to the power of exponent.
- Parameters:
- {Number} base
- {Number} exponent
- Returns:
- {Number} base to the power of exponent.
<static>
{Array}
JXG.Math.projection(fov, ratio, n, f)
Generates a 4x4 matrix for 3D to 2D projections.
- Parameters:
- {Number} fov
- Field of view in vertical direction, given in rad.
- {Number} ratio
- Aspect ratio of the projection plane.
- {Number} n
- Near
- {Number} f
- Far
- Returns:
- {Array} 4x4 Projection Matrix
<static>
{Number}
JXG.Math.ratpow(base, m, n)
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:
- {Number} base
- {Number} m
- numerator of exponent
- {Number} n
- denominator of exponent
- Returns:
- {Number} base to the power of exponent.
<static>
{Number}
JXG.Math.relDif(a, b)
Determine the relative difference between two numbers.
- Parameters:
- {Number} a
- First number
- {Number} b
- Second number
- Returns:
- {Number} Relative difference between a and b: |a-b| / max(|a|, |b|)
<static>
{Number}
JXG.Math.roundToStep(value, step, min, max)
Special use of Math.round function to round not only to integers but also to chosen decimal values.
- Parameters:
- {Number} value
- Value to be rounded.
- {Number} step
- Distance between the values to be rounded to. (default: 1.0)
- {Number} min Optional
- If set, it will be returned the maximum of value and min.
- {Number} max Optional
- If set, it will be returned the minimum of value and max.
- Returns:
- {Number} Fitted value.
<static>
{Number}
JXG.Math.sign(x)
The sign() function returns the sign of a number, indicating whether the number is positive, negative or zero.
- Parameters:
- {Number} x
- A Number
- Returns:
- {Number} 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.
<static>
{Number}
JXG.Math.sinh(x)
Sine hyperbolicus of x.
- Parameters:
- {Number} x
- The number the sine hyperbolicus will be calculated of.
- Returns:
- {Number} Sine hyperbolicus of the given value.
<static>
{Number}
JXG.Math.squampow(base, exponent)
A square & multiply algorithm to compute base to the power of exponent.
Implementated by Wolfgang Riedl.
- Parameters:
- {Number} base
- {Number} exponent
- Returns:
- {Number} Base to the power of exponent
<static>
{Float32Array}
JXG.Math.toGL(m)
Converts a two dimensional array to a one dimensional Float32Array that can be processed by WebGL.
- Parameters:
- {Array} m
- A matrix in a two dimensional array.
- Returns:
- {Float32Array} 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.
<static>
{Array}
JXG.Math.transpose(M)
Transposes a matrix given as a two dimensional array.
- Parameters:
- {Array} M
- The matrix to be transposed
- Returns:
- {Array} The transpose of M
<static>
{Array}
JXG.Math.vector(n, init)
Initializes a vector of size n wih coefficients set to the init value (default 0)
- Parameters:
- {Number} n
- Length of the vector
- {Number} init Optional, Default: 0
- Initial value for each coefficient
- Returns:
- {Array} An array of length n
<static>
{Array}
JXG.Math.Vieta(x)
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:
- {Array} x
- Simple zeroes of the polynomial.
- Returns:
- {Array} Coefficients of the polynomial.
<static>
JXG.Math.wrap(x, a, b)
Translate
x
into the interval [a, b)
by adding
a multiple of b - a
.
- Parameters:
- {Number} x
- {Number} a
- {Number} b
<static>
JXG.Math.wrapAndClamp(x, a, b, period)
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.
- Parameters:
- x
- a
- b
- period
<static>
{Boolean}
JXG.Math.xor(a, b)
Logical operator: either a or b?
- Parameters:
- {Boolean} a
- {Boolean} b
- Returns:
- {Boolean}