Hello I have two function in R like g(x)=2x-3 and s(x)=5x^2+2 and I want to find the integrafl of the g(x)*s(x) inside the interval of [a,b] Could you please help me find the proper function? I would like to thank you in advance for your help Regards Alex [[alternative HTML version deleted]]
Alaios <alaios <at> yahoo.com> writes:> > Hello I have two function in R > like > g(x)=2x-3 > and s(x)=5x^2+2 > > and I want to find the integrafl of the g(x)*s(x) inside the interval of [a,b] >Analytically or numerically? It sounds like you want the answer analytically, in which case R can't do it, but it is an easy integral g(x)*s(x) = 10*x^3-15*x^2+4*x-6 indefinite integral = 10/3*x^4 -15/3*x^3 + 4/2*x^2 - 6*x + C evaluate between a and b or if you can't do this (although this is a very basic integral) you can try it on Wolfram alpha/the Mathematica integrator (google for it) use ?integrate (surprisingly enough) for 1-D numerical integration
On Dec 16, 2010, at 7:27 AM, Alaios wrote:> Hello I have two function in R > like > g(x)=2x-3 > and s(x)=5x^2+2 > > and I want to find the integrafl of the g(x)*s(x) inside the > interval of [a,b] > > Could you please help me find the proper function?It depends on what you are doing: None of what appears below is valid R code. Finding the closed form expression for the integral of a third degree polynomial evaluated at a and b would be a simple first semester calculus problem. It's not clear why you are using R for this. And if someone has posed this to you as a homework problem in hopes that you will find a way to get a polynomial solution in terms of a and b then you need to look at the RYacas package. R has some limited symbolic differentiation tools but I do not remember seeing any symbolic integrations within R. So if you were think of using not a and b but rather specific numbers for a numeric solution, then the integrate function is the obvious choice. If you don't understand what the help page for "integrate" says, then perhaps you should explain at what point you are getting stuck. Bring code next time.> > I would like to thank you in advance for your help > > Regards > AlexDavid Winsemius, MD West Hartford, CT
I guess what you have is g <- function(x){ 2*x-3 } s <- function(x){ 5*x^2+2 } and what you want is f<-function(x){ g(x)*s(x) } integrate(f,a,b) Try that and see if it works. If not (that is, if your actual g and s are not as in the example), maybe you'll have to do this: integrate(Vectorize(f),a,b) On Thu, Dec 16, 2010 at 10:27 AM, Alaios <alaios@yahoo.com> wrote:> Hello I have two function in R > like > g(x)=2x-3 > and s(x)=5x^2+2 > > and I want to find the integrafl of the g(x)*s(x) inside the interval of > [a,b] > > Could you please help me find the proper function? > > I would like to thank you in advance for your help > > Regards > Alex > > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@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. >[[alternative HTML version deleted]]