Chapter 7.1 Exercise 6

Find the are of the shaded region in the given graph.

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

\(g(x) = x^2 + x -1\)

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

curve(f, xlim = c(-1,1), ylim = c(-2,4), ylab='')
curve(g, add = T)
abline(v=0, h=0, col = 'grey')
abline(v=-1, col = 'blue', lty=3)
abline(v=1, col = 'blue', lty=3)

\(\int_{-1}^{1} (f(x) - g(x)) dx\)

\(\int_{-1}^{1} ((3x^3 + 3x + 2) - (x^2 + x -1)) dx\)

\(\int_{-1}^{1} (3x^3 - x^2 + 2x + 3) dx\)

solution v1

library(mosaicCalc)
ad <- antiD(3 * x^3 - x^2 + 2 * x + 3 ~ x)

print(ad)
## function (x, C = 0) 
## 3/4 * x^4 - 1/3 * x^3 + 1 * x^2 + 3 * x + C
ad(1) - ad(-1)
## [1] 5.333333

v2

y <- function(x) {3 * x^3 - x^2 + 2 * x + 3}

p <- integrate(y,-1,1)
p
## 5.333333 with absolute error < 6.8e-14