Application of Differentiation and Integration

Differentiation and integration are the backbones of the Newtonian calculus. Basically, differentiation at any point gives the slope of any tangent at that point of the corresponding curve. It has several meanings in several domains like in case of chemistry if you are experimenting any physical process then differentiation at any time is denoted as the rate of the process; in any kind of ecological phenomena it represents the growth rate of species etc. The most important point is that all functions are not differentiable. Generally for the existence of the differentiability the function should be smooth i.e. continuous.  

Differentiation is used in many many domains. With the help of this method you can elaborate many natural procedures. In case of C/C++ language it is very difficult to execute the differentiation of any expression but in the R software it is nothing but a work of twinkle of eye. The following codes will give the illustration:

#### Differentiate the expression x^3


differentiation = D(expression(x^3), "x")

differentiation


#### Look at the output and check whether it is 3*x^2 is not

### You can also enumerate repeat the differentiation multiple times by just repeating the previous    command


2nd.order.differentiation = D(D(expression(x^3), "x"), "x") 


### But if you wish to repeat this process upto nth times (say for n = 100) 

### then it will be quite laborious. 

### In order to get rid of those issue we have to follow some functional approach


multiple.differetiation = function(expr, name, order) {

  if(order < 1) stop("'order' must be >= 1")

  if(order == 1) D(expr, name)

  else multiple.differetiation(D(expr, name), name, order-1)

}

multiple.differetiation(expression(x^3), "x", 3)


#### Similarly we can also perform the partial differentiation too

#### As we know that in case of many situation like state space model, fluid dynamics, jacobian 

### formation, etc. Partial differentiation is very much essential tool. 


partial.differentiation = D(expression(x^2*y), "y")

partial.differentiation


### Similarly for multiple times partial differentiation we can execute the codes as mentioned above


In a similar manner we can also execute the integration in R software but the problem is that, we can't execute any indefinite integration. You can say that it is a limitation of R software. Now, in the following the code for numerical integration is provided

## In order to perform any definite integration you have to construct the integrand first


integrand = function(x) x^2

result = integrate(integrand, lower = 0, upper = 2)


### Look at the output, it consists of the value with some error

value = result$value

### Verification of the area under the curve

integrate(dnorm, lower = -Inf, upper = Inf)$value