Re: [R] Solve an equation including integral

2016-01-08 Thread Berend Hasselman
> On 8 Jan 2016, at 17:47, Ravi Varadhan wrote: > > There was a mistake in the previously sent function. I had hard coded the > values of parameters `nu' and `exi'. > > Use this one: > > myroot <- function(t, nu, exi, alpha){ > fun <- function(t, exi, nu) > (nu+t^2)^(-(nu+1)/2)*exp(((nu+1)

Re: [R] Solve an equation including integral

2016-01-08 Thread Ravi Varadhan
There was a mistake in the previously sent function. I had hard coded the values of parameters `nu' and `exi'. Use this one: myroot <- function(t, nu, exi, alpha){ fun <- function(t, exi, nu) (nu+t^2)^(-(nu+1)/2)*exp(((nu+1)*exi*t)/((nu+t^2)^0.5)) res <- alpha - integrate(fun, -Inf, t, nu=

Re: [R] Solve an equation including integral

2016-01-08 Thread Ravi Varadhan
I think this is what you want: myroot <- function(t, nu, exi, alpha){ fun <- function(t, exi, nu) (nu+t^2)^(-(nu+1)/2)*exp(((nu+1)*exi*t)/((nu+t^2)^0.5)) res <- alpha - integrate(fun, -Inf, t, nu=2, exi=0.5)$value return(res) } uniroot(myroot, c(-2, 2), nu=2, exi=0.5, alpha=.05) Hope this