Numerics

Namespace

The JXG.Math.Numerics namespace holds numerical algorithms, constants, and variables.

Members

Own

(static) maxIterationsMinimize : Number

Description

Maximum number of iterations in JXG.Math.Numerics.fminbr

Type
Number
Default Value
500
Source
math/numerics.js, line 3422

(static) maxIterationsRoot : Number

Description

Maximum number of iterations in JXG.Math.Numerics.fzero and JXG.Math.Numerics.chandrupatla

Type
Number
Default Value
80
Source
math/numerics.js, line 3414

Inherited

none

Methods

Own

(static) CardinalSpline(points, tau, type) → {Array}

Computes the cubic cardinal spline curve through a given set of points. The curve is uniformly parametrized. Two artificial control points at the beginning and the end are added.

The implementation (especially the centripetal parametrization) is from https://stackoverflow.com/questions/9489736/catmull-rom-curve-with-no-cusps-and-no-self-intersections.

Parameters

Name Type Description
points Array

Array consisting of Points

tau Number | function

The tension parameter, either a constant number or a function returning a number. This number is between 0 and 1. tau=1/2 give Catmull-Rom splines.

type String

(Optional) parameter which allows to choose between "uniform" (default) and "centripetal" parameterization. Thus the two possible values are "uniform" or "centripetal".

Returns

An Array consisting of four components: Two functions each of one parameter t which return the x resp. y coordinates of the Catmull-Rom-spline curve in t, a zero value, and a function simply returning the length of the points array minus three.

Type
Array

Details

Source
math/numerics.js, line 2474

(static) CatmullRomSpline(points, type) → {Array}

Computes the cubic Catmull-Rom spline curve through a given set of points. The curve is uniformly parametrized. The curve is the cardinal spline curve for tau=0.5. Two artificial control points at the beginning and the end are added.

Parameters

Name Type Description
points Array

Array consisting of Points

type String

(Optional) parameter which allows to choose between "uniform" (default) and "centripetal" parameterization. Thus the two possible values are "uniform" or "centripetal".

Returns

An Array consisting of four components: Two functions each of one parameter t which return the x resp. y coordinates of the Catmull-Rom-spline curve in t, a zero value, and a function simply returning the length of the points array minus three.

Type
Array

Details

Source
math/numerics.js, line 2657

(static) D(f, objopt) → {function}

Numerical (symmetric) approximation of derivative. suspendUpdate is piped through, see JXG.Curve#updateCurve and JXG.Curve#hasPoint.

Parameters

Name Type Attributes Description
f function

Function in one variable to be differentiated.

obj object <optional>

Optional object that is treated as "this" in the function body. This is useful, if the function is a method of an object and contains a reference to its parent object via "this".

Returns

Derivative function of a given function f.

Type
function

Details

Source
math/numerics.js, line 3001

(static) Gauss(A, b) → {Array}

Solves a system of linear equations given by A and b using the Gauss-Jordan-elimination. The algorithm runs in-place. I.e. the entries of A and b are changed.

Parameters

Name Type Description
A Array

Square matrix represented by an array of rows, containing the coefficients of the lineare equation system.

b Array

A vector containing the linear equation system's right hand side.

Throws

If a non-square-matrix is given or if b has not the right length or A's rank is not full.

Type
Error

Returns

A vector that solves the linear equation system.

Type
Array

Details

Source
math/numerics.js, line 93

(static) GaussKronrod15(interval, f, resultObj) → {Number}

15-point Gauss-Kronrod quadrature algorithm, see the library QUADPACK

Parameters

Name Type Description
interval Array

The integration interval, e.g. [0, 3].

f function

A function which takes one argument of type number and returns a number.

resultObj Object

Object returning resultObj.abserr, resultObj.resabs, resultObj.resasc. See the library QUADPACK for an explanation.

Returns

Integral value of f over interval

Type
Number

Details

Source
math/numerics.js, line 965

(static) GaussKronrod21(interval, f, resultObj) → {Number}

21 point Gauss-Kronrod quadrature algorithm, see the library QUADPACK

Parameters

Name Type Description
interval Array

The integration interval, e.g. [0, 3].

f function

A function which takes one argument of type number and returns a number.

resultObj Object

Object returning resultObj.abserr, resultObj.resabs, resultObj.resasc. See the library QUADPACK for an explanation.

Returns

Integral value of f over interval

Type
Number

Details

Source
math/numerics.js, line 1010

(static) GaussKronrod31(interval, f, resultObj) → {Number}

31 point Gauss-Kronrod quadrature algorithm, see the library QUADPACK

Parameters

Name Type Description
interval Array

The integration interval, e.g. [0, 3].

f function

A function which takes one argument of type number and returns a number.

resultObj Object

Object returning resultObj.abserr, resultObj.resabs, resultObj.resasc. See the library QUADPACK for an explanation.

Returns

Integral value of f over interval

Type
Number

Details

Source
math/numerics.js, line 1058

(static) GaussLegendre(interval, f, configopt) → {Number}

Calculates the integral of function f over interval using Gauss-Legendre quadrature.

Example

function f(x) {
  return x*x;
}

// calculates integral of `f` from 0 to 2.
var area1 = JXG.Math.Numerics.GaussLegendre([0, 2], f);

// the same with an anonymous function
var area2 = JXG.Math.Numerics.GaussLegendre([0, 2], function (x) { return x*x; });

// use 16 point Gauss-Legendre rule.
var area3 = JXG.Math.Numerics.GaussLegendre([0, 2], f,
                                  {n: 16});

Parameters

Name Type Attributes Description
interval Array

The integration interval, e.g. [0, 3].

f function

A function which takes one argument of type number and returns a number.

config Object <optional>

The algorithm setup. Accepted property is the order n of type number. n is allowed to take values between 2 and 18, default value is 12.

Properties
Name Type Attributes Default Description
n Number <optional>
16

Returns

Integral value of f over interval

Type
Number

Details

Source
math/numerics.js, line 606

(static) I(interval, f) → {Number}

Integral of function f over interval.

Parameters

Name Type Description
interval Array

The integration interval, e.g. [0, 3].

f function

A function which takes one argument of type number and returns a number.

Returns

The value of the integral of f over interval

Type
Number

Details

See
Source
math/numerics.js, line 1498

(static) Jacobi(Ain) → {Array}

Compute the Eigenvalues and Eigenvectors of a symmetric 3x3 matrix with the Jacobi method Adaption of a FORTRAN program by Ed Wilson, Dec. 25, 1990

Parameters

Name Type Description
Ain Array

A symmetric 3x3 matrix.

Returns

[A,V] the matrices A and V. The diagonal of A contains the Eigenvalues, V contains the Eigenvectors.

Type
Array

Details

Source
math/numerics.js, line 294

(static) Neville(p) → {Array}

Returns the Lagrange polynomials for curves with equidistant nodes, see Jean-Paul Berrut, Lloyd N. Trefethen: Barycentric Lagrange Interpolation, SIAM Review, Vol 46, No 3, (2004) 501-517. The graph of the parametric curve [x(t),y(t)] runs through the given points.

Example

var p = [];

p[0] = board.create('point', [0, -2], {size:2, name: 'C(a)'});
p[1] = board.create('point', [-1.5, 5], {size:2, name: ''});
p[2] = board.create('point', [1, 4], {size:2, name: ''});
p[3] = board.create('point', [3, 3], {size:2, name: 'C(b)'});

// Curve
var fg = JXG.Math.Numerics.Neville(p);
var graph = board.create('curve', fg, {strokeWidth:3, strokeOpacity:0.5});

Parameters

Name Type Description
p Array

Array of Points

Returns

An array consisting of two functions x(t), y(t) which define a parametric curve f(t) = (x(t), y(t)), a number x1 (which equals 0) and a function x2 defining the curve's domain. That means the curve is defined between x1 and x2(). x2 returns the (length of array p minus one).

Type
Array

Details

Source
math/numerics.js, line 1856

(static) Newton(f, x, context) → {Number}

Newton's method to find roots of a funtion in one variable.

Parameters

Name Type Description
f function

We search for a solution of f(x)=0.

x Number

initial guess for the root, i.e. start value.

context Object

optional object that is treated as "this" in the function body. This is useful if the function is a method of an object and contains a reference to its parent object via "this".

Returns

A root of the function f.

Type
Number

Details

Source
math/numerics.js, line 1518

(static) NewtonCotes(interval, f, configopt) → {Number}

Calculates the integral of function f over interval using Newton-Cotes-algorithm.

Example

function f(x) {
  return x*x;
}

// calculates integral of `f` from 0 to 2.
var area1 = JXG.Math.Numerics.NewtonCotes([0, 2], f);

// the same with an anonymous function
var area2 = JXG.Math.Numerics.NewtonCotes([0, 2], function (x) { return x*x; });

// use trapez rule with 16 nodes
var area3 = JXG.Math.Numerics.NewtonCotes([0, 2], f,
                                  {number_of_nodes: 16, integration_type: 'trapez'});

Parameters

Name Type Attributes Description
interval Array

The integration interval, e.g. [0, 3].

f function

A function which takes one argument of type number and returns a number.

config Object <optional>

The algorithm setup. Accepted properties are number_of_nodes of type number and integration_type with value being either 'trapez', 'simpson', or 'milne'.

Properties
Name Type Attributes Default Description
number_of_nodes Number <optional>
28
integration_type String <optional>
'milne'

Possible values are 'milne', 'simpson', 'trapez'

Throws

If config.number_of_nodes doesn't match config.integration_type an exception is thrown. If you want to use simpson rule respectively milne rule config.number_of_nodes must be dividable by 2 respectively 4.

Type
Error

Returns

Integral value of f over interval

Type
Number

Details

Source
math/numerics.js, line 418

(static) Qag(interval, f, configopt) → {Number}

Quadrature algorithm qag from QUADPACK. Internal method used in JXG.Math.Numerics.GaussKronrod15, JXG.Math.Numerics.GaussKronrod21, JXG.Math.Numerics.GaussKronrod31.

Example

function f(x) {
  return x*x;
}

// calculates integral of `f` from 0 to 2.
var area1 = JXG.Math.Numerics.Qag([0, 2], f);

// the same with an anonymous function
var area2 = JXG.Math.Numerics.Qag([0, 2], function (x) { return x*x; });

// use JXG.Math.Numerics.GaussKronrod31 rule as sub-algorithm.
var area3 = JXG.Math.Numerics.Quag([0, 2], f,
                                  {q: JXG.Math.Numerics.GaussKronrod31});

Parameters

Name Type Attributes Description
interval Array

The integration interval, e.g. [0, 3].

f function

A function which takes one argument of type number and returns a number.

config Object <optional>

The algorithm setup. Accepted propert are max. recursion limit of type number, and epsrel and epsabs, the relative and absolute required precision of type number. Further, q the internal quadrature sub-algorithm of type function.

Properties
Name Type Attributes Default Description
limit Number <optional>
15
epsrel Number <optional>
0.0000001
epsabs Number <optional>
0.0000001
q Number <optional>
JXG.Math.Numerics.GaussKronrod15

Returns

Integral value of f over interval

Type
Number

Details

Source
math/numerics.js, line 1303

(static) RamerDouglasPeucker(pts, eps, usropt) → {Array}

Polyline simplification with the Ramer-Douglas-Peucker algorithm. It discards points which are not necessary from the polygonal line defined by the point array pts. The computation is done in screen coordinates.

Average runtime is O(nlog(n)), worst case runtime is O(n^2), where n is the number of points.

Parameters

Name Type Attributes Default Description
pts Array

Array of JXG.Coords

eps Number

If the absolute value of a given number x is smaller than eps it is considered to be equal 0.

usr Boolean <optional>
false

Minimize number of points using user coords

Returns

An array containing points which represent an apparently identical curve as the points of pts do, but contains fewer points.

Type
Array

Details

Source
math/numerics.js, line 4810

(static) RamerDouglasPeuker()

Old name for the implementation of the Ramer-Douglas-Peucker algorithm.

Details

Deprecated
Use JXG.Math.Numerics.RamerDouglasPeucker
Source
math/numerics.js, line 4856

(static) Romberg(interval, f, configopt) → {Number}

Calculates the integral of function f over interval using Romberg iteration.

Example

function f(x) {
  return x*x;
}

// calculates integral of `f` from 0 to 2.
var area1 = JXG.Math.Numerics.Romberg([0, 2], f);

// the same with an anonymous function
var area2 = JXG.Math.Numerics.Romberg([0, 2], function (x) { return x*x; });

// use trapez rule with maximum of 16 iterations or stop if the precision 0.0001 has been reached.
var area3 = JXG.Math.Numerics.Romberg([0, 2], f,
                                  {max_iterations: 16, eps: 0.0001});

Parameters

Name Type Attributes Description
interval Array

The integration interval, e.g. [0, 3].

f function

A function which takes one argument of type number and returns a number.

config Object <optional>

The algorithm setup. Accepted properties are max_iterations of type number and precision eps.

Properties
Name Type Attributes Default Description
max_iterations Number <optional>
20
eps Number <optional>
0.0000001

Returns

Integral value of f over interval

Type
Number

Details

Source
math/numerics.js, line 532

(static) Visvalingam(pts, numPoints) → {Array}

Implements the Visvalingam-Whyatt algorithm. See M. Visvalingam, J. D. Whyatt: "Line generalisation by repeated elimination of the smallest area", C.I.S.R.G Discussion paper 10, July 1992

The algorithm discards points which are not necessary from the polygonal line defined by the point array pts (consisting of type JXG.Coords).

Example

var i, p = [];
    for (i = 0; i < 5; ++i) {
        p.push(board.create('point', [Math.random() * 12 - 6, Math.random() * 12 - 6]));
    }

    // Plot a cardinal spline curve
    var splineArr = JXG.Math.Numerics.CardinalSpline(p, 0.5);
    var cu1 = board.create('curve', splineArr, {strokeColor: 'green'});

    var c = board.create('curve', [[0],[0]], {strokeWidth: 2, strokeColor: 'black'});
    c.updateDataArray = function() {
        var i, len, points;

        // Reduce number of intermediate points with Visvakingam-Whyatt to 6
        points = JXG.Math.Numerics.Visvalingam(cu1.points, 6);
        // Plot the remaining points
        len = points.length;
        this.dataX = [];
        this.dataY = [];
        for (i = 0; i < len; i++) {
            this.dataX.push(points[i].usrCoords[1]);
            this.dataY.push(points[i].usrCoords[2]);
        }
    };
    board.update();

Parameters

Name Type Description
pts Array

Array of JXG.Coords

numPoints Number

Number of remaining intermediate points. The first and the last point of the original points will be taken in any case.

Returns

An array containing points which approximates the curve defined by pts.

Type
Array

Details

Source
math/numerics.js, line 4938

(private, static) _riemannValue(x, f, type, delta) → {Number}

Evaluate the function term for JXG.Math.Numerics.riemann.

Parameters

Name Type Description
x Number

function argument

f function

JavaScript function returning a number

type String

Name of the Riemann sum type, e.g. 'lower'.

delta Number

Width of the bars in user coordinates

Returns

Upper (delta > 0) or lower (delta < 0) value of the bar containing x of the Riemann sum.

Type
Number

Details

See
Source
math/numerics.js, line 3045

(private, static) _workspace(interval, n) → {Object}

Generate workspace object for JXG.Math.Numerics.Qag.

Parameters

Name Type Description
interval Array

The integration interval, e.g. [0, 3].

n Number

Max. limit

Returns

Workspace object

Type
Object

Details

Source
math/numerics.js, line 1110

(static) backwardSolve(R, b, canModifyopt) → {Array}

Solves a system of linear equations given by the right triangular matrix R and vector b.

Parameters

Name Type Attributes Default Description
R Array

Right triangular matrix represented by an array of rows. All entries a_(i,j) with i < j are ignored.

b Array

Right hand side of the linear equation system.

canModify Boolean <optional>
false

If true, the right hand side vector is allowed to be changed by this method.

Returns

An array representing a vector that solves the system of linear equations.

Type
Array

Details

Source
math/numerics.js, line 164

(static) bezier(points) → {Array}

Computes the cubic Bezier curve through a given set of points.

Parameters

Name Type Description
points Array

Array consisting of 3*k+1 Points. The points at position k with k mod 3 = 0 are the data points, points at position k with k mod 3 = 1 or 2 are the control points.

Returns

An array consisting of two functions of one parameter t which return the x resp. y coordinates of the Bezier curve in t, one zero value, and a third function accepting no parameters and returning one third of the length of the points.

Type
Array

Details

Source
math/numerics.js, line 2821

(static) bspline(points, order) → {Array}

Computes the B-spline curve of order k (order = degree+1) through a given set of points.

Parameters

Name Type Description
points Array

Array consisting of Points.

order Number

Order of the B-spline curve.

Returns

An Array consisting of four components: Two functions each of one parameter t which return the x resp. y coordinates of the B-spline curve in t, a zero value, and a function simply returning the length of the points array minus one.

Type
Array

Details

Source
math/numerics.js, line 2876

(static) chandrupatla(f, x0, contextopt) → {Number}

Find zero of an univariate function f.

Parameters

Name Type Attributes Description
f function

Function, whose root is to be found

x0 Array | Number

Start value or start interval enclosing the root. If x0 is an interval [a,b], it is required that f(a)f(b) <= 0, otherwise the minimum of f in [a, b] will be returned. If x0 is a number, the algorithms tries to enclose the root by an interval [a, b] containing x0 and the root and f(a)f(b) <= 0. If this fails, the algorithm falls back to Newton's method.

context Object <optional>

Parent object in case f is method of it

Returns

the approximation of the root Algorithm: Chandrupatla's method, see Tirupathi R. Chandrupatla, "A new hybrid quadratic/bisection algorithm for finding the zero of a nonlinear function without using derivatives", Advances in Engineering Software, Volume 28, Issue 3, April 1997, Pages 145-149.

If x0 is an array containing lower and upper bound for the zero algorithm 748 is applied. Otherwise, if x0 is a number, the algorithm tries to bracket a zero of f starting from x0. If this fails, we fall back to Newton's method.

Type
Number

Details

See
Source
math/numerics.js, line 3700

(static) det(mat) → {Number}

Computes the determinant of a square nxn matrix with the Gauss-Bareiss algorithm.

Parameters

Name Type Description
mat Array

Matrix.

Returns

The determinant pf the matrix mat. The empty matrix returns 0.

Type
Number

Details

Source
math/numerics.js, line 277

(static) findBracket(f, x0, contextopt) → {Array}

Given a number x_0, this function tries to find a second number x_1 such that the function f has opposite signs at x_0 and x_1. The return values have to be tested if the method succeeded.

Parameters

Name Type Attributes Description
f function

Function, whose root is to be found

x0 Number

Start value

context Object <optional>

Parent object in case f is method of it

Returns

[x_0, f(x_0), x_1, f(x_1)] in case that x_0 <= x_1 or [x_1, f(x_1), x_0, f(x_0)] in case that x_1 < x_0.

Type
Array

Details

See
Source
math/numerics.js, line 3440

(static) fminbr(f, x0, contextopt) → {Number}

Find minimum of an univariate function f.

Algorithm: G.Forsythe, M.Malcolm, C.Moler, Computer methods for mathematical computations. M., Mir, 1980, p.180 of the Russian edition

Parameters

Name Type Attributes Description
f function

Function, whose minimum is to be found

x0 Array

Start interval enclosing the minimum

context Object <optional>

Parent object in case f is method of it

Returns

the approximation of the minimum value position

Type
Number

Details

Source
math/numerics.js, line 3922

(static) fzero(f, x0, contextopt) → {Number}

Find zero of an univariate function f.

Parameters

Name Type Attributes Description
f function

Function, whose root is to be found

x0 Array | Number

Start value or start interval enclosing the root. If x0 is an interval [a,b], it is required that f(a)f(b) <= 0, otherwise the minimum of f in [a, b] will be returned. If x0 is a number, the algorithms tries to enclose the root by an interval [a, b] containing x0 and the root and f(a)f(b) <= 0. If this fails, the algorithm falls back to Newton's method.

context Object <optional>

Parent object in case f is method of it

Returns

the approximation of the root Algorithm: Brent's root finder from G.Forsythe, M.Malcolm, C.Moler, Computer methods for mathematical computations. M., Mir, 1980, p.180 of the Russian edition https://www.netlib.org/c/brent.shar

If x0 is an array containing lower and upper bound for the zero algorithm 748 is applied. Otherwise, if x0 is a number, the algorithm tries to bracket a zero of f starting from x0. If this fails, we fall back to Newton's method.

Type
Number

Details

See
Source
math/numerics.js, line 3526

(private, static) gaussBareiss(mat)

Gauss-Bareiss algorithm to compute the determinant of matrix without fractions. See Henri Cohen, "A Course in Computational Algebraic Number Theory (Graduate texts in mathematics; 138)", Springer-Verlag, ISBN 3-540-55640-0 / 0-387-55640-0 Third, Corrected Printing 1996 "Algorithm 2.2.6", pg. 52-53

Parameters

Name Type Description
mat Array

Matrix

Returns

Number

Details

Source
math/numerics.js, line 203

(static) generalizedNewton(c1, c2, t1ini, t2ini) → {JXG.Coords}

Compute an intersection of the curves c1 and c2 with a generalized Newton method (Newton-Raphson). We want to find values t1, t2 such that c1(t1) = c2(t2), i.e.

(c1_x(t1) - c2_x(t2), c1_y(t1) - c2_y(t2)) = (0, 0).

We set (e, f) := (c1_x(t1) - c2_x(t2), c1_y(t1) - c2_y(t2))

The Jacobian J is defined by

J = (a, b)
    (c, d)

where

  • a = c1_x'(t1)
  • b = -c2_x'(t2)
  • c = c1_y'(t1)
  • d = -c2_y'(t2)

The inverse J^(-1) of J is equal to

 (d, -b) / (ad - bc)
 (-c, a) / (ad - bc)

Then, (t1new, t2new) := (t1,t2) - J^(-1)*(e,f).

Parameters

Name Type Description
c1 Curve | Line | Circle

Curve, Line or Circle

c2 Curve | Line | Circle

Curve, Line or Circle

t1ini Number

start value for t1

t2ini Number

start value for t2

Returns

intersection point

Type
JXG.Coords

Details

Source
math/numerics.js, line 1611

(static) generatePolynomialTerm(coeffs, deg, varname, prec) → {String}

Generate a string containing the function term of a polynomial.

Parameters

Name Type Description
coeffs Array

Coefficients of the polynomial. The position i belongs to x^i.

deg Number

Degree of the polynomial

varname String

Name of the variable (usually 'x')

prec Number

Precision

Returns

A string containing the function term of the polynomial.

Type
String

Details

Source
math/numerics.js, line 2054

(static) lagrangePolynomial(p) → {function}

Computes the polynomial through a given set of coordinates in Lagrange form. Returns the Lagrange polynomials, see Jean-Paul Berrut, Lloyd N. Trefethen: Barycentric Lagrange Interpolation, SIAM Review, Vol 46, No 3, (2004) 501-517.

It possesses the method getTerm() which returns the string containing the function term of the polynomial and the method getCoefficients() which returns an array containing the coefficients of the polynomial.

Examples

var p = [];
p[0] = board.create('point', [-1,2], {size:4});
p[1] = board.create('point', [0,3], {size:4});
p[2] = board.create('point', [1,1], {size:4});
p[3] = board.create('point', [3,-1], {size:4});
var f = JXG.Math.Numerics.lagrangePolynomial(p);
var graph = board.create('functiongraph', [f,-10, 10], {strokeWidth:3});

var points = [];
points[0] = board.create('point', [-1,2], {size:4});
points[1] = board.create('point', [0, 0], {size:4});
points[2] = board.create('point', [2, 1], {size:4});

var f = JXG.Math.Numerics.lagrangePolynomial(points);
var graph = board.create('functiongraph', [f,-10, 10], {strokeWidth:3});
var txt = board.create('text', [-3, -4,  () => f.getTerm(2, 't', ' * ')], {fontSize: 16});
var txt2 = board.create('text', [-3, -6,  () => f.getCoefficients()], {fontSize: 12});

Parameters

Name Type Description
p Array

Array of Points

Returns

A function of one parameter which returns the value of the polynomial, whose graph runs through the given points.

Type
function

Details

Source
math/numerics.js, line 2140

(static) lagrangePolynomialCoefficients(points) → {function}

Determine the Lagrange polynomial through an array of points and return the coefficients of the polynomial as array. The leading coefficient is at position 0.

Example

var points = [];
points[0] = board.create('point', [-1,2], {size:4});
points[1] = board.create('point', [0, 0], {size:4});
points[2] = board.create('point', [2, 1], {size:4});

var f = JXG.Math.Numerics.lagrangePolynomial(points);
var graph = board.create('functiongraph', [f,-10, 10], {strokeWidth:3});

var f_arr = JXG.Math.Numerics.lagrangePolynomialCoefficients(points);
var txt = board.create('text', [1, -4, f_arr], {fontSize: 10});

Parameters

Name Type Description
points Array

Array of Points

Returns

returning the coefficients of the Lagrange polynomial through the supplied points.

Type
function

Details

Source
math/numerics.js, line 2408

(static) lagrangePolynomialTerm(points, digits, param, dot) → {function}

Determine the Lagrange polynomial through an array of points and return the term of the polynomial as string.

Example

var points = [];
points[0] = board.create('point', [-1,2], {size:4});
points[1] = board.create('point', [0, 0], {size:4});
points[2] = board.create('point', [2, 1], {size:4});

var f = JXG.Math.Numerics.lagrangePolynomial(points);
var graph = board.create('functiongraph', [f,-10, 10], {strokeWidth:3});

var f_txt = JXG.Math.Numerics.lagrangePolynomialTerm(points, 2, 't', ' * ');
var txt = board.create('text', [-3, -4, f_txt], {fontSize: 16});

Parameters

Name Type Description
points Array

Array of Points

digits Number

Number of decimal digits of the coefficients

param String

Name of the parameter. Default: 'x'.

dot String

Multiplication symbol. Default: ' * '.

Returns

returning the Lagrange polynomial term through the supplied points as string

Type
function

Details

Source
math/numerics.js, line 2322

(static) polzeros(a, degopt, tolopt, max_itopt, initial_valuesopt) → {Array}

Determine all roots of a polynomial with real or complex coefficients by using the iterative method attributed to Weierstrass, Durand, Kerner, Aberth, and Ehrlich. In particular, the iteration method with cubic convergence is used that is usually attributed to Ehrlich-Aberth.

The returned roots are sorted with respect to their real values. This method makes use of the JSXGraph classes JXG.Complex and JXG.C to handle complex numbers.

Examples

// Polynomial p(z) = -1 + 1z^2
var i, roots,
    p = [-1, 0, 1];

roots = JXG.Math.Numerics.polzeros(p);
for (i = 0; i < roots.length; i++) {
    console.log(i, roots[i].toString());
}
// Output:
  0 -1 + -3.308722450212111e-24i
  1 1 + 0i
// Polynomial p(z) = -1 + 3z - 9z^2 + z^3 - 8z^6 + 9z^7 - 9z^8 + z^9
var i, roots,
    p = [-1, 3, -9, 1, 0, 0, -8, 9, -9, 1];

roots = JXG.Math.Numerics.polzeros(p);
for (i = 0; i < roots.length; i++) {
    console.log(i, roots[i].toString());
}
// Output:
0 -0.7424155888401961 + 0.4950476539211721i
1 -0.7424155888401961 + -0.4950476539211721i
2 0.16674869833354108 + 0.2980502714610669i
3 0.16674869833354108 + -0.29805027146106694i
4 0.21429002063640837 + 1.0682775088132996i
5 0.21429002063640842 + -1.0682775088132999i
6 0.861375497926218 + -0.6259177003583295i
7 0.8613754979262181 + 0.6259177003583295i
8 8.000002743888055 + -1.8367099231598242e-40i

Parameters

Name Type Attributes Default Description
a Array

Array of coefficients of the polynomial a[0] + a[1]*x+ a[2]*x**2... The coefficients are of type Number or JXG.Complex.

deg Number <optional>

Optional degree of the polynomial. Otherwise all entries are taken, with leading zeros removed.

tol Number <optional>
Number.EPSILON

Approximation tolerance

max_it Number <optional>
30

Maximum number of iterations

initial_values Array <optional>
null

Array of initial values for the roots. If not given, starting values are determined by the method of Ozawa.

Returns

Array of complex numbers (of JXG.Complex) approximating the roots of the polynomial.

Type
Array

Details

See
Source
math/numerics.js, line 4361

(static) regressionPolynomial(degree, dataX, dataY) → {function}

Computes the regression polynomial of a given degree through a given set of coordinates. Returns the regression polynomial function.

Parameters

Name Type Description
degree Number | function | Slider

number, function or slider. Either

dataX Array

Array containing either the x-coordinates of the data set or both coordinates in an array of JXG.Points or JXG.Coords. In the latter case, the dataY parameter will be ignored.

dataY Array

Array containing the y-coordinates of the data set,

Returns

A function of one parameter which returns the value of the regression polynomial of the given degree. It possesses the method getTerm() which returns the string containing the function term of the polynomial. The function returned will throw an exception, if the data set is malformed.

Type
function

Details

Source
math/numerics.js, line 2675

(static) riemann(f, n, type, start, end) → {Array}

Helper function to create curve which displays Riemann sums. Compute coordinates for the rectangles showing the Riemann sum.

In case of type "simpson" and "trapezoidal", the horizontal line approximating the function value is replaced by a parabola or a secant. IN case of "simpson", the parabola is approximated visually by a polygonal chain of fixed step width.

Parameters

Name Type Description
f function | Array

Function or array of two functions. If f is a function the integral of this function is approximated by the Riemann sum. If f is an array consisting of two functions the area between the two functions is filled by the Riemann sum bars.

n Number

number of rectangles.

type String

Type of approximation. Possible values are: 'left', 'right', 'middle', 'lower', 'upper', 'random', 'simpson', or 'trapezoidal'. "simpson" is Simpson's 1/3 rule.

start Number

Left border of the approximation interval

end Number

Right border of the approximation interval

Returns

An array of two arrays containing the x and y coordinates for the rectangles showing the Riemann sum. This array may be used as parent array of a JXG.Curve. The third parameteris the riemann sum, i.e. the sum of the volumes of all rectangles.

Type
Array

Details

Source
math/numerics.js, line 3131

(static) riemannsum(f, n, type, start, end) → {Number}

Approximate the integral by Riemann sums. Compute the area described by the riemann sum rectangles.

If there is an element of type Riemannsum, then it is more efficient to use the method JXG.Curve.Value() of this element instead.

Parameters

Name Type Description
f Function_Array

Function or array of two functions. If f is a function the integral of this function is approximated by the Riemann sum. If f is an array consisting of two functions the area between the two functions is approximated by the Riemann sum.

n Number

number of rectangles.

type String

Type of approximation. Possible values are: 'left', 'right', 'middle', 'lower', 'upper', 'random', 'simpson' or 'trapezoidal'.

start Number

Left border of the approximation interval

end Number

Right border of the approximation interval

Returns

The sum of the areas of the rectangles.

Type
Number

Details

Source
math/numerics.js, line 3271

(static) root(f, x, context) → {Number}

Abstract method to find roots of univariate functions, which - for the time being - is an alias for JXG.Math.Numerics.chandrupatla.

Parameters

Name Type Description
f function

We search for a solution of f(x)=0.

x Number | Array

initial guess for the root, i.e. starting value, or start interval enclosing the root. If x is an interval [a,b], it is required that f(a)f(b) <= 0, otherwise the minimum of f in [a, b] will be returned. If x is a number, the algorithms tries to enclose the root by an interval [a, b] containing x and the root and f(a)f(b) <= 0. If this fails, the algorithm falls back to Newton's method.

context Object

optional object that is treated as "this" in the function body. This is useful if the function is a method of an object and contains a reference to its parent object via "this".

Returns

A root of the function f.

Type
Number

Details

See
Source
math/numerics.js, line 1567

(static) rungeKutta(butcher, x0, I, N, f) → {Array}

Solve initial value problems numerically using explicit Runge-Kutta methods. See https://en.wikipedia.org/wiki/Runge-Kutta_methods for more information on the algorithm.

Example

// A very simple autonomous system dx(t)/dt = x(t);
var f = function(t, x) {
    return [x[0]];
}

// Solve it with initial value x(0) = 1 on the interval [0, 2]
// with 20 evaluation points.
var data = JXG.Math.Numerics.rungeKutta('heun', [1], [0, 2], 20, f);

// Prepare data for plotting the solution of the ode using a curve.
var dataX = [];
var dataY = [];
var h = 0.1;        // (I[1] - I[0])/N  = (2-0)/20
var i;
for(i=0; i<data.length; i++) {
    dataX[i] = i*h;
    dataY[i] = data[i][0];
}
var g = board.create('curve', [dataX, dataY], {strokeWidth:'2px'});

Parameters

Name Type Description
butcher object | String

Butcher tableau describing the Runge-Kutta method to use. This can be either a string describing a Runge-Kutta method with a Butcher tableau predefined in JSXGraph like 'euler', 'heun', 'rk4' or an object providing the structure

{
    s: <Number>,
    A: <matrix>,
    b: <Array>,
    c: <Array>
}

which corresponds to the Butcher tableau structure shown here: https://en.wikipedia.org/w/index.php?title=List_of_Runge%E2%80%93Kutta_methods&oldid=357796696 . Default is 'euler'.

x0 Array

Initial value vector. Even if the problem is one-dimensional, the initial value has to be given in an array.

I Array

Interval on which to integrate.

N Number

Number of integration intervals, i.e. there are \(N+1\) evaluation points.

f function

Function describing the right hand side of the first order ordinary differential equation, i.e. if the ode is given by the equation

dx/dt = f(t, x(t))
. So, f has to take two parameters, a number t and a vector x, and has to return a vector of the same length as x has.

Returns

An array of vectors describing the solution of the ode on the given interval I.

Type
Array

Details

Source
math/numerics.js, line 3339

(static) splineDef(x, y) → {Array}

Calculates second derivatives at the given knots.

Parameters

Name Type Description
x Array

x values of knots

y Array

y values of knots

Returns

Second derivatives of the interpolated function at the knots.

Type
Array

Details

See
Source
math/numerics.js, line 1913

(static) splineEval(x0, x, y, F) → {Number|Array}

Evaluate points on spline.

Parameters

Name Type Description
x0 Number | Array

A single float value or an array of values to evaluate

x Array

x values of knots

y Array

y values of knots

F Array

Second derivatives at knots, calculated by JXG.Math.Numerics.splineDef

Returns

A single value or an array, depending on what is given as x0.

Type
Number | Array

Details

See
Source
math/numerics.js, line 1988

Inherited

none

Details

Numerics

Source
math/numerics.js, line 76