[R] Integral implicit function

From: Eddy H. G. Bekkers <ebekkers_at_few.eur.nl>
Date: Thu, 6 Dec 2007 22:45:07 +0100


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. Received on Thu 06 Dec 2007 - 21:48:22 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 10 Dec 2007 - 20:30:18 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.