> Financial Mathematics
>> MATLAB Programming
>>> Matrix Algebra

Matrix Algebra

Matrix algebra in Matlab. How to perform Matrix arithmetical operations in Matlab.



Solution:


>> A = [1 2; 3 4];
>> B = [5 6; 7 8] (press Enter)
A =
     1  2
     3  4
B =
     5  6
     7  8

These Matlab commands will generate matrices A and B.


>> A+B (press Enter)
ans =
      6    8
     10   12


>> A-B (press Enter)
ans =
     -4   -4
     -4   -4


>> A*B (press Enter)
ans =
     19   22
     43   50


>> B*A (press Enter)
ans =
     23   34
     31   46

NOTE: A*B B*A



>> A/B (press Enter)
ans =
     3   -2
     2   -1

NOTE: A/B = A*B-1



>> B/A (press Enter)
ans =
     -1   2
     -2   3

NOTE: B/A = B*A-1