search for: ab_nodes

Displaying 1 result from an estimated 1 matches for "ab_nodes".

2008 Sep 27
3
Double integration - Gauss Quadrature
...orm",l=-1,u=1)$nodes # and weights weights <- gauss.quad.prob(25,dist="uniform",l=-1,u=1)$weights weights <- weights*2 # Approximate integral of f from a to b using Gauss-Legendre gauss_legendre<-function(f,a,b,nodes,weights) { # change of variables from [-1,1] to [a,b] ab_nodes <- a + (b-a)*(nodes+1)/2; ab_weights <- weights*(b-a)/2; # apply Gauss-Legendre rule sum <- 0 for(i in 1:length(nodes)){ sum <- (sum + ab_weights[i]*f(ab_nodes[i]))} return(sum) } gauss_legendre(function(y) { sapply(y, function(y) { gauss_legendre(function(x) x*y, 0, 1, n...