IntegrationPoints

Package: Libraries.Compute.Statistics.Distributions · Inherits from: Libraries.Language.Object

The IntegrationPoints class holds the nodes and weights of an n-point Gauss-Legendre quadrature rule on (-1, 1): the integral of g(y) from -1 to 1 is approximately the sum of weight i times g(node i), exactly for polynomials of degree up to 2n - 1. The nodes are the roots of the Legendre polynomial P_n, found by Newton's method from the starting guesses cos(pi (i - 1/4) / (n + 1/2)); each weight is 2 / ((1 - x^2) P_n'(x)^2), as in Abramowitz and Stegun (1970), 25.4.29. RangeRatioDistribution uses 12 and 16 points, as Copenhaver and Holland (1988) do.

Example Code

use Libraries.Compute.Statistics.Distributions.IntegrationPoints

IntegrationPoints rule
rule:Setup(12)
// the integral of y^2 from -1 to 1 is 2/3
number total = 0
integer i = 0
repeat while i < rule:GetSize()
    total = total + rule:GetWeight(i) * rule:GetNode(i) * rule:GetNode(i)
    i = i + 1
end
output total

Actions

GetNode(integer index)

This action returns a node.

Parameters

  • index integer: The node, from 0.

Returns

number: The node, in (-1, 1).

GetSize()

This action returns how many points the rule has.

Returns

integer

GetWeight(integer index)

This action returns a node's weight.

Parameters

  • index integer: The node, from 0.

Returns

number: The weight.

Setup(integer size)

This action computes the nodes and weights of the n-point rule, smallest node first.

Parameters

  • size integer: How many points (n), 1 or more.

Inherited Actions

3 actions from Libraries.Language.Object