[R] Integral implicit function

Peter Ruckdeschel Peter.Ruckdeschel at uni-bayreuth.de
Mon Dec 10 21:04:46 CET 2007


Have you tried vectorizing the inner function? 
Hint: integrate() calls the integrand vectorwise... 
in your example,
      integrate(Vectorize(f),lower=1,upper=2)
should do what you expected.

Best,
Peter


Eddy H. G. Bekkers wrote:
> 
> Hi,
> 
> Could somebody help me with the following. I want to calculate the
> integral over an implicit function. I thought to integrate over a function
> depending on uniroot. In previous topics I found a thread about finding
> the root of an integral. And that works. But the other way around, does
> not work. Does R support this?
> 
> I included the following example. The function in the example is very easy
> and can be solved explicitly, but when it does not work for such an easy
> function it will certainly not work for a more difficult function. First
> the root of an integral (which works) and then the integral of a function
> dependent on uniroot:
> 
> # Calculating the root of an integral
> 
> a<- function(x,y)
>     {x-y}
> 
> b<- function(y)
>     {integrate(a,lower=1,upper=2,y=y)$value}
> 
> d<- uniroot(b,c(0,10))$root
> 
> print(d)
> 
> # Calculating the integral of a function dependent on uniroot
> 
> e<- function(u,v)
>     {u-v}
> 
> f<- function(v)
>     {uniroot(e,c(0,10),v=v)$root}
> 
> g<- integrate(f,lower=1,upper=2)$value
> 
> print(g)
> 
> Does anyone have suggestions how to proceed? By the way, the implicit
> function I am targeting does have a unique solution, it is only not
> explicitly solvable, i.e. in the example above, you cannot solve u as a
> function of v explicitly, so as to substitute it in the integrand. 
> 
> 
> Thanks a lot in advance for your help,
> 
> Best regards,
> 
> Eddy Bekkers
> Department of Economics
> Erasmus University Rotterdam
> 
> ______________________________________________
> 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.
> 
> 

-- 
View this message in context: http://www.nabble.com/Integral-implicit-function-tp14201932p14260535.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list