Transcript

The Symbolic Toolbox in MATLAB allows you to perform mathematical operations analytically that is, without calculating numeric values. You can differentiate, integrate, simplify the expressions solve equations, take the limits and take a lot of other things. Yes - you can check your assignment solutions too using symbolic toolbox.

In Command Window if I just type sine x, without giving x any value, it's going to give me an error - because x is not first given a value. Now if I type syms x first, which means x is made a symbolic variable and then sine x, MATLAB is going to take it without any error.

So sin x is now a symbolic of x in MATLAB. In fact, any expression which involves x will become a symbolic object. For example, if I type sine x divided by cos x, plus sine x, plus a similar expression (easier to copy and paste). Copy ....plus paste ...and I'll have a minus here. So this is also a symbolic object. I can name it y. Okay. So we can use pretty command to see how this expression will look like when you type set in maths. Yes - that is right.

You can simplify this expression. Just type simplify ...simplify ....and in the bracket y. See - it is simplified. Sine 2x over cos 2x.

There is another command - simple. Let's do that. So simple of y - it does a number of different things. You can explore each line in your own time. But it is at the end the simplest value - tan 2x.

Let us find the limit as x goes to 1 of this expression, using symbolic toolbox limit function. Well this question is from your sample MATLAB test. Let's do it. Okay. In MATLAB, because I have cleared everything, I need to type syms first. syms x. And then I can use limit command and it is the syntax - you need to type the expression and then x goes to whatever a. Okay your function is 4 to the power x minus 1. Then minus 1. And then this whole thing is divided by x squared minus 1 divided by x squared minus 1. Make sure you type the function correction otherwise you get wrong answer.

Ok and we need to find limit when x goes to 1 - so 1 there. And close this bracket. Enter so you get the answer. So the limit is log of 4 divided by 2. But this is a symbolic expression. How to convert this into a decimal number?

There is a command in MATLAB - double. So what it does? It converts symbolic object into a double precision decimal number. Okay, so I am going to use it. So double - we didn't give any name to this variable so it is just ans. double ans. And this converts the answer into a decimal number.

You can differentiate and integrate as well using the symbolic toolbox. So for example let's do this question. Determine the definite integral zero to pi sine x to the power 4 dx. Okay, so in MATLAB again I have cleared everything, so I need to type syms x first. And then for integrating, int, and the function is sine of x, then to the power 4 and it is from zero to pi. Close the bracket and it is integrated. So answer is 3 pi over 8.

We can differentiate as well using symbolic toolbox. Let's do this exercise. So find the second derivative and simplify. And the function is x cubed plus 1 to the power 1 over 3. Let's do it in MATLAB. Ok so syms x is already there and we need to use diff command.

So in the bracket type the expression what ever you have to differentiate. So here it is x cube plus 1 all to the power 1 over 3.

Remember to put 1 over 3 in the bracket otherwise it will be power 1 and the whole thing will be divided by 3 and you will get wrong answer. So if you had to do just first derivative - then you don't need to type anything after that, you just close the bracket and press enter.

But if you have to do the second derivative, just type 2 there and close the bracket, enter - so this is the second derivative. Now you know how to simplify. Just use simplify command - we did not give any name so it is ans so there it is simplified for you.

Last modified: Monday, 10 August 2015, 10:20 AM