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.

The limit definition of the derivative: f’(x)=limh->0 [f(x+h)-f(x)]/h

To calculate this limit we will compute the following two limits and average those results together:

f’(x)=limh->0 [f(x+h)-f(x)]/h

Let h be a very small value, say 0.000001. Once we have the above values we can then average the two limits to get a linear approximation of the actual value of the limit.

derivative.limits <- function(x, h=0.000001){
    
    fx     <- x^3 + 2*x^2
    fxhP <- (x+h)^3 + 2*(x+h)^2
    fxhN <- (x-h)^3 + 2*(x-h)^2
    
    dxp <- (fxhP - fx)/h
    dxn <- (fxhN - fx)/-h
    dx <- (dxp + dxn)/2
    return(dx)
}

derivative.limits(2)
## [1] 20

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 0.000001) and then compute the approximation to the area under the curve.

areaunderCurve <- function(){

    a <- 1
    b <- 3
    deltaX <- 0.000001
    subint <- (b-a)/deltaX 
    # we are dividing the region into subintervals
    area <- 0
    for(i in 1:subint){
        area <- area + (3*a^2 + 4*a)*deltaX 
        # using the above formula
        
        #increment a now by deltaX
        a <- a + deltaX
    }
    return(area)
}

areaunderCurve()
## [1] 41.99998

Please solve these problems analytically (i.e. by working out the math) and submit your answers.

\[\frac{d}{dx} {e^{x^4}} ={e^{x^4}} * 4{x^3}\]