[R] integral in R

Christos Argyropoulos argchris at hotmail.com
Tue Jul 20 00:37:02 CEST 2010



I'm not really sure I understand the question. Do you want to create a function, which is defined as the integral of another function? 
Something like:

> f1<-function(x) sin(x)
> f2<-function(x) cos(x)
> 
> integral<-function(u,integrand) integrate(integrand,0,u)
> 
> integral(pi,f1)
2 with absolute error < 2.2e-14
> integral(pi,f2)
1.363722e-16 with absolute error < 2.2e-14
> 

should do the trick if this is what you want. If you are going to use your own "integrand" function make sure it is vectorized.

Christos

----------------------------------------
> Date: Mon, 19 Jul 2010 17:59:36 -0300
> From: ncgmsanches at gmail.com
> To: r-help at r-project.org
> Subject: [R] integral in R
>
> Hello All,
>
> I have to create a variable that is a function of another one (already
> created), its cumulative distribution function and the integral of this
> cumulative distribution, with limits: 0 and the value of the variable.
>
> To be clear, I have the variable called “cip”. And its cdf called “cdfcip”
>
> I need to create the variable:
>
> bip = cip + ((1 – cdfcip)^4)*integral((1-cdf(u))^4*du, 0, value of the
> variable cip)
>
> The problem: I don’t know how to do this integral. It is like a integral of
> ((1 – F(u))^4*du with limits 0 and a value c of individual i in case p of
> the variable cip.
>
> Does anybody knows how to do it? Am I clear with the question?
>
[[elided Hotmail spam]]
>
> Nathalie
>
> [[alternative HTML version deleted]]
>
 		 	   		  
_________________________________________________________________
Hotmail: Powerful Free email with security by Microsoft.



More information about the R-help mailing list