API Docs for: 0.99.4
Show:

# JXG.Math Class

Mathematics subroutines

Here, the namespace JXG.Math is defined, which is the base namespace for namespaces like Math.Numerics, Math.Algebra, Math.Statistics etc.

## Methods

### `binomial`

(
• `n`
• `k`
)

Computes the binomial coefficient n over k.

#### Parameters:

• `n` Number

Fraction will be ignored

• `k` Number

Fraction will be ignored

#### Returns:

Number:

The binomial coefficient n choose k

### `cosh`

(
• `x`
)

Calculates the cosine hyperbolicus of x.

#### Parameters:

• `x` Number

The number the cosine hyperbolicus will be calculated of.

#### Returns:

Number:

Cosine hyperbolicus of the given value.

### `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:

• `c1` Array

Homogeneous coordinates of line or point 1

• `c2` Array

Homogeneous coordinates of line or point 2

#### Returns:

Array:

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

### `factorial`

(
• `n`
)

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

#### Returns:

Number:

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

### `frustum`

(
• `l`
• `r`
• `t`
• `b`
• `n`
• `f`
)

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

Array:

4x4 Matrix

### `identity`

(
• `n`
• `[m=n]`
)

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:

• `n` Number

Number of rows

• `[m=n]` Number optional

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.

### `innerProduct`

(
• `a`
• `b`
• `[n]`
)

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

#### Parameters:

• `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:

Number:

The inner product of a and b.

### `inverse`

(
• `Ain`
)

Compute the inverse of an nxn matrix with Gauss elimination.

#### Parameters:

• `Ain` Array

matrix

#### Returns:

Array:

Inverse matrix of Ain

### `log`

(
• `x`
• `b`
)

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

#### Returns:

Number:

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

### `log10`

(
• `x`
)

Logarithm to base 10.

#### Returns:

Number:

log10(x) Logarithm of x to base 10.

### `log2`

(
• `x`
)

Logarithm to base 2

#### Returns:

Number:

log2(x) Logarithm of x to base 2.

### `matMatMult`

(
• `mat1`
• `mat2`
)

Computes the product of the two matrices mat1*mat2.

#### Parameters:

• `mat1` Array

Two dimensional array of numbers

• `mat2` Array

Two dimensional array of numbers

#### Returns:

Array:

Two dimensional Array of numbers containing mat1 * mat2

### `matrix`

(
• `n`
• `[m=n]`
• `[init=0]`
)

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

#### Parameters:

• `n` Number

Number of rows

• `[m=n]` Number optional

Number of columns

• `[init=0]` Number optional

Initial value for each coefficient

#### Returns:

Array:

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

### `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:

• `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:

Array of numbers containing mat * vec

#### Example:

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

### `mod`

(
• `a`
• `m`
)

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

#### Returns:

Number:

Mathematical modulo a mod m

### `normalize`

(
• `stdform`
)
private

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

#### Parameters:

• `stdform` Array

The standard form to be normalized.

#### Returns:

Array:

The normalized standard form.

### `pow`

(
• `base`
• `exponent`
)

Compute base to the power of exponent. This method expands the JavaScript method Math.pow. It also works if the exponent is not an integer.

#### Returns:

Number:

base to the power of exponent.

### `projection`

(
• `fov`
• `ratio`
• `n`
• `f`
)

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

#### Parameters:

• `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:

Array:

4x4 Projection Matrix

### `sinh`

(
• `x`
)

Sine hyperbolicus of x.

#### Parameters:

• `x` Number

The number the sine hyperbolicus will be calculated of.

#### Returns:

Number:

Sine hyperbolicus of the given value.

### `squampow`

(
• `base`
• `exponent`
)

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

#### Returns:

Number:

Base to the power of exponent

### `toGL`

(
• `m`
)

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

#### Parameters:

• `m` Array

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.

### `transpose`

(
• `M`
)

Transposes a matrix given as a two dimensional array.

#### Parameters:

• `M` Array

The matrix to be transposed

#### Returns:

Array:

The transpose of M

### `vector`

(
• `n`
• `[init=0]`
)

Initializes a vector as an array with the coefficients set to the given value resp. zero.

#### Parameters:

• `n` Number

Length of the vector

• `[init=0]` Number optional

Initial value for each coefficient

#### Returns:

Array:

A vector of length n represented by a one-dimensional array.

## Properties

### `eps`

Number

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.