## Symbolic Integration and Differentiation using MATLAB

While messing with MATLAB during free time I have found the method (thanks to MATLAB documentation) of performing symbolic integration and differentiation using MATLAB. And also the proper way to display a function in MATLAB command line. In this small article I am going to share my experience on symbolic integration and differentiation using MATLAB.

### Representing a function as reader friendly format

Take an example function f(x) as,

We can input our function to MATLAB as follows.

You can clearly see that ‘x’ is a symbolic object and f(x) is a symbolic function. Say If you need to evaluate f(x) at x = 10; that is f(10) then it’s simply;

However this equation and answer representation is bit annoying. Therefore by using the command * ‘pretty’ *we can display this in more readable format in MATLAB command line.

Now let’s have a look how the symbolic differentiation is performed.

### Symbolic Differentiation

The MATLAB function * ‘diff’ *is used for performing symbolic differentiation and the function format is as follows.

g(x) = diff(f(x),variable in interest, order of derivative);

Consider the following example.

Now say you need to evaluate first derivative of f(x) at x = 5; then It can be calculated as follows.

### Symbolic Integration

Command format we use is* ‘int’* and the format is as follows.

g(x) = int(f(x),integrate on); %gives you symbolic result g(x) = int(f(x),integrate on, from, to); % gives you the integral

Consider the following example.

There is another function named ‘integral’ to perform the numerical integration using MATLAB. And it has two variations named ‘* integral2’* and

*for 2D and 3D integration as well. You can use MATLAB documentation to obtain clear idea how does it work.*

**‘integral3’**At this point I conclude my short article on ‘Symbolic Integration and Differentiation using MATLAB’. Hope you got some basic idea about it from this article. Thank you very much for reading.

No comments yet.

## Leave a Reply