Solution

a=rand(3)            //to create random matrix of range 0 to 1 and of size 3x3
a=a*4                 //for range;
a=a+7
a=round(a)         // to convert elements into int.
b=eye(3)            // to create identity matrix
addi=a+b           // addition
sub=a-b             //subtraction
mul1=a*b         //multiplication
mul2=a.*b       //corresponding elements multiplication

Output :
//for a=rand(3)
a =

    0.7922    0.0357    0.6787
    0.9595    0.8491    0.7577
    0.6557    0.9340    0.7431

//for a=a*4;
a =

    3.1688    0.1428    2.7149
    3.8380    3.3965    3.0310
    2.6230    3.7360    2.9725

//for a=a+7;
a =

   10.1688    7.1428    9.7149
   10.8380   10.3965   10.0310
    9.6230   10.7360    9.9725

//for a=round(a);
a =

    10     7    10
    11    10    10
    10    11    10

// for b=eye(3);
b =

     1     0     0
     0     1     0
     0     0     1

// for addi=a+b;
addi =

    11     7    10
    11    11    10
    10    11    11

//for sub=a-b;
sub =

     9     7    10
    11     9    10
    10    11     9

// for mul1=a*b;
mul1 =

    10     7    10
    11    10    10
    10    11    10

//for mul2=a.*b;
mul2 =

    10     0     0
     0    10     0
     0     0    10


Popular posts from this blog

Shutdown Pc

Ellipse using OpenGl

String Comparisons