Title: | Gregory Weights for Function Integration |
---|---|
Description: | Computes Gregory weights for a given number nodes and function order. Anthony Ralston and Philip Rabinowitz (2001) <ISBN:9780486414546> |
Authors: | Dylan Hettinger [aut, cre, cph]
|
Maintainer: | Dylan Hettinger <[email protected]> |
License: | GPL-3 |
Version: | 1.0.0 |
Built: | 2025-02-18 04:56:32 UTC |
Source: | https://github.com/dhetting/gregoryquadrature |
f %*% t(w)
where w are the returned weights. Translated
from https://www.colorado.edu/amath/sites/default/files/attached-files/gregory.pdf.Calculate the Gregory quadrature weights for equispaced integration. If f is
a row vector containing the function values, the integral is approximated by
the statement f %*% t(w)
where w are the returned weights. Translated
from https://www.colorado.edu/amath/sites/default/files/attached-files/gregory.pdf.
Gregory_weights(n_nodes, h, order)
Gregory_weights(n_nodes, h, order)
n_nodes |
Total number of nodes |
h |
Step size |
order |
Order of accuracy desired. 2, 3, 4, ... (with 2 giving the trapezoidal rule). The value must satisfy 2 <= order <= n_nodes |
The weights to be used for the successive function values
n_nodes = 11 order = 8 h = 2/(n_nodes-1) x = pracma::linspace(-1, 1, n_nodes) f = exp(x) w = GregoryQuadrature::Gregory_weights(n_nodes, h, order) int = f %*% w # Exact value for integral exact = exp(1) - exp(-1) error = int - exact
n_nodes = 11 order = 8 h = 2/(n_nodes-1) x = pracma::linspace(-1, 1, n_nodes) f = exp(x) w = GregoryQuadrature::Gregory_weights(n_nodes, h, order) int = f %*% w # Exact value for integral exact = exp(1) - exp(-1) error = int - exact