Re: [R] numerical integration of a ftn of 2 variables

From: Berend Hasselman <>
Date: Thu, 21 Feb 2008 12:15:54 -0800 (PST)

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:
Sent from the R help mailing list archive at

______________________________________________ mailing list
PLEASE do read the posting guide
and provide commented, minimal, self-contained, reproducible code.
Received on Thu 21 Feb 2008 - 20:31:07 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 Thu 21 Feb 2008 - 21:30:16 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.

list of date sections of archive