# problem with input of integrate function

4 messages
Open this post in threaded view
|

## problem with input of integrate function

 Dear R-users, I am trying to integrate a function using integrate command in R. The function is as follows, integrand function(x,a)  {  exp(-0.5*a*(1+x^2))/(1+x^2)  } Now while I want to integrate it using the command integrate, I get the following error, integrate(integrand(x,2),0,inf) Error in match.fun(f) :   'integrand(x, 2)' is not a function, character or symbol I understand that the argument of integrate needs to be solely dependent on x, that is why it is not able to recognize the input as there are both x and a. But I need to have the integrand dependent on the variable a. Does anyone know how can I handle the problem? Any help is appreciated. Thanks in advance. -Cassie         [[alternative HTML version deleted]] ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|

## Re: problem with input of integrate function

 On Jun 16, 2013, at 6:46 PM, cassie jones wrote: > Dear R-users, > > I am trying to integrate a function using integrate command in R. > The function is as follows, > > integrand > function(x,a) > { > exp(-0.5*a*(1+x^2))/(1+x^2) > } > > Now while I want to integrate it using the command integrate, I get the > following error, > > integrate(integrand(x,2),0,inf) > > Error in match.fun(f) : >  'integrand(x, 2)' is not a function, character or symbol > > I understand that the argument of integrate needs to be solely dependent on > x, that is why it is not able to recognize the input as there are both x > and a. But I need to have the integrand dependent on the variable a. Does > anyone know how can I handle the problem? Any help is appreciated. You also misspelled `Inf` > integrand <- function(x,a=2) + { + exp(-0.5*a*(1+x^2))/(1+x^2) + } > > integrate(integrand,0,Inf) 0.247085 with absolute error < 3e-05 > > Thanks in advance. > > -Cassie > > [[alternative HTML version deleted]] > > ______________________________________________ > [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. David Winsemius Alameda, CA, USA ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.