

Dear Rusers,
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/rhelpPLEASE do read the posting guide http://www.Rproject.org/postingguide.htmland provide commented, minimal, selfcontained, reproducible code.


On Jun 16, 2013, at 6:46 PM, cassie jones wrote:
> Dear Rusers,
>
> 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 < 3e05
David Winsemius
Alameda, CA, USA
______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/rhelpPLEASE do read the posting guide http://www.Rproject.org/postingguide.htmland provide commented, minimal, selfcontained, reproducible code.


On Jun 16, 2013, at 7:15 PM, David Winsemius wrote:
>
> On Jun 16, 2013, at 6:46 PM, cassie jones wrote:
>
>> Dear Rusers,
>>
>> 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 < 3e05
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 < 3e05
David Winsemius
Alameda, CA, USA
______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/rhelpPLEASE do read the posting guide http://www.Rproject.org/postingguide.htmland provide commented, minimal, selfcontained, reproducible code.


Hi David,
Thank you so much.
Cassie
On Sun, Jun 16, 2013 at 9:19 PM, David Winsemius < [hidden email]>wrote:
>
> On Jun 16, 2013, at 7:15 PM, David Winsemius wrote:
>
> >
> > On Jun 16, 2013, at 6:46 PM, cassie jones wrote:
> >
> >> Dear Rusers,
> >>
> >> 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 < 3e05
>
> 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 < 3e05
> >
> >
> >>
> >> Thanks in advance.
> >>
> >> Cassie
> >>
> >> [[alternative HTML version deleted]]
> >>
> >> ______________________________________________
> >> [hidden email] mailing list
> >> https://stat.ethz.ch/mailman/listinfo/rhelp> >> PLEASE do read the posting guide
> http://www.Rproject.org/postingguide.html> >> and provide commented, minimal, selfcontained, reproducible code.
> >
> > David Winsemius
> > Alameda, CA, USA
> >
> > ______________________________________________
> > [hidden email] mailing list
> > https://stat.ethz.ch/mailman/listinfo/rhelp> > PLEASE do read the posting guide
> http://www.Rproject.org/postingguide.html> > and provide commented, minimal, selfcontained, reproducible code.
>
> David Winsemius
> Alameda, CA, USA
>
>
[[alternative HTML version deleted]]
______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/rhelpPLEASE do read the posting guide http://www.Rproject.org/postingguide.htmland provide commented, minimal, selfcontained, reproducible code.

