Write a program to compute the derivative of \(f(x) = x^3 + 2x^2\) at any value of \(x\). Your function should take in a value of \(x\) and return back an approximation to the derivative of \(f(x)\) evaluated at that value. You should not use the analytical form of the derivative to compute it. Instead, you should compute this approximation using limits.
Now, write a program to compute the area under the curve for the function \(3x^2+4x\) in the range \(x = [1, 3]\). You should first split the range into many small intervals using some really small \(???x\) value (say \(1e-6\)) and then compute the approximation to the area under the curve.
Please solve these problems analytically (i.e. by working out the math) and submit your answers.
Use integration by parts to solve for \(\int sin(x)cos(x)dx\)
Use integration by parts to solve for \(\int x^2e^xdx\)
What is \(\frac{d}{dx}(x cos(x))\)?
What is \(\frac{d}{dx}({e^x}^4)\)?
my_drivative <- function(x){
driv <- ((x+1e-5)^3 + 2*(x+1e-5)^2 - x^3 - 2*x^2)/1e-5
driv <- round(driv,0)
return(driv)
}
my_drivative(1)
## [1] 7
my_drivative(5)
## [1] 95
my_drivative(10)
## [1] 340
# split the range into many small intervals
x <- seq(1, 3, by=1e-6)
# function
f <- 3*(x^2) + 4*x
area <- f*(1e-6)
sum(area)
## [1] 42.00002
\(\int sin(x)cos(x)dx\)
let, \(u = cos(x)\)
\(du = -sin(x)dx\)
\(dx = \frac{du}{-sin(x)}\)
\(\int sin(x) u \frac{du}{-sinx}\)
\(=-\frac{1}{2}udu\)
\(=-\frac{1}{2}u^2\)
\(=-\frac{1}{2}cos^2x + c\)
\(\int x^2e^xdx\)
We know, \(\int fg'dx = fg - \int f'gdx\)
If \(f = x^2\), then, \(f' = 2x\), if \(g = e^x\) then \(g' = e^x\)
\(\int x^2e^xdx\)
\(= x^2e^x - 2\int xe^xdx\)
(we will perform another integration by parts for \(\int xe^xdx\) where \(f(x) = x, f'(x) = 1, g(x) = e^x. g'(x) = e^x\))
\(= x^2e^x - 2(xe^x - \int e^xdx)\)
\(= x^2e^x - 2(xe^x-e^x) + C\)
\(= x^2e^x-2xe^x + 2e^x + C\)
\(\frac{d}{dx}(xcos(x))\)
\(= x(-sin(x)) + cos(x)(1)\)
\(= - xsin(x) + cos(x)\)
\(\frac{d}{dx}(e^{x^{4}})\)
\(= e^{x^{4}}.\frac{d}{dx}[x^{4}]\)
\(4x^3{e^x}^4\)