Question 18

Find the total area enclosed by the functons f and g.

\(f(x)=-x^3+5x^2+2x+1\)

\(g(x)=3x^2+x+3\)

Plot the functions

Based on the graph below, there are two areas enclosed by the function.

library(ggplot2)

x_values <- seq(-2,3, by = 0.1)

f <- function(x) -x^3 + 5*x^2 +2*x+1
g <- function(x) 3*x^2+x+3

data <- data.frame(x = x_values, f = f(x_values), g = g(x_values))

ggplot(data, aes(x = x)) + 
  geom_line(aes(y = f), color = "blue", size = 1, linetype = "solid") + 
  geom_line(aes(y = g), color = "green", size = 1, linetype = "solid") + theme_minimal() + geom_ribbon(aes( ymin=pmin(f,g), ymax = pmax(f,g)), fill="gray")
## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## ℹ Please use `linewidth` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.

Find the Point of Intersections

Area 1 (Left most)

For area 1, \(g(x) \geq f(x)\)

\(Area_{1} = \int_{a}^{b} [g(x) - f(x)]dx\)

The lower bound is about -1.

root <- uniroot(function(x) g(x)-f(x), c(-10, 0))
root$root
## [1] -1.000001

The lower bound is about 1.

root <- uniroot(function(x) g(x)-f(x), c(0, 1.5))
root$root
## [1] 1.00001

Area 2 (Right most)

For area 1, \(f(x) \geq g(x)\)

\(Area_{2} = \int_{a}^{b} [f(x) - g(x)] dx\)

The lower bound is about -1.

root <- uniroot(function(x) f(x)-g(x), c(0, 1.5))
root$root
## [1] 1.00001

The lower bound is about 2.

root <- uniroot(function(x) f(x)-g(x), c(1.1, 5))
root$root
## [1] 1.999994

Area

R Solution

\(Total \; Area = Area_{1} +Area_{2}\) \(Total \; Area = \int_{-1}^{1} [g(x) - f(x)] dx + \int_{1}^{2} [f(x) - g(x)] dx\)

Area1 <- integrate(function(x) g(x)-f(x), lower = -1, upper = 1 )
Area2 <- integrate(function(x) f(x)-g(x), lower = 1, upper = 2 )

Area1$value + Area2$value 
## [1] 3.083333

Calulation By Hand

\(f(x)=-x^3+5x^2+2x+1\)

\(g(x)=3x^2+x+3\)

\(Total \; Area = \int_{-1}^{1} [(3x^2+x+3) - (-x^3+5x^2+2x+1)] dx + \int_{1}^{2} [(-x^3+5x^2+2x+1) - (3x^2+x+3) ] dx\)

\(Total \; Area = \int_{-1}^{1} [x^3-2x^2-x+2)] dx + \int_{1}^{2} [-x^3+2x^2+x-2 ] dx\)

\(Total \; Area = [\frac{x^4}{4}-\frac{2x^3}{3}-\frac{x^2}{2}+2x)]_{-1}^{1} + [-\frac{x^4}{4}+\frac{2x^3}{3}+\frac{x^2}{2}-2x ]_{1}^{2}\)

\(Total \; Area = [(\frac{1^4}{4}-\frac{2(1)^3}{3}-\frac{1^2}{2}+2(1))-(\frac{(-1)^4}{4}-\frac{2(-1)^3}{3}-\frac{(-1)^2}{2}+2(-1))] +[(-\frac{2^4}{4}+\frac{2(2)^3}{3}+\frac{2^2}{2}-2(2))-(-\frac{1^4}{4}+\frac{2(1)^3}{3}+\frac{1^2}{2}-2(1))]\)

\(Total \; Area = [(\frac{1}{4}-\frac{2}{3}-\frac{1}{2}+2)-(\frac{1}{4}+\frac{2}{3}-\frac{1}{2}-2] +[(-\frac{16}{4}+\frac{16}{3}+\frac{4}{2}-4-(-\frac{1}{4}+\frac{2}{3}+\frac{1}{2}-2 ]\)

\(Total \; Area = \frac{8}{3} + \frac{5}{12}= \frac{37}{12}\)

37/12
## [1] 3.083333