Namespace JXG.Math.Numerics
↳ JXG.Math.Numerics
Defined in: MathNumerics.js.
Constructor Attributes | Constructor Name and Description |
---|---|
The JXG.Math.Numerics namespace holds numerical algorithms, constants, and variables.
|
Method Attributes | Method Name and Description |
---|---|
<static> |
JXG.Math.Numerics.backwardSolve(R, b, canModify)
Solves a system of linear equations given by the right triangular matrix R and vector b.
|
<static> |
JXG.Math.Numerics.bezier(points)
Computes the cubic Bezier curve through a given set of points.
|
<static> |
JXG.Math.Numerics.bspline(points, order)
Computes the B-spline curve of order k (order = degree+1) through a given set of points.
|
<static> |
JXG.Math.Numerics.CatmullRomSpline(points)
Computes the cubic Catmull-Rom spline curve through a given set of points.
|
<static> |
JXG.Math.Numerics.D(f, obj)
Numerical (symmetric) approximation of derivative.
|
<static> |
JXG.Math.Numerics.det(mat)
Computes the determinant of a square nxn matrix with the
Gauss-Bareiss algorithm.
|
<static> |
JXG.Math.Numerics.fminbr(f, x0, object)
Find minimum of an univariate function f.
|
<static> |
JXG.Math.Numerics.fzero(f, x0, object)
Find zero of an univariate function f.
|
<static> |
JXG.Math.Numerics.Gauss(A, b)
Solves a system of linear equations given by A and b using the Gauss-Jordan-elimination.
|
<private> <static> |
JXG.Math.Numerics.gaussBareiss(mat)
|
<static> |
JXG.Math.Numerics.generatePolynomialTerm(coeffs, deg, varname, prec)
Generate a string containing the function term of a polynomial.
|
<static> |
JXG.Math.Numerics.I(interval, f)
Integral of function f over interval.
|
<static> |
JXG.Math.Numerics.Jacobi(Ain)
Compute the Eigenvalues and Eigenvectors of a symmetric 3x3 matrix with the Jacobi method
Adaption of a FORTRAN program by Ed Wilson, Dec.
|
<static> |
JXG.Math.Numerics.lagrangePolynomial(p)
Computes the polynomial through a given set of coordinates in Lagrange form.
|
<static> |
JXG.Math.Numerics.Neville(p)
Returns the Lagrange polynomials for curves with equidistant nodes, see
Jean-Paul Berrut, Lloyd N.
|
<static> |
JXG.Math.Numerics.Newton(f, x, object)
Newton's method to find roots of a funtion in one variable.
|
<static> |
JXG.Math.Numerics.NewtonCotes(interval, f, config)
Calculates the integral of function f over interval using Newton-Cotes-algorithm.
|
<static> |
JXG.Math.Numerics.RamerDouglasPeuker(pts, eps)
Implements the Ramer-Douglas-Peuker algorithm.
|
<static> |
JXG.Math.Numerics.regressionPolynomial(degree, dataX, dataY, dataX, dataY)
Computes the regression polynomial of a given degree through a given set of coordinates.
|
<static> |
JXG.Math.Numerics.reuleauxPolygon(points, nr)
Helper function to create curve which displays Reuleaux polygons.
|
<static> |
JXG.Math.Numerics.riemann(f, n, type, start, end)
Helper function to create curve which displays Riemann sums.
|
<static> |
JXG.Math.Numerics.riemannsum(f, n, type, start, end)
Approximate the integral by Riemann sums.
|
<static> |
JXG.Math.Numerics.root(f, x, object)
Abstract method to find roots of univariate functions.
|
<static> |
JXG.Math.Numerics.rungeKutta(butcher, x0, I, N, f)
Solve initial value problems numerically using Runge-Kutta-methods.
|
<static> |
JXG.Math.Numerics.splineDef(x, y)
Calculates second derivatives at the given knots.
|
<static> |
JXG.Math.Numerics.splineEval(x0, x, y, F)
Evaluate points on spline.
|
Namespace Detail
JXG.Math.Numerics
The JXG.Math.Numerics namespace holds numerical algorithms, constants, and variables.
Method Detail
<static>
{Array}
JXG.Math.Numerics.backwardSolve(R, b, canModify)
Solves a system of linear equations given by the right triangular matrix R and vector b.
- Parameters:
- {Array} R
- Right triangular matrix represented by an array of rows. All entries a_(i,j) with i < j are ignored.
- {Array} b
- Right hand side of the linear equation system.
- {Boolean} canModify Optional, Default: false
- 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.
<static>
{Array}
JXG.Math.Numerics.bezier(points)
Computes the cubic Bezier curve through a given set of points.
- Parameters:
- {Array} points
- Array consisting of 3*k+1 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.
<static>
{Array}
JXG.Math.Numerics.bspline(points, order)
Computes the B-spline curve of order k (order = degree+1) through a given set of points.
- Parameters:
- {Array} points
- Array consisting of JXG.Points.
- {Number} order
- 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.
<static>
{Array}
JXG.Math.Numerics.CatmullRomSpline(points)
Computes the cubic Catmull-Rom 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:
- {Array} points
- 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.
<static>
{function}
JXG.Math.Numerics.D(f, obj)
Numerical (symmetric) approximation of derivative. suspendUpdate is piped through, see JXG.Curve#updateCurve
and JXG.Curve#hasPoint.
- Parameters:
- {function} f
- Function in one variable to be differentiated.
- {object} obj 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.
<static>
{Number}
JXG.Math.Numerics.det(mat)
Computes the determinant of a square nxn matrix with the
Gauss-Bareiss algorithm.
- Parameters:
- {Array} mat
- Matrix.
- Returns:
- {Number} The determinant pf the matrix mat. The empty matrix returns 0.
<static>
{number}
JXG.Math.Numerics.fminbr(f, x0, object)
Find minimum of an univariate function f.
- Parameters:
- {function} f
- Function, whose minimum is to be found
- {array} x0
- Start interval enclosing the minimum
- {object} object
- Parent object in case f is method of it
- Returns:
- {number} the approximation of the minimum Algorithm: G.Forsythe, M.Malcolm, C.Moler, Computer methods for mathematical computations. M., Mir, 1980, p.180 of the Russian edition x0
<static>
{number}
JXG.Math.Numerics.fzero(f, x0, object)
Find zero of an univariate function f.
- Parameters:
- {function} f
- Function, whose root is to be found
- {array or number} x0
- 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 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.
<static>
{Array}
JXG.Math.Numerics.Gauss(A, b)
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:
- {Array} A
- Square matrix represented by an array of rows, containing the coefficients of the lineare equation system.
- {Array} b
- A vector containing the linear equation system's right hand side.
- Throws:
- {Error}
- If a non-square-matrix is given or if b has not the right length or A's rank is not full.
- Returns:
- {Array} A vector that solves the linear equation system.
<private> <static>
JXG.Math.Numerics.gaussBareiss(mat)
- Parameters:
- mat
<static>
{String}
JXG.Math.Numerics.generatePolynomialTerm(coeffs, deg, varname, prec)
Generate a string containing the function term of a polynomial.
- Parameters:
- {Array} coeffs
- Coefficients of the polynomial. The position i belongs to x^i.
- {Number} deg
- Degree of the polynomial
- {String} varname
- Name of the variable (usually 'x')
- {Number} prec
- Precision
- Returns:
- {String} A string containg the function term of the polynomial.
<static>
{Number}
JXG.Math.Numerics.I(interval, f)
Integral of function f over interval.
- Parameters:
- {Array} interval
- The integration interval, e.g. [0, 3].
- {function} f
- A function which takes one argument of type number and returns a number.
- Returns:
- {Number} The value of the integral of f over interval
<static>
{Array}
JXG.Math.Numerics.Jacobi(Ain)
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:
- {Array} Ain
- A symmetric 3x3 matrix.
- Returns:
- {Array} [A,V] the matrices A and V. The diagonal of A contains the Eigenvalues, V contains the Eigenvectors.
<static>
{function}
JXG.Math.Numerics.lagrangePolynomial(p)
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:
- {Array} p
- 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.
<static>
{Array}
JXG.Math.Numerics.Neville(p)
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:
- {Array} p
- 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.
<static>
{Number}
JXG.Math.Numerics.Newton(f, x, object)
Newton's method to find roots of a funtion in one variable.
- Parameters:
- {function} f
- We search for a solution of f(x)=0.
- {Number} x
- initial guess for the root, i.e. start value.
- {object} 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.
<static>
{Number}
JXG.Math.Numerics.NewtonCotes(interval, f, config)
Calculates the integral of function f over interval using Newton-Cotes-algorithm.
- Parameters:
- {Array} interval
- The integration interval, e.g. [0, 3].
- {function} f
- A function which takes one argument of type number and returns a number.
- {object} config Optional, Default: {number_of_nodes:28,integration_type:'milne'}
- The algorithm setup. Accepted properties are number_of_nodes of type number and integration_type with value being either 'trapez', 'simpson', or 'milne'.
- 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.
- Returns:
- {Number} Integral value of f over interval
- Examples:
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, intergration_type: 'trapez'});
<static>
{Array}
JXG.Math.Numerics.RamerDouglasPeuker(pts, eps)
Implements the Ramer-Douglas-Peuker 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:
- {Array} pts
- Array of JXG.Coords
- {Number} eps
- 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.
<static>
{function}
JXG.Math.Numerics.regressionPolynomial(degree, dataX, dataY, dataX, dataY)
Computes the regression polynomial of a given degree through a given set of coordinates.
Returns the regression polynomial function.
- Parameters:
- {Number} degree
- number, function or slider. Either
- {Array} dataX
- array containing the x-coordinates of the data set
- {Array} dataY
- array containing the y-coordinates of the data set, or
- {Array} dataX
- Array consisting of JXG.Points.
- dataY
- Ignored
- 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.
<static>
{array}
JXG.Math.Numerics.reuleauxPolygon(points, nr)
Helper function to create curve which displays Reuleaux polygons.
- Parameters:
- {array} points
- Array of points which should be the vertices of the Reuleaux polygon. Typically, these point list is the array vrtices of a regular polygon.
- {number} nr
- Number of vertices
- Returns:
- {array} An array containing the two functions defining the Reuleaux polygon and the two values for the start and the end of the paramtric curve. array may be used as parent array of a JXG.Curve.
- Examples:
var A = brd.create('point',[-2,-2]); var B = brd.create('point',[0,1]); var pol = brd.create('regularpolygon',[A,B,3], {withLines:false, fillColor:'none', highlightFillColor:'none', fillOpacity:0.0}); var reuleauxTriangle = brd.create('curve', JXG.Math.Numerics.reuleauxPolygon(pol.vertices, 3), {strokeWidth:6, strokeColor:'#d66d55', fillColor:'#ad5544', highlightFillColor:'#ad5544'});
<static>
{Array}
JXG.Math.Numerics.riemann(f, n, type, start, end)
Helper function to create curve which displays Riemann sums.
Compute coordinates for the rectangles showing the Riemann sum.
- Parameters:
- {function} f
- Function, whose integral is approximated by the Riemann sum.
- {Number} n
- number of rectangles.
- {String} type
- Type of approximation. Possible values are: 'left', 'right', 'middle', 'lower', 'upper', or 'trapezodial'.
- {Number} start
- Left border of the approximation interval
- {Number} end
- 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 JXG.Curve.
<static>
{Number}
JXG.Math.Numerics.riemannsum(f, n, type, start, end)
Approximate the integral by Riemann sums.
Compute the area described by the riemann sum rectangles.
- Parameters:
- {function} f
- Function, whose integral is approximated by the Riemann sum.
- {Number} n
- number of rectangles.
- {String} type
- Type of approximation. Possible values are: 'left', 'right', 'middle', 'lower', 'upper', or 'trapezodial'.
- {Number} start
- Left border of the approximation interval
- {Number} end
- Right border of the approximation interval
- Returns:
- {Number} The sum of the areas of the rectangles.
<static>
{Number}
JXG.Math.Numerics.root(f, x, object)
Abstract method to find roots of univariate functions.
- Parameters:
- {function} f
- We search for a solution of f(x)=0.
- {Number} x
- initial guess for the root, i.e. staring value.
- {object} 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.
<static>
{Array}
JXG.Math.Numerics.rungeKutta(butcher, x0, I, N, f)
Solve initial value problems numerically using Runge-Kutta-methods.
See http://en.wikipedia.org/wiki/Runge-Kutta_methods for more information on the algorithm.
- Parameters:
- {object|String} butcher
- 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%E2%80%93Kutta_methods&oldid=357796696 - {Array} x0
- Initial value vector. If the problem is of one-dimensional, the initial value also has to be given in an array.
- {Array} I
- Interval on which to integrate.
- {Number} N
- Number of evaluation points.
- {function} f
- 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.
- Examples:
// 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<data.length; i++) { dataX[i] = i*h; dataY[i] = data[i][0]; } var g = board.create('curve', [dataX, dataY], {strokeWidth:'2px'});
<static>
{Array}
JXG.Math.Numerics.splineDef(x, y)
Calculates second derivatives at the given knots.
- Parameters:
- {Array} x
- x values of knots
- {Array} y
- y values of knots
- Returns:
- {Array} Second derivatives of the interpolated function at the knots.
- See:
- #splineEval
<static>
{Number|Array}
JXG.Math.Numerics.splineEval(x0, x, y, F)
Evaluate points on spline.
- Parameters:
- {Number|Array} x0
- A single float value or an array of values to evaluate
- {Array} x
- x values of knots
- {Array} y
- y values of knots
- {Array} F
- Second derivatives at knots, calculated by #splineDef
- Returns:
- {Number|Array} A single value or an array, depending on what is given as x0.
- See:
- #splineDef