[R] numerical integration of a ftn of 2 variables

Berend Hasselman bhh at xs4all.nl
Thu Feb 21 21:15:54 CET 2008



Chris Rhoads wrote:
> 
> 
> I wish to find the root of a function of two variables that is defined by
> an integral which must be 
> evaluated numerically.
> 
> So the problem I want to solve is of the form:  Find k such that f(k)=0,
> where f(y) = int_a^b
> g(x,y) dx.  Again, the integral
> involved must be done numerically.
> 
> 

g <- function(x,p) 2*(x-p)

Find value of p such that integral_0^1 g(x,p)dx  is zero

f <- function(p) integrate(g,0,1,p)$value

uniroot(f, c(0,1))

$root should be 0.5 which is what is expected here.

Berend Hasselman
-- 
View this message in context: http://www.nabble.com/numerical-integration-of-a-ftn-of-2-variables-tp15578652p15618830.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list