[R] problem with input of integrate function
David Winsemius
dwinsemius at comcast.net
Mon Jun 17 04:19:01 CEST 2013
On Jun 16, 2013, at 7:15 PM, David Winsemius wrote:
>
> 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
Can also use '..." argument:
?integrate
integrand <- function(x,a)
{
exp(-0.5*a*(1+x^2))/(1+x^2)
}
integrate(integrand,0,Inf, a=2)
# 0.247085 with absolute error < 3e-05
>
>
>>
>> Thanks in advance.
>>
>> -Cassie
>>
>> [[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.
>
> David Winsemius
> Alameda, CA, USA
>
> ______________________________________________
> 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.
David Winsemius
Alameda, CA, USA
More information about the R-help
mailing list