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.

I chose the Problem 7.1.11:

In Exercises 11-16, find the total area enclosed by the functions \(f\) and \(g\).

\(11. f(x) = 2x^2 + 5x -3, g(x) = x^2 + 4x -1\)

# create functions f and g
f <- function(x) {2*x^2+5*x-3}
g <- function(x) {x^2+4*x-1}
# plot to visualize
curve(f, -3, 3)
curve(g, -3, 3, add=TRUE)

# confirm points of intersection
# intersection where x below zero is -2:
rt <- uniroot(function(x)  f(x) - g(x)  , c(-5000,-0.01), tol=1e-8) 
rt$root
## [1] -2
# intersection where x above zero is 1:
rt <- uniroot(function(x)  f(x) - g(x)  , c(0.0001, 5000), tol=1e-8) 
rt$root
## [1] 1
# area between curves is g minus f for x = -2 to 1
# integrate g
g_area <- integrate(g, lower = -2, upper = 1)
# integrate f
f_area <- integrate(f, lower = -2, upper = 1)
# compute difference between g_area and f_area
g_area$value - f_area$value
## [1] 4.5