Find the total area enclosed by the functions f and g:

\(f(x) = 2x^2 + 5x - 31\), $ g(x) = x^2 + 4x - 1$

Solution

using R to put up functions f and g for the computations:
f <- function(x) {2*x^2+5*x-3}
g <- function(x) {x^2+4*x-1}
curve(f, -3, 3)
curve(g, -3, 3, add=TRUE)

Looking for the value where the point of intersection falls below 0:
(rootF <- uniroot(function(x)  f(x) - g(x)  , c(-5000,-0.01), tol=1e-8)) 
## $root
## [1] -2
## 
## $f.root
## [1] 1.776357e-15
## 
## $iter
## [1] 29
## 
## $init.it
## [1] NA
## 
## $estim.prec
## [1] 8.680272e-09
What is the root of the function:
rootF$root
## [1] -2
Looking for the value where the point of intersection is above 0:
(root0 <- uniroot(function(x)  f(x) - g(x)  , c(0.0001, 5000), tol=1e-8))
## $root
## [1] 1
## 
## $f.root
## [1] 2.112702e-09
## 
## $iter
## [1] 29
## 
## $init.it
## [1] NA
## 
## $estim.prec
## [1] 5.000001e-09
What is the root of the function:
root0$root
## [1] 1

Therefore, the area between the curves will be g minus f at x(-2, 1)

integrating for g
(areaG <- integrate(g, lower = -2, upper = 1))
## -6 with absolute error < 9.9e-14
integrating for f
(areaF <- integrate(f, lower = -2, upper = 1))
## -10.5 with absolute error < 1.4e-13
compute difference between g_area and f_area
areaG$value - areaF$value
## [1] 4.5