f(x) = \(x^{2}\)-3x+2 g(x) = -3x + 3
# create functions f and g
f <- function(x) {x^2-3*x+2}
g <- function(x) {-3*x+3}
# draw both functions f and g
curve(expr=f, from = -3, to = 3)
curve(expr=g, from = -3, to = 3, add = T)
# find lower intersection
rt <- uniroot(function(x) f(x) - g(x) , interval = c(-3,0), tol=0.00001)
rt$root
## [1] -1
# find upper intersection
rt <- uniroot(function(x) f(x) - g(x) , interval = c(0, 3), tol=0.00001)
rt$root
## [1] 1
# f area between -1 and 1
f_area <- integrate(f, lower = -1, upper = 1)
# g area between -1 and 1
g_area <- integrate(g, lower = -1, upper = 1)
# area in between
g_area$value - f_area$value
## [1] 1.333333