Hello everybody I need to approximate the amount of integral by using legendre quadrature. I have written a program which doesn't give me a logical answer; Can anybody help me and send the correct program? For example the approximated amount of integral of ( x ^2) on (-1,1) based on legendre quad rule. integrand<-function(x) {x^2} rules <- legendre.quadrature.rules( 50 ) order.rule <- rules[[50]] chebyshev.c.quadrature(integrand, order.rule, lower = -1, upper = 1) Thank you Diba [[alternative HTML version deleted]]
you could use package distrEx: library(distrEx) GLIntegrate(function(x) x^2, lower = -1, upper = 1, order = 50) hth Matthias On 01.05.2014 09:43, pari hesabi wrote:> Hello everybody > I need to approximate the amount of integral by using > legendre quadrature. I have written a program which doesn't give me a > logical answer; Can anybody help me and send the correct program? For > example the approximated amount of integral of ( x ^2) on (-1,1) based > on legendre quad rule. > > > > > integrand<-function(x) {x^2} > rules <- legendre.quadrature.rules( 50 ) > order.rule <- rules[[50]] > chebyshev.c.quadrature(integrand, order.rule, lower = -1, upper = 1) > > Thank you > Diba > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >-- Prof. Dr. Matthias Kohl www.stamats.de
On Thu, 01 May 2014, pari hesabi <statistics84 at hotmail.com> writes:> Hello everybody > I need to approximate the amount of integral by using > legendre quadrature. I have written a program which doesn't give me a > logical answer; Can anybody help me and send the correct program? For > example the approximated amount of integral of ( x ^2) on (-1,1) based > on legendre quad rule. >One possibility: require("NMOF") xw <-xwGauss(10, "legendre") fun <- function(x) x^2 sum(fun(xw$nodes) * xw$weights)> > > integrand<-function(x) {x^2} > rules <- legendre.quadrature.rules( 50 )Error: object 'legendre.quadrature.rules' not found PLEASE "provide commented, minimal, self-contained, reproducible code".> order.rule <- rules[[50]] > chebyshev.c.quadrature(integrand, order.rule, lower = -1, upper = 1) > > Thank you > Diba-- Enrico Schumann Lucerne, Switzerland http://enricoschumann.net
On 01-05-2014, at 09:43, pari hesabi <statistics84 at hotmail.com> wrote:> Hello everybody > I need to approximate the amount of integral by using > legendre quadrature. I have written a program which doesn't give me a > logical answer; Can anybody help me and send the correct program? For > example the approximated amount of integral of ( x ^2) on (-1,1) based > on legendre quad rule. > > > > > integrand<-function(x) {x^2} > rules <- legendre.quadrature.rules( 50 ) > order.rule <- rules[[50]] > chebyshev.c.quadrature(integrand, order.rule, lower = -1, upper = 1)You must be using package gaussquad. Why are you using Legendre rules but doing Chebyshev quadrature (which does not seem correct)? Replace the last line of your given code with legendre.quadrature(integrand, order.rule, lower = -1, upper = 1) and the result will make more sense. Berend