gaussLegendreQuadrature

Gauss-Legendre Quadrature

@safe pure nothrow @nogc
size_t
gaussLegendreQuadrature
(
T
)
(
scope T[] x
,
scope T[] w
,
scope T[] work
)

Parameters

x T[]

(out) user-allocated quadrature nodes in ascending order length of N

w T[]

(out) user-allocated corresponding quadrature weights length of N

work T[]

(temp) user-allocated workspace length of greate or equal to (N + 1) ^^ 2

Return Value

Type: size_t

0 on success, xSTEQR LAPACK code on numerical error.

Examples

import mir.math.common;
import mir.ndslice.allocation;

auto n = 5;
auto x = new double[n];
auto w = new double[n];
auto work = new double[(n + 1) ^^ 2];

gaussLegendreQuadrature(x, w, work);

static immutable xc =
   [-0.90617985,
    -0.53846931,
     0.        ,
     0.53846931,
     0.90617985];

static immutable wc =
   [0.23692689,
    0.47862867,
    0.56888889,
    0.47862867,
    0.23692689];

foreach (i; 0 .. n)
{
    assert(x[i].approxEqual(xc[i]));
    assert(w[i].approxEqual(wc[i]));
}

Meta