Example 2: Adding Matrices

a.) Matrices are added by adding entries in equivalent locations.  This is a good chance to learn the function Table and/or Array (much cleaner).

$Post:=If[MatrixQ[#],MatrixForm[#],#]& 
A={{1,2},{3,4}}
B={{5,6},{7,8}} 
A+B

Your approach by hand: add corresponding elements.  So, the (ij^th) element would be (Subscript[a, ij])+(Subscript[b, ij])

matrixadd[i_,j_]:=A[[i,j]]+B[[i,j]]

Check your function by testing the (2,1) element

matrixadd[2,1]

We can find an element, so to find the whole matrix, we need to cycle thru all rows and all columns.

Array[matrixadd,{2,2}]

Another less beautiful approach would be to use the Table command.  First, we build a matrix of the right size (say a zero matrix), and then we change the elements one at a time.

mat1=ConstantArray[0,{2,2}]

Table[mat1[[i,j]]=matrixadd[i,j],{i,1,2},{j,1,2}]