Thursday, 19 December 2013

Basic Operations on Matrices Matlab Code

clear all;
close all;
clc;
a=input('enter matrix A:');
b=input('eneter matrix B:');
c=input('enter Matrix C:');
disp('the size of matrix A is :');
disp(size(a));
disp('the size of matrix B is :');
disp(size(b));
disp('the size of matrix C is :');
disp(size(c));
disp('the addition of matrices A & B is:');
disp(a+b);
disp('the substraction of matrices A & B is :');
disp(a-b);
disp('the element by element multiplication of A & B is:');
disp(a.*b);
disp('The trace of matrix C is :');
disp(trace(c));
disp('the determinant of the matrix C is :');
disp(det(c));
disp ('the inverse of matrix C is :');
disp(inv(c));
disp(' the rank of matrix C is :');
disp(rank(c));

Outputs if the specied inputs as given  below are:

Matrix A : [1 2;3 4]
Matrix B : [3 4;5 6]
Matrix C:  [1 2;3 4]

The size of matrix A is
       2     2
The size of matrix B is
      2      2
The size of matrix c is
      2       2
the addition of matrices A & B is:  4     6
                                                    8      10
the substraction of matrices A & B is :  -2    -2
                                                            -2    -2

the element by element multiplication of A & B is:  3     8
                                                                            15  24

The trace of matrix C is : 5

the determinant of the matrix C is : -2

the inverse of matrix C is :   -2.000       1.000
.                                         1.5000      -0.5000

the rank of matrix C is : 2

No comments:

Post a Comment