Problem 7.1.11:
Find the total area enclosed by the functions f and g.
f(x) = 2x^2 + 5x - 3
g(x) = x^2 + 4x - 1
f <- function(x){
return(2*x^2 + 5*x - 3)
}
g <- function(x){
return(x^2 + 4*x - 1)
}
curve(f, -3, 3, col="blue")
curve(g, -3, 3, add=TRUE, col="red")
a <- uniroot(function(x) f(x) - g(x), c(-5000, -0.01), tol=1e-8)
a$root
## [1] -2
a <- uniroot(function(x) f(x) - g(x), c(0.01, 5000), tol=1e-8)
a$root
## [1] 1
gOfx_area <- integrate(g, lower = -2, upper = 1)
fOfx_area <- integrate(f, lower = -2, upper = 1)
gOfx_area$value - fOfx_area$value
## [1] 4.5