4:44 AM

Matrix operation

1.If you want to add/subtract two matrices just adding them will do provided they are of same dimensions.
eg.,

a=[1 2;3 4];
b=[5 6;7 8];

 c=a+b gives

c =

     6     8
    10    12

2.Multiplying two matrices can also be done in a similar way so is dividing one matrix by another.
eg.,
c=a*b %provided num_of_columns of a=num_of_rows of b
gives

c =

    19    22
    43    50
 and for division
c=a/b %this is actually a*inverse(b)
gives you
c =

    3.0000   -2.0000
    2.0000   -1.0000

3.In fact you can solve linear equations using matrix form.This can be done by Martin's rule.eg.,
if the three equations are-
6x+8y+z=8;
4x+7y-5z=5;
10x+6y-9z=14;

if the equation can be represented as AX=B where A=[6 8 1;4 7 -5;10 6 -9]

A =

     6     8     1
     4     7    -5
    10     6    -9
i.e.,the coefficients of the variables and X=x
                                                                y
                                                                z
and B=8
           5
           14
then the solution can be found out by Martin's rule:X=B.inverse(A)
so if you type X=B/A gives you the desired solution:

X =
    2.7472   -2.5843    0.1854

4.However if you want to do element-by-element operation you need to do a little variation.

Suppose you want to square each number of a matrix x=1 2
                                                                                      3 4

simply doing x^2 will multiply the whole matrix with itself.Hence for element-by-element operation you need to do the following

>> x.^2

The dot(.) signifies element-by-element operation.So if you want to divide one matrix by another element-by-element simply write
x./y.Therefore the dot(.) must appear before every operational sign.


5.Transpose of a matrix.
X' gives you the transpose of the matrix X.
PLEASE LEAVE A COMMENT :)

0 comments:

Post a Comment