- x.values <- seq(-2, 2, by = 0.1)
- x <- x.values
- y.values <- ifelse(x <= 0, -x^3, ifelse(x <= 1, x^2, sqrt(x)))
- plot(x.values, y.values, type = "l")
- x.values <- seq(-2, 2, by = 0.1)
- x <- x.values
- y.values <- ifelse(x <= 0, -x^3, ifelse(x <= 1, x^2, x^(1/2)))
- plot(x.values, y.values, type = "l")
上面的代码,用sqrt会有警告信息:
Warning message:In sqrt(x) : NaNs produced
用^(1/2)不会,不知道为何?