근 찾기
x <- seq(-5, 5, by = 0.01)
f.x.1 <- x/sqrt(x^2 + 1)
f.x.2 <- x^4 - x
plot(x, f.x.1, type = "l", xlim = c(-1, 2), ylim = c(-2, 2), ylab ="")
lines(x, f.x.2)
which(abs(f.x.1 - f.x.2) <= 0.1)
## [1] 496 497 498 499 500 501 502 503 504 505 506 618 619 620
which(abs(f.x.1 - f.x.2) <= 0.01)
## [1] 501 619
x[which(abs(f.x.1 - f.x.2) <= 0.01)]
## [1] 0.00 1.18
적분을 근사시키기
x.r <- runif(1000, 0, 1.18)
f.x <- function(x) {x/sqrt(x^2 + 1) - (x^4 - x)}
y <- f.x(x.r)
mean(y)*1.18
## [1] 0.7746057
x.r.2 <- runif(100000, 0, 1.18)
y <- f.x(x.r.2)
mean(y)*1.18
## [1] 0.7866919