Saturday, April 12, 2014

How to create a Matrix Using Freemat

By now we have come to know some basics about Matrix. Now how to create them and later work with them. Its very easy to create matrix in Freemat.
The commands are similar to Matlab.

1. Row Matrix
---------------------------------------------------------------------------------------------------------------------
A = [ 1 2 3 4 ]

A is the name of the matrix and the value of all the elements are stored in the variable A. You can name it anything .Its an array and give a location number to all the elements of the matrix. The picture of freemat is given below.

If we are defining Matrix we have to use square brackets and inside the brackets we have to write the elements. In creating row matrix we just separate the element with blank spaces only.

2. Column Matrix
---------------------------------------------------------------------------------------------------------------------
B = [ 1; 2; 3; 4 ]

We assigned another name to a column matrix.  Here each element is separated by a ';' . Square bracket is need and every element is given an address to identify it.
Like what does
B(2,1) signify
Its the 'B' Matrix
2nd Row
1st Column
So B(2,1) is 2
The pic is given Below.

3. Any size Matrix
---------------------------------------------------------------------------------------------------------------------
C = [1 2 3 4;5 6 7 8;9 10 11 12]

Here we have created 3 row matrices and a ';' in between them to make the program understand that next segment belong to the next row. So we have 3 row staked together making it a 3X3 matrix.

4. Random Number matrix
---------------------------------------------------------------------------------------------------------------------
D = rand(3,3)

'rand' is the command for random matrix. After a command you don't need to use the square brackets but use first brackets ( ) . This contain the specifications for 'rand' command i.e a 3X3 matrix. The first element signify the number of rows and the second signify the number of columns.




5. Null matrix or Zero Matrix
---------------------------------------------------------------------------------------------------------------------

A = zeros(3,3)

will produce all the 9 elements as zero which is also called null matrix

6. Identity Matrix
---------------------------------------------------------------------------------------------------------------------
B   = eye(3)

Identity matrix is a square matrix of all zeros except the diagonal. The diagonal is one.

7. All One Matrix
-------------------------------------------------------------------------------------------------------------------

C = ones(3,3)

Creates all the elements as one




1 comment:

  1. HOW TO DO A GRAPHIC LIKE STEM FROM MATLAB

    ReplyDelete