API Docs for: 0.99.4
Show:

JXG.Math.Numerics Class

Module: JXG

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

Methods

_gaussKonrod

(
  • interval
  • f
  • n
  • xgk
  • wg
  • wgk
  • resultObj
)
Number private

Generic Gauss-Kronrod quadrature algorithm. Internal method used in undefined, undefined, undefined. Taken from QUADPACK.

Parameters:

  • interval Array

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

  • f Function

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

  • n Number

    order

  • xgk Array

    Kronrod quadrature abscissae

  • wg Array

    Weights of the Gauss rule

  • wgk Array

    Weights of the Kronrod rule

  • resultObj Object

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

Returns:

Number:

Integral value of f over interval

_riemannValue

(
  • x
  • f
  • type
  • delta
)
Number private

Evaluate the function term for {@see #riemann}.

Parameters:

  • x Number

    function argument

  • f Function

    JavaScript function returning a number

  • type String

    Name of the Riemann sum type, e.g. 'lower', see {@see #riemann}.

  • delta Number

    Width of the bars in user coordinates

Returns:

Number:

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

_workspace

(
  • interval
  • n
)
Object private

Generate workspace object for undefined.

Parameters:

  • interval Array

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

  • n Number

    Max. limit

Returns:

Object:

Workspace object

backwardSolve

(
  • R
  • b
  • [canModify=false]
)
Array

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

Parameters:

  • 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=false] Boolean optional

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

Returns:

Array:

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

bezier

(
  • points
)
Array

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

Parameters:

  • points Array

    Array consisting of 3*k+1 {@link JXG.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:

Array:

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.

bspline

(
  • points
  • order
)
Array

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

Parameters:

  • points Array

    Array consisting of JXG.Points.

  • order Number

    Order of the B-spline curve.

Returns:

Array:

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.

CardinalSpline

(
  • points
  • tau
)
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.

Parameters:

  • points Array

    Array consisting of JXG.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.

Returns:

Array:

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.

CatmullRomSpline

(
  • points
)
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:

  • points Array

    Array consisting of JXG.Points.

Returns:

Array:

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.

D

(
  • f
  • [obj]
)
Function

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

Parameters:

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

Function:

Derivative function of a given function f.

det

(
  • mat
)
Number

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

Parameters:

Returns:

Number:

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

fminbr

(
  • f
  • x0
  • context
)
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 x0

Parameters:

  • f Function

    Function, whose minimum is to be found

  • x0 Array

    Start interval enclosing the minimum

  • context Object

    Parent object in case f is method of it

Returns:

Number:

the approximation of the minimum value position

fzero

(
  • f
  • x0
  • object
)
Number

Find zero 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 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.

Parameters:

  • f Function

    Function, whose root is to be found

  • x0 Array | Number

    Start value or start interval enclosing the root

  • object Object

    Parent object in case f is method of it

Returns:

Number:

the approximation of the root

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:

  • 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.

Returns:

Array:

A vector that solves the linear equation system.

Throws:

Error:

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

gaussBareiss

(
  • mat
)
Number private

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:

Returns:

Number:

Determinant of matrix mat

GaussKronrod15

(
  • interval
  • f
  • resultObj
)
Number

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

Gauss quadrature weights and kronrod quadrature abscissae and weights as evaluated with 80 decimal digit arithmetic by L. W. Fullerton, Bell Labs, Nov. 1981.

Parameters:

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

Number:

Integral value of f over interval

GaussKronrod21

(
  • interval
  • f
  • resultObj
)
Number

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

Gauss quadrature weights and kronrod quadrature abscissae and weights as evaluated with 80 decimal digit arithmetic by L. W. Fullerton, Bell Labs, Nov. 1981.

Parameters:

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

Number:

Integral value of f over interval

GaussKronrod31

(
  • interval
  • f
  • resultObj
)
Number

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

Gauss quadrature weights and kronrod quadrature abscissae and weights as evaluated with 80 decimal digit arithmetic by L. W. Fullerton, Bell Labs, Nov. 1981.

Parameters:

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

Number:

Integral value of f over interval

GaussLegendre

(
  • interval
  • f
  • [config]
)
Number

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

Parameters:

  • 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.

Returns:

Number:

Integral value of f over interval

Example:

function f(x) {
                        return x*x;
                    }
                    
                    // calculates integral of <tt>f</tt> 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});

generalizedNewton

(
  • c1
  • c2
  • t1ini
  • t2ini
)
JXG.Coords

Compute an intersection of the curves c1 and c2 with a generalized Newton method. 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)/ (-c, a) / (ad-bc)

Then, (t1new, t2new) := (t1,t2) - J^(-1)*(e,f). If the function meetCurveCurve possesses the properties t1memo and t2memo then these are taken as start values for the Newton algorithm. After stopping of the Newton algorithm the values of t1 and t2 are stored in t1memo and t2memo.

Parameters:

Returns:

JXG.Coords:

intersection point

generatePolynomialTerm

(
  • coeffs
  • deg
  • varname
  • prec
)
String

Generate a string containing the function term of a polynomial.

Parameters:

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

String:

A string containg the function term of the polynomial.

I

(
  • interval
  • f
)
Number

Integral of function f over interval.

Parameters:

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

Number:

The value of the integral of f over interval

See also:

  • JXG.Math.Numerics#JXG.Math.Numerics.NewtonCotes
  • JXG.Math.Numerics#JXG.Math.Numerics.Romberg
  • JXG.Math.Numerics#JXG.Math.Numerics.Qag

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:

  • Ain Array

    A symmetric 3x3 matrix.

Returns:

Array:

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

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.

Parameters:

  • p Array

    Array of JXG.Points

Returns:

Function:

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

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.

Parameters:

  • p Array

    Array of JXG.Points

Returns:

Array:

An array consisting of two functions x(t), y(t) which define a parametric curve f(t) = (x(t), y(t)) and two numbers x1 and x2 defining the curve's domain. x1 always equals zero.

Newton

(
  • f
  • x
  • context
)
Number

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

Parameters:

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

Number:

A root of the function f.

NewtonCotes

(
  • interval
  • f
  • [config]
)
Number

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

Parameters:

  • 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'.

    • [number_of_nodes=28] Number optional
    • [integration_type='milne'] String optional

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

Returns:

Number:

Integral value of f over interval

Throws:

Error:

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.

Example:

function f(x) {
                        return x*x;
                    }
                    
                    // calculates integral of <tt>f</tt> 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'});

Qag

(
  • interval
  • f
  • [config]
)
Number

Quadrature algorithm qag from QUADPACK. Internal method used in undefined, undefined, undefined.

Parameters:

  • 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.

    • [limit=15] Number optional
    • [epsrel=0.0000001] Number optional
    • [epsabs=0.0000001] Number optional
    • [q=JXG.Math.Numerics.GaussKronrod15] Number optional

Returns:

Number:

Integral value of f over interval

Example:

function f(x) {
                        return x*x;
                    }
                    
                    // calculates integral of <tt>f</tt> 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});

RamerDouglasPeucker

(
  • pts
  • eps
)
Array

Implements 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:

  • pts Array

    Array of {@link JXG.Coords}

  • eps Number

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

Returns:

Array:

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

RamerDouglasPeuker

() deprecated

Defined in src/math/numerics.js:3111

Deprecated: Use {@link JXG.Math.Numerics#RamerDouglasPeucker}

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

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:

  • degree Number | Function | JXG.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 {@link JXG.Point}s or {@link JXG.Coords}. In the latter case, the dataY parameter will be ignored.

  • dataY Array

    Array containing the y-coordinates of the data set,

Returns:

Function:

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.

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.

Parameters:

  • 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'.

  • start Number

    Left border of the approximation interval

  • end Number

    Right border of the approximation interval

Returns:

Array:

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 {@link JXG.Curve}. The third parameteris the riemann sum, i.e. the sum of the volumes of all rectangles.

riemannsum

(
  • f
  • n
  • type
  • start
  • end
)
Number deprecated

Defined in src/math/numerics.js:2456

Deprecated: Replaced by JXG.Curve.Value(), see {@link JXG.Curve#riemannsum}

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

Parameters:

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

Number:

The sum of the areas of the rectangles.

Romberg

(
  • interval
  • f
  • [config]
)
Number

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

Parameters:

  • 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.

    • [max_iterations=20] Number optional
    • [eps=0.0000001] Number optional

Returns:

Number:

Integral value of f over interval

Example:

function f(x) {
                        return x*x;
                    }
                    
                    // calculates integral of <tt>f</tt> 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});

root

(
  • f
  • x
  • context
)
Number

Abstract method to find roots of univariate functions.

Parameters:

  • f Function

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

  • x Number

    initial guess for the root, i.e. starting 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:

Number:

A root of the function f.

rungeKutta

(
  • butcher
  • x0
  • I
  • N
  • f
)
Array

Solve initial value problems numerically using Runge-Kutta-methods. See undefined for more information on the algorithm.

Parameters:

  • 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: http://en.wikipedia.org/w/index.php?title=List_of_Runge–Kutta_methods&oldid=357796696

  • x0 Array

    Initial value vector. If the problem is of one-dimensional, the initial value also has to be given in an array.

  • I Array

    Interval on which to integrate.

  • N Number

    Number of 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 dimension as x has.

Returns:

Array:

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

Example:

// A very simple autonomous system dx(t)/dt = x(t);
                    function f(t, x) {
                        return x;
                    }
                    
                    // 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
                    for(var i=0; i&lt;data.length; i++) {
                        dataX[i] = i*h;
                        dataY[i] = data[i][0];
                    }
                    var g = board.create('curve', [dataX, dataY], {strokeWidth:'2px'});
                    

splineDef

(
  • x
  • y
)
Array

Calculates second derivatives at the given knots.

Parameters:

  • x Array

    x values of knots

  • y Array

    y values of knots

Returns:

Array:

Second derivatives of the interpolated function at the knots.

See also:

  • #splineEval

splineEval

(
  • x0
  • x
  • y
  • F
)
Number | Array

Evaluate points on spline.

Parameters:

  • 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 {@link #splineDef}

Returns:

Number | Array:

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

See also:

  • #splineDef

Properties

maxIterationsMinimize

Number

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

Default: 500

maxIterationsRoot

Number

Maximum number of iterations in JXG.Math.Numerics#fzero

Default: 80