Using R, provide the solution for any exercise in either Chapter 4 or Chapter 7 of the calculus textbook. If you are unsure of your solution, post your concerns.
In Exercises 11 – 16, find the total area enclosed by the functions f and g. Exercise 12:
\(f(x) = x^2 − 3x + 2\), \(g(x) = −3x + 3\)
#f(x)
f <- function(x) {x^2 - 3*x + 2}
#g(x)
g <- function(x) {-3*x + 3}
#visualize the both functions
curve(f, -2, 4)
curve(g, -2, 4, add=TRUE)
# find intersection point of each function
# intersection where x below zero is -1:
r <- uniroot(function(x) f(x) - g(x) , c(-10000,-0.001), tol=1e-8)
r$root
## [1] -1
# intersection where x above zero is 1:
r <- uniroot(function(x) f(x) - g(x) , c(0.001, 10000), tol=1e-8)
r$root
## [1] 1
# area = g-f for x = 1 to 1
# integrate g
area.g <- integrate(g, lower = -1, upper = 1)
# integrate f
area.f <- integrate(f, lower = -1, upper = 1)
# compute difference between the areas
area.g$value - area.f$value
## [1] 1.333333