Video: More built in functions (3.00)

 

 

Transcript

Suppose I want to know the value of sin of pi by 4. Of course pi by 4 is in radians, so I can use pi by 4 as

input for the sin function.

So in MATLAB I will type sin and in the bracket, pi, by 4. The symbol pi is typed as p - i, pi, in MATLAB.

Ok, now if I press enter, I get the answer which is the value of sin of pi by 4.

Another useful function is rand function r-a-n-d. It is used to generate random numbers between zero and 1. Suppose you want to generate a single random number between 0 and 1 then this function doesn't require any input. You simply type rand and press enter. You see you got the random number which is between 0 and 1.

We can do a bunch of other things with rand function. But that would require some input. Let's see. If I type rand and just one left bracket, as you can see there are a lot of different options for syntax. I am

not going through all of those, but just a simple example.

Suppose you want a 2 by 3 matrix of random numbers which are between 0 and 1. That is you want 2 rows and three columns of random numbers, all of them between 0 and 1. So what will you do? You just type 2, 3 and close the bracket and press enter.

As you can see there are 2 rows and 3 columns so every row has 3 members in them and all the numbers are between 0 and 1.

What will you do if you want all these numbers bewtween 0 and 100? Ok, simply multiply by 100. So let me recall my previous command using up arrow key, and if I just multiply it by 100 and press enter you see now there are 2 rows and 3 columns of random numbers, which all are between 0 and 100.

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