I am trying to compute the approximate numerical integration of the following
expression using the integrate function:


>       (integrate(function(x) {log(1+x^2)*(1+x^2)^(-20.04543)},low,Inf)$val)
Error in integrate(function(x) { : the integral is probably divergent


which gives me an error.  If this error happens I want to return the
following instead

> (area(function(x) {-2*log(cos(x))*(cos(x)^(2*e-2))}, atan(low), pi/2))
[1] 0.01045636

In order to accomplish this I tried the following:

> this= tryCatch((integrate(function(x)
> {log(1+x^2)*(1+x^2)^(-e)},low,Inf)$val),error=function(e) e, finally =
> (area(function(x) {-2*log(cos(x))*(cos(x)^(2*e-2))}, atan(low), pi/2)))
> this
<simpleError in integrate(function(x) {    log(1 + x^2) * (1 + x^2)^(-e)},
low, Inf): the integral is probably divergent>

Perhaps I am using tryCatch incorrectly? Any help would be greatly
appreciated.

--
View this message in context: 
http://r.789695.n4.nabble.com/tryCatch-with-integration-tp3954528p3954528.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
R-help@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.

Reply via email to