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.

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

Setup functions f and g

f <- function(x){
  return(2*x^2 + 5*x - 3)
}

g <- function(x){
  return(x^2 + 4*x - 1)
}

Plot

curve(f, -3, 3, col="blue")
curve(g, -3, 3, add=TRUE, col="red")

Determine points of intersection below zero:

a <- uniroot(function(x) f(x) - g(x), c(-5000, -0.01), tol=1e-8)
a$root
## [1] -2

Determine points of intersection abov zero:

a <- uniroot(function(x) f(x) - g(x), c(0.01, 5000), tol=1e-8)
a$root
## [1] 1

Determine area between curve: g minus f for x = -2 to 1.

integrate g(x) from -2 to 1:

gOfx_area <- integrate(g, lower = -2, upper = 1)

integrate f(x) frm -2 to 1:

fOfx_area <- integrate(f, lower = -2, upper = 1)

Get area

gOfx_area$value - fOfx_area$value
## [1] 4.5