그래프 그리기ㄱ
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", ylab ="")
plot(x, f.x.1, type = "l", xlim = c(-1, 2), ylim = c(-2, 2), ylab ="")
lines(x, f.x.2)
abline(h = 0, v = 0, lty = 3)
근 찾기
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
(index.min <-which(abs(f.x.1 - f.x.2) <= 0.01))
## [1] 501 619
x[index.min]
## [1] 0.00 1.18
# x[which(abs(f.x.1 - f.x.2) <= 0.01)]
적분을 근사시키기
x.r <- runif(1000, 0, 1.18)
hist(x.r, prob = TRUE)
f.x <- function(x) {x/sqrt(x^2 + 1) - (x^4 - x)}
y <- f.x(x.r)
mean(y)*1.18
## [1] 0.7904891
sd(y)
## [1] 0.3143315
x.r.2 <- runif(100000, 0, 1.18)
hist(x.r.2, prob = TRUE, breaks = seq(0, 1.18, by = 0.02))
y <- f.x(x.r.2)
mean(y)*1.18
## [1] 0.787255
sd(y)
## [1] 0.3156908