I am trying to perform direct integration, but I have a problem that (I think) is related to the form in which I write the integrand.
Suppose I want to find the area connected by f (x) = 3x and g (x) = x ^ 2. Geometrically, the area between the two curves:

Well, therefore, you should not analyze analytically:

But I would like to do it with R, of course.
So, I introduce my function and there is the problem:
> g <- function(x) {3x-x^2} Error: unexpected symbol in "g <- function(x) {3x"
It upset me, and I started playing with things. Interestingly, I found that if I expose x from the integrand:

everything works smoothly:
> f <- function(x) {x*(3-x)} > integrate(f, 0, 3) 4.5 with absolute error < 5e-14
My next step was to check for ?integrate , part of which is attached below:
integrate (f, lower, upper, ..., subdivisions = 100L, rel.tol = .Machine $ double.eps ^ 0.25, abs.tol = rel.tol, stop.on.error = TRUE, keep.xy = FALSE , aux = NULL) Arguments
e
a function R that takes a numeric first argument and returns a numeric vector of the same length. Returning a non-final item will result in an error.
lower, upper - the limits of integration. May be infinite.
Am I somehow not accepting the numeric first argument in my first attempt to integrate? Thanks in advance.