Tonja Krueger
2010-Sep-14 07:15 UTC
[R] solve integrate(,..) varying limits of integration
Dear List, Is there a way to solve integrate(func.1,x, Inf) $value =0.05 by varying the lower limit of integration (x in the example above)? So far I got: r<- 0.730163 s<--2 func.1<- function(t) {1/(2*pi*sqrt(1-r^2))*exp(-1/(2*(1-r^2))*(s^2-2*r*s*t+t^2))} I can change the lower limit manually, like: integrate(func.1, -2.5, Inf) $value [1] 0.05053265 integrate(func.1, -2.4, Inf) $value [1] 0.04942731 integrate(func.1, -2.45, Inf) $value [1] 0.05000923 but this is very time-consuming. So I was wondering if there is a better, preferably an automated way to solve the equation? Thanks, Tonja ___________________________________________________________ Neu: WEB.DE De-Mail - Einfach wie E-Mail, sicher wie ein Brief! Jetzt De-Mail-Adresse reservieren: https://produkte.web.de/go/demail02
Dimitris Rizopoulos
2010-Sep-14 07:39 UTC
[R] solve integrate(,..) varying limits of integration
have a look at uniroot(), e.g., ff <- function (low, r, s) { f <- function (t, r, s) { exp(-(s^2 - 2*r*s*t + t^2) / (2*(1-r^2))) / (2*pi*sqrt(1-r^2)) } integrate(f, low, Inf, r = r, s = s)$value - 0.05 } uniroot(ff, c(-3, -2), r = 0.730163, s = -2)$root I hope it helps. Best, Dimitris On 9/14/2010 9:15 AM, Tonja Krueger wrote:> Dear List, > Is there a way to solve > > integrate(func.1,x, Inf) $value =0.05 > > by varying the lower limit of integration (x in the example above)? > So far I got: > > r<- 0.730163 > s<--2 > func.1<- function(t) {1/(2*pi*sqrt(1-r^2))*exp(-1/(2*(1-r^2))*(s^2-2*r*s*t+t^2))} > > I can change the lower limit manually, like: > > integrate(func.1, -2.5, Inf) $value > [1] 0.05053265 > integrate(func.1, -2.4, Inf) $value > [1] 0.04942731 > integrate(func.1, -2.45, Inf) $value > [1] 0.05000923 > > but this is very time-consuming. So I was wondering if there is a better, preferably an automated way to solve the equation? > > Thanks, > Tonja > ___________________________________________________________ > Neu: WEB.DE De-Mail - Einfach wie E-Mail, sicher wie ein Brief! > Jetzt De-Mail-Adresse reservieren: https://produkte.web.de/go/demail02 > > ______________________________________________ > 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. >-- Dimitris Rizopoulos Assistant Professor Department of Biostatistics Erasmus University Medical Center Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands Tel: +31/(0)10/7043478 Fax: +31/(0)10/7043014