github ↗
docs menu

Module Quad.Rule

Quadrature rules on [−1, 1].

A rule's tag says which integrals take it: `Formula rules sum their nodes in fixed and cumulative; `Embedded rules also estimate their error.

#type -'k t

The type for rules with tags 'k. A rule with more tags can be used as one with fewer, by coercion: (Quad.Rule.kronrod 7 :> [ `Formula ] Quad.Rule.t).

#val gauss : int -> [ `Formula ] t

gauss n is the n-point Gauss–Legendre rule, exact for polynomials of degree 2n − 1. Its nodes and weights are computed on the host in float64 by Newton's method on the Legendre polynomial.

Raises Invalid_argument if n < 1.

#val kronrod : int -> [ `Formula | `Embedded ] t

kronrod n is the (2n + 1)-point Gauss–Kronrod rule that extends gauss n (Piessens et al., QUADPACK, 1983): exact for polynomials of degree 3n + 1, with the n Gauss nodes among its own. n is 7 or 10.

Raises Invalid_argument if n is neither.

#val nodes : _ t -> (float, 'b) Nx.dtype -> (float, 'b, Nx.host) Nx.t * (float, 'b, Nx.host) Nx.t

nodes r dtype is (x, w), r's nodes in increasing order and their weights, 1-D tensors of dtype: Σ w f(x) approximates ∫₋₁¹ f. A sum in log space is logsumexp (log w + ℓ x).

#val nodes_at : 'd Nx.Placement.t -> _ t -> (float, 'b) Nx.dtype -> (float, 'b, 'd) Nx.t * (float, 'b, 'd) Nx.t

nodes_at p r dtype is nodes r dtype at p.