MatLab

Sunday, 5 May 2013

Application of Operators.....!!!!


As I have explained in previous tutorials about the different operators on the Matrices.  In this tutorial, I have tried to cover the operations of different operators.
Let’s have a look one by one…
           
          1)      For element wise forward division

 >> a=[1 2 3; 2 3 4];
>> b=[1 2 3; 4 5 6];
>> c=a./b

c =

  1.000000000000000   1.000000000000000   1.000000000000000
  0.500000000000000   0.600000000000000   0.666666666666667

Note: - You can notice that one on one forward division of the elements.  By using this operator one can divide 1st element from 1st matrix with 1st element from 2nd element, 2nd element with 2nd element, etc.

            2)      For element wise Multiplication

>> a=[1 2 3; 2 3 4];
>> b=[1 2 3; 4 5 6];
>> d= a.*b

d =

  1     4     9
  8    15    24

Note: - You can notice that one on one multiplication of the elements.  By using this operator one can multiply first element with first element, second element with second element, etc.

             3)      For element wise backward division

>> a=[1 2 3; 2 3 4];
>> b=[1 2 3; 4 5 6];
>> h=a.\b

h =

                1.000000000000000   1.000000000000000   1.000000000000000
                2.000000000000000   1.666666666666667   1.500000000000000

Note: - You can notice that one on one backward division of the elements.  By using this operator one can divide 1st element from 1st matrix with 1st element from 2nd element, 2nd element with 2nd element, etc.

4)      Addition of the two matrix

>> a=[1 2 3; 2 3 4];
>> b=[1 2 3; 4 5 6];
>> f=a+b

f =

     2     4     6
     6     8    10

Note: - Normal addition is done with the matrix.

5)      Subtraction of the two matrix   

>> a=[1 2 3; 2 3 4];
>>b=[1 2 3; 4 5 6];
>> f=a-b

f =

     0     0     0
    -2    -2    -2

Note: - Normal subtraction is done with the matrix.

Many more operations are there which can be performed on the matrices. I will discuss them in upcoming articles.

P.S: - Please try these operations once on your own to understand it better.

Hope to see you in next tutorial….!!!!

No comments:

Post a Comment