Integration of Gauss-type
Compute nodes and weights for Gauss integration.
xwGauss(n, method = "legendre") changeInterval(nodes, weights, oldmin, oldmax, newmin, newmax)
n |
number of nodes |
method |
character. default is |
nodes |
the nodes (a numeric vector) |
weights |
the weights (a numeric vector) |
oldmin |
the minimum of the interval (typically as tabulated) |
oldmax |
the maximum of the interval (typically as tabulated) |
newmin |
the desired minimum of the interval |
newmax |
the desired maximum of the interval |
xwGauss
computes nodes and weights for integration for the
interval -1 to 1. It uses the method of Golub and Welsch (1969).
changeInterval
is a utility that transforms nodes and weights
to an arbitrary interval.
a list with two elements
weights |
a numeric vector |
nodes |
a numeric vector |
Enrico Schumann
Gilli, M., Maringer, D. and Schumann, E. (2019) Numerical Methods and Optimization in Finance. 2nd edition. Elsevier. https://www.elsevier.com/books/numerical-methods-and-optimization-in-finance/gilli/978-0-12-815065-8
Golub, G.H. and Welsch, J.H. (1969). Calculation of Gauss Quadrature Rules. Mathematics of Computation, 23(106), pp. 221–230+s1–s10.
Schumann, E. (2019) Financial Optimisation with R (NMOF Manual). http://enricoschumann.net/NMOF.htm#NMOFmanual
## examples from Gilli/Maringer/Schumann (2011), ch. 15 ## a test function f1 <- function(x) exp(-x) m <- 5; a <- 0; b <- 5 h <- (b - a)/m ## rectangular rule -- left w <- h; k <- 0:(m-1); x <- a + k * h sum(w * f1(x)) ## rectangular rule -- right w <- h; k <- 1:m ; x <- a + k * h sum(w * f1(x)) ## midpoint rule w <- h; k <- 0:(m-1); x <- a + (k + 0.5)*h sum(w * f1(x)) ## trapezoidal rule w <- h k <- 1:(m-1) x <- c(a, a + k*h, b) aux <- w * f1(x) sum(aux) - (aux[1] + aux[length(aux)])/2 ## R's integrate (from package stats) integrate(f1, lower = a,upper = b) ## Gauss--Legendre temp <- xwGauss(m) temp <- changeInterval(temp$nodes, temp$weights, oldmin = -1, oldmax = 1, newmin = a, newmax = b) x <- temp$nodes; w <- temp$weights sum(w * f1(x))
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.