Solution for the unknown upper bound of the integral

I am trying to implement an algorithm in R, which includes a solution for the boundary limit of an integral. For example, I want to find a, given the following integral:

integral_0^a exp(x) = 1/2

I have a general idea of ​​how to do this matlab. But how would you solve this in R?

Thanks for your suggestions.

+3
source share
1 answer

You can use integrateto calculate the integral (numerical) and unirootto solve the equation (numerically).

f <- function(a) integrate( exp, 0, a )$value - 1/2
uniroot( f, c(-1, 1) ) # Look for a solution in [-1,1]
log(3/2) # Compare with the exact solution
+5
source

All Articles