m <- 100
xs <- seq(-1, 1, length.out = m + 1)
gram_weights <- create_gram_weights(m)
# the sum of stable weights is equal to 2.
cat("Sum of Gram weights:", sum(gram_weights), "\n")
# test integration, integrate f below between [-1,1]
f = function(x){ 9 * x ^ 2 + 45 * 13 * x ^ 3 + 16 * x ^ 4}
gram_quad <- sum(gram_weights * f(xs))
cat("Approx. integration:", gram_quad, "\n")
Run the code above in your browser using DataLab