Dear all,
It has been ages since I studied integration in college. Right now I try to recover all this kind of knowledge and then try to understand how integration works. Thus I am doing some first 'experiments' and I would like to request your help and comments. I have the function: p2<-function(x){0.5*(3*x^2-1)} # I found the square of p2 by using some pencil and paper. # The result is inside myfunc below myfunc<- function(x) {0.25*(9*x^4+6*x^2+1)} # Below I made R to find the square of p2 p2sq<-function(x) {p2(x) * p2(x)} # Now I am trying to integrate both two function at the same interval. #Both functions should denote the square of p2 integrate(p2sq,-1,+1) # returns 0.4 with absolute error < 4.4e-15 integrate(myfunc,-1,+1) # returns 2.4 with absolute error < 2.7e-14 if there is no error in my calculations could you please explain me why the two integrations return different results. Might be that I am missing something from the theory. I would like to thank you for your help Regards Alex ______________________________________________ [hidden email] 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. |
Hi
[hidden email] napsal dne 10.01.2011 15:12:33: > Dear all, > > It has been ages since I studied integration in college. Right now I > try to recover all this kind of knowledge and then try to understand how > integration works. > > > > Thus I am doing some first 'experiments' and I would like to request your help > and comments. > > > > I have the function: > > > > p2<-function(x){0.5*(3*x^2-1)} > > # I found the square of p2 by using some pencil and paper. > > # The result is inside myfunc below > > > > myfunc<- function(x) {0.25*(9*x^4+6*x^2+1)} It is quite a long time I did school math but shouldn't be myfunc<- function(x) {0.25*(9*x^4-6*x^2+1)} ^^^^^ myfunc<- function(x) {0.25*(9*x^4-6*x^2+1)} curve(myfunc,-1,1) integrate(p2sq,-1,+1) 0.4 with absolute error < 4.4e-15 integrate(myfunc,-1,+1) 0.4 with absolute error < 4.4e-15 Regards Petr > > > > # Below I made R to find the square of p2 > > p2sq<-function(x) {p2(x) * p2(x)} > > > > # Now I am trying to integrate both two function at the same interval. > functions should denote the square of p2 > > > > integrate(p2sq,-1,+1) > > # returns 0.4 with absolute error < 4.4e-15 > > > > integrate(myfunc,-1,+1) > > # returns 2.4 with absolute error < 2.7e-14 > > > > if there is no error in my calculations could you please explain me why > the two integrations return different results. Might be that I am > missing something from the theory. I would like to thank you for your > help > > > > Regards > > Alex > > ______________________________________________ > [hidden email] mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > and provide commented, minimal, self-contained, reproducible code. ______________________________________________ [hidden email] 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. |
In reply to this post by alaios
You are missing basic algebra skills!
You had: myfunc<- function(x) {0.25*(9*x^4 + 6*x^2 + 1)} This should be: myfunc<- function(x) {0.25*(9*x^4 - 6*x^2 + 1)} Ravi. ------------------------------------------------------- Ravi Varadhan, Ph.D. Assistant Professor, Division of Geriatric Medicine and Gerontology School of Medicine Johns Hopkins University Ph. (410) 502-2619 email: [hidden email] -----Original Message----- From: [hidden email] [mailto:[hidden email]] On Behalf Of Alaios Sent: Monday, January 10, 2011 9:13 AM To: [hidden email] Subject: [R] Integration in R Dear all, It has been ages since I studied integration in college. Right now I try to recover all this kind of knowledge and then try to understand how integration works. Thus I am doing some first 'experiments' and I would like to request your help and comments. I have the function: p2<-function(x){0.5*(3*x^2-1)} # I found the square of p2 by using some pencil and paper. # The result is inside myfunc below myfunc<- function(x) {0.25*(9*x^4+6*x^2+1)} # Below I made R to find the square of p2 p2sq<-function(x) {p2(x) * p2(x)} # Now I am trying to integrate both two function at the same interval. #Both functions should denote the square of p2 integrate(p2sq,-1,+1) # returns 0.4 with absolute error < 4.4e-15 integrate(myfunc,-1,+1) # returns 2.4 with absolute error < 2.7e-14 if there is no error in my calculations could you please explain me why the two integrations return different results. Might be that I am missing something from the theory. I would like to thank you for your help Regards Alex ______________________________________________ [hidden email] 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. ______________________________________________ [hidden email] 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. |
In reply to this post by PIKAL Petr
Thanks a lot :)
Feeling embarassed ! Alex --- On Mon, 1/10/11, Petr PIKAL <[hidden email]> wrote: > From: Petr PIKAL <[hidden email]> > Subject: Odp: [R] Integration in R > To: "Alaios" <[hidden email]> > Cc: [hidden email] > Date: Monday, January 10, 2011, 2:45 PM > Hi > > [hidden email] > napsal dne 10.01.2011 15:12:33: > > > Dear all, > > > > It has been ages since I studied > integration in college. Right now I > > try to recover all this kind of knowledge and then try > to understand how > > integration works. > > > > > > > > Thus I am doing some first 'experiments' and I would > like to request > your help > > and comments. > > > > > > > > I have the function: > > > > > > > > p2<-function(x){0.5*(3*x^2-1)} > > > > # I found the square of p2 by using some pencil and > paper. > > > > # The result is inside myfunc below > > > > > > > > myfunc<- function(x) {0.25*(9*x^4+6*x^2+1)} > > It is quite a long time I did school math but shouldn't be > > myfunc<- function(x) {0.25*(9*x^4-6*x^2+1)} > > > ^^^^^ > myfunc<- function(x) {0.25*(9*x^4-6*x^2+1)} > curve(myfunc,-1,1) > integrate(p2sq,-1,+1) > 0.4 with absolute error < 4.4e-15 > integrate(myfunc,-1,+1) > 0.4 with absolute error < 4.4e-15 > > Regards > Petr > > > > > > > > > > > # Below I made R to find the square of p2 > > > > p2sq<-function(x) {p2(x) * p2(x)} > > > > > > > > # Now I am trying to integrate both two function at > the same interval. > #Both > > functions should denote the square of p2 > > > > > > > > integrate(p2sq,-1,+1) > > > > # returns 0.4 with absolute error < 4.4e-15 > > > > > > > > integrate(myfunc,-1,+1) > > > > # returns 2.4 with absolute error < 2.7e-14 > > > > > > > > if there is no error in my calculations could you > please explain me why > > the two integrations return different results. Might > be that I am > > missing something from the theory. I would like to > thank you for your > > help > > > > > > > > Regards > > > > Alex > > > > ______________________________________________ > > [hidden email] > 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. > > ______________________________________________ [hidden email] 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. |
Free forum by Nabble | Edit this page |