Frage

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

integral_0^a exp(x) = 1/2

I have a rough idea how to do it in matlab. But how would one go about solving this in R?

Thanks for your suggestions.

War es hilfreich?

Lösung

You can use integrate to compute the integral (numerically) and uniroot to 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
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top