Video: Built-in Functions (7.04)

 

Transcript

There are several built in functions in MATLAB. Automatic functions like square root, remainder; trigonometric functions like sine, cosine, tangent and inverses, sine inverse, cos inverse, tan inverse; and then exponential and logarithmic functions and so on.

 

We can also run these functions in the Command Window. Let's begin with a simple example, say round.

So if I type in the Command Window, r-o-u-n-d, round, and in the brackets a number, say..3.7. What it will do? It should round the number to the nearest integer. The nearest integer to 3.7 is 4. So if I press enter in MATLAB, it will give me answer 4.

 

Similarly there is another function which is called floor, f-l-double-o-r. So if I enter a number in the bracket, say 3.7, what do you suppose it will do? The floor function will round down to the nearest integer. So rounding down to the nearest integer means it should be giving answer equal to 3.

 

Similarly there is another function which is called c-e-i-l ceil. This is just opposite of floor function, so it will round up to the nearest integer. So if I type in the bracket a number, say 3.7 again, answer will be 4, rounding up this time.

 

Another useful built in function is rem. The Remainder function. Suppose I want to know what will be the remainder, if I divided 27 by 4.

 

Then I can use rem function, r-e-m. How should I type it in MATLAB? So I am dividing 27 by 4, so I will write 27 first, and then comma and then 4 and close the bracket. You might be noticing there is a little help popping up. That tells you the correct syntax. Okay. I am closing the bracket. When I press enter,  it gives me answer 3. So 3 is the remainder when you divide 27 by 4. Okay. Some of us might be tempted to type rem 27 by 4, like 27 slash 4, because 27 is being divided by 4 - but this is not the correct syntax. See what you get. If you press enter you are getting error - not enough input arguments. So syntax is really important in MATLAB.

 

Okay, so always there is a little instant help available, like when you type r-e-m and just one bracket, and you will see this small window pops up. It tells you about - there should be two inputs, x and y separated by a comma, so yes. And if you want to know more about it, you can click on More Help, and you can see the syntax there, and there is a little description about the function and some more tips and some relevant functions etc. Okay so help is always available in MATLAB.

 

There are a couple of other ways to find help in MATLAB. Suppose you want to know about trigonometric function, sine? Then in the Command Window you will type help sine and press enter. Then you can see some help about sine function. It tells you that argument of sine should be in radians, so x should be in radians and this is the syntax of the sine of something, well that something should be in brackets. Ok and there are some related functions suggested related functions and also there is a document about sin. If you click in doc sin a window pops up and you can see the syntax of sine, a little description about it and there is a graph as well and suggested functions which are related to sine. Okay.

 

There is another way to find help. Suppose you don't know the name of function, you don't know the exact name or command, then there is a little question mark in the top you can click over there, or you can press F1 then a window will pop up. Then search about the document using some key words you know about it. So suppose you want to know about inverse sine function. So you want to know what it is in MATLAB. If you want to know inverse sine function. So if you type in here inverse sin as you can see there are some suggestions of functions. So actually the first one is the one we wanted. Click over there. So inverse sine function is asin in MATLAB and this is the syntax. Okay, so because this is inverse function, inverse sine function, the result will be in radians, will be angle.

And there is a description about it, and also a graph and some related functions. This is how you can get help in MATLAB.

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