Video: Using Brackets (4.01)
Transcript
It is important to understand the use of round brackets in MATLAB. In fact the same rules are followed in MATLAB as in normal Mathematics. That is, the expressions are evaluated from left to right, the power operator
has the highest order of priority multiplication and division, they both have second order of priority Addition and subtraction They both have third order of priority.
And round brackets () can be used to change the order of operations.
Anything enclosed in the bracket will be evaluated first. Let's look at an example. Suppose I have 3 plus 10 divided by, in the round bracket, 2 plus 2 cubed.
What do you think the answer will be? Now this thing is in the bracket - 2 plus 2 cubed, so this will be evaluated first.
So, now 2 cubed is 8, and 8 plus 2 is 10, and then this 10 is divided by this 10 here, so 10 divided by 10 is 1, and 3 plus 1 is equal to 4. So as we expect, if I press Enter in MATLAB, I am getting answer equal to 4. that is right. Okay?
Now, suppose I don't have any bracket here. Suppose I have this expression without any bracket. 3 plus 10 divided by 2 plus 2 cubed. What do you think the answer will be now?
So first order of priority is the power. So 2 cubed is 8. Second order of priority, division 10 divided by 2 is 5.
So what we think we should get? 3 plus 5 plus 8.
Ok, let's see what we get. If I press enter in MATLAB, I got answer is equal to 16.
That is right, this is 3 plus 5 plus 8, equal to 16.
Now finally, I am recalling this same expression, using arrow key. Suppose this 3 plus 10, this whole thing is in
the bracket, and this is divided by this whole bunch, by 2 plus 2 cubed.
What do you think now we should have?
Okay, we go from left to right, but the things in the bracket will be evaluated first, so 3 plus 10 is 13 and 2 plus 2 cubed, as we just calculated should be 2 plus 8 which is 10. So answer should be 13 divided by 10.
Okay, so if I press enter in MATLAB, Yes, that is right, answer is 13 divided by 10 which is 1.3.