search for: gauss_legendr

Displaying 2 results from an estimated 2 matches for "gauss_legendr".

Did you mean: gauss_legendre
2008 Sep 27
3
Double integration - Gauss Quadrature
...work for a double one: # Gauss-Legendre abscissas nodes <- gauss.quad.prob(25,dist="uniform",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) }...
2008 Oct 15
0
R-help Digest, Vol 67, Issue 31
...written the following code (using R's statmod package) which > works fine for one integral but it doesn't work for a double one: Maybe there's some way to use sapply as your code suggests, but I'm not sure where you defined the $value that is being returned in your inner call: gauss_legendre(function(x) x*y, 0, 1, nodes, weights)$value I converted some old IDL code to do this 2D integral but without trying to use your sapply: # For N=5, see "known" values here: # http://mathworld.wolfram.com/Legendre-GaussQuadrature.html library(statmod) N <- 5 GL <- gauss.quad(N)...