Working with integration in R
Recall that differentiation is performed using the D()
function. Assuming y = A x 2 + Bx + 3, we have y ′ = f′(x) = 2Ax + B. We can plot the raw function f(x) and its derivative function f′(x) to facilitate the comparison.
In the following code snippet, we create this expression using the makeFun()
function and name the function f
:
f = makeFun( A*x^2 + B*x + 3 ~ x) >>> f function (x, A, B) A * x^2 + B * x + 3
We can do a simple evaluation as follows:
>>> f(1, A=1, B=1) 5
Now, we obtain the derivative function and store the function in f_prime
:
f_prime = D(f(x) ~ x) >>> f_prime function (x, A, B) 2 * A * x + B
This is a new function derived from the original function. We also do a simple evaluation for this function, as follows:
>>> f_prime(x=1, A=1, B=1) 3
Now, let us plot the raw function f(x) = x 2 + x + 3:
>>> slice_plot(f(x) ~ x, domain...