[R] NaN not expected

Thiem Alrik thiem at sipo.gess.ethz.ch
Fri Dec 17 17:40:34 CET 2010


Dear mailing list,

Why does the following code produce numerical results for x.pos.l, but NaNs for x.neg.l?

x.pos <- function(tau.e, tau.c){
  tau.e + ((-tau.e^3 + 3*tau.e^2*tau.c - 
  3*tau.e*tau.c^2 + tau.c^3)^(1/3))/(2*2^(1/3))
}
(x.pos.l <- x.pos(1, 2))

x.neg <- function(tau.c, tau.i){
  tau.i + ((tau.c^3 - 3*tau.c^2*tau.i + 
  3*tau.c*tau.i^2 - tau.i^3)^(1/3))/(2*2^(1/3))
}
(x.neg.l <- x.neg(2, 3))

Many thanks for help,

Alrik



More information about the R-help mailing list