MASTERSHEET
Copy/Paste Formulae for Module 1 Matrices

>Copy the formula you need
>Paste it into the other workbook you are using
>NOTE: Do NOT alter the formulae in this workbook, these are your templates only.

MATHEMATICA COMMANDS FOR Module 1 Matrices

1. Three ways to write Matrices

a. Method 1

{{"row 1 elements"},{"row 2 elements"}}//MatrixForm

{{a,b,c}, {d,e,f}}//MatrixForm

b. Method 2

Top tool bar: Insert > Table/Matrix >New... >Create Matrix with row numbers and column numbers, for example 3X3, then fill elements in your new Matrix:

(({{\[Placeholder], \[Placeholder], \[Placeholder]}, {\[Placeholder], \[Placeholder], \[Placeholder]}, {\[Placeholder], \[Placeholder], \[Placeholder]}}))

c. Method 3

Top tool bar: Palettes  > Basic Math Assistant > Basic Commands

2. Define a matrix with an upper case letter

Examples:

A=(({{a, b, c}, {d, e, f}}))

B=(({{1, 0, -7, 2}, {5, 5, 5, 5}, {-4, 3, 2, 0}}))

F=(({{2, 4}, {1, 7}}))

3. Adding, Subtracting, Scalar Multiple, Transposing Matrices

a. Adding Matrices

"matrix 1"+"matrix 2"//MatrixForm

F+(({{1, 2}, {3, 4}}))//MatrixForm

b. Subtracting Matrices

"matrix 1"-"matrix 2"//MatrixForm

F-(({{1, 2}, {3, 4}}))//MatrixForm

c. Scalar Multiple

"scalar number"×"matrix"//MatrixForm

3(({{2, 4}, {1, 7}}))//MatrixForm

d. Transposing Matrix

Transpose["matrix"]//MatrixForm

Transpose[(({{1, 2}, {3, 4}}))]//MatrixForm

4. Two Matrices Multiplication, Powers of Matrices

a. Multiplication with a dot in between

"matrix 1"."matrix 2"//MatrixForm

(({{1, 0, 0}, {0, 1, 0}, {0, 0, 1}})).(({{2, 3, 4}, {3, 4, 5}, {5, 6, 7}}))//MatrixForm

b. Powers

MatrixPower["matrix","powers"]//MatrixForm

Example 1: (G^3)

MatrixPower[G,3]//MatrixForm

5. Identity,  Inverse matrices and Determinant of a Matrix

a. Identity Matrix

IdentityMatrix["row or column numbers"]//MatrixForm

IdentityMatrix[3]//MatrixForm

b. Inverse Matrix

Inverse["matrix"]//MatrixForm

Inverse[(({{1, 2}, {3, 4}}))]//MatrixForm

c. Complicated Inverse Calculation

mA="the 1st matrix know";
mB="the 2nd matrix know";
mC="the 3rd matrix know";
mD="the 4th matrix know";
Inverse["Calculation inside INVERSE brackets"]//MatrixForm

mA=(({{3, -1}, {4, 5}}));
mB=(({{-7, 2}, {3, 1}}));
mC=(({{-4, 9}, {6, 8}}));
mD=(({{0, 8}, {4, -1}}));
(mA.mB+Inverse[mD])//MatrixForm

d. Determinant of a Matrix

determinant[det_,x_]:=Det["matrix"]//N
NSolve[determinant["the value of Determinant","the unknown letter, if a matrix given, just type any number in matrix here"]=="the value of Determinant",Reals]

determinant[det_,x_]:=Det[(({{1, 2}, {m, 4}}))]//N
NSolve[determinant[0,m]==0,Reals]

determinant[det_,x_]:=Det[(({{1, 2}, {3, 4}}))]//N
NSolve[determinant["the value of Determinant",1]=="the value of Determinant",Reals]

6. Using Matrices to Solve Simultaneous Equations

a. LinearSolve: Determinant = 0 means no solution or non-unique solutions

LinearSolve["Left side of standard equations - coefficient matrix","Right side of standard equations - constant matrix"]//MatrixForm

LinearSolve[(({{2, 3}, {1, -2}})),(({{6}, {4}}))]//MatrixForm//N

b. Alternatively

Solve[{equation here number one,another equation here},{variable1,variable2}]

Solve[{2x+3y==6,x-2y==4},{x,y}]//N

c. Given Matrices, write Equations

eqns=Thread["Left side of standard equations - coefficient matrix"."unknown matrix"=="Right side of standard equations - constant matrix"]

eqns=Thread[(({{1, 1, 1}, {1, 0, 1}, {0, 1, 1}})).(({{x}, {y}, {z}}))==(({{6}, {4}, {5}}))]

d. Given Equations, write Matrices

l={"Write all equations here, separate by comma, each equation needs two == signs"};
lm=CoefficientArrays[l,{"Write all unknown letters here, separate by comma,"}][[2]]//MatrixForm
Print[Normal[lm],{"Write all unknown letters here, separate by comma,"}//MatrixForm, "= Write right side of the equations constant numbers in a column matrix here"]

l={x-y-z==0,x+2 y+z==1,x+2y+5z==5};
lm=CoefficientArrays[l,{x,y,z}][[2]]//MatrixForm
Print[Normal[lm],{x,y,z}//MatrixForm, "= Write right side of the equations constant numbers in a column matrix here"]

(({{1, -1, -1}, {1, 2, 1}, {1, 2, 5}}))(({{x}, {y}, {z}}))= (({{0}, {1}, {5}}))

7. Recurrence tables of Matrices from the first Matrix/ Transition Matrices/Leslie Matrics

lindiff[n_]:= "Transition Matrix".n + "Extra Matrix"
NestList[lindiff,"Initial Matrix","How many more Matrices"]//MatrixForm//N

lindiff[n_]:= (({{0.7, 0.2, 0.1}, {0.1, 0.5, 0.4}, {0.2, 0.3, 0.5}})).n + (({{100}, {200}, {300}}))
NestList[lindiff,(({{1100}, {1200}, {1300}})),3]//MatrixForm//N

lindiff[n_]:= (({{0.96, 0.05}, {0.04, 0.95}})).n 
NestList[lindiff,(({{700}, {900}})),11]//MatrixForm//N

geometric[n_]:= (({{0.92, 0.01, 0.01, 0.01}, {0.02, 0.95, 0.01, 0.02}, {0.04, 0.02, 0.97, 0.03}, {0.02, 0.02, 0.01, 0.94}})).n +(({{750}, {875}, {1025}, {825}}))
NestList[geometric,(({{35500}, {43500}, {51000}, {42000}})),11]//MatrixForm//N

geometric[n_]:=(({{0.75, 0.30}, {0.25, 0.70}})).n 
NestList[geometric,(({{200}, {300}})),11]//MatrixForm//N

8. Dominance/ Ranking D+(D^2)

K="matrix 1"
K+MatrixPower[K,2]//MatrixForm//MatrixForm

K=(({{0, 1, 0, 1}, {1, 0, 0, 0}, {0, 0, 1, 1}, {1, 0, 1, 0}}))
K+MatrixPower[K,2]//MatrixForm//MatrixForm

9. Find Previous Matrix from new/next Matrix/ Transition Matrices

Inverse["Transition Matrix"].("Next Matrix"-"Extra Matrix")//MatrixForm

Inverse[(({{0.1, 0.2, 0.5}, {0.3, 0.7, 0.2}, {0.6, 0.1, 0.3}}))].((({{9830}, {11130}, {7830}}))-(({{70}, {70}, {70}})))//MatrixForm

10. Solving Equations for Matrices

mA="the 1st matrix know";
mB="the 2nd matrix know";
mC="the 3rd matrix know";
mD="the 4th matrix know";
mE="the 5th matrix know";
mX=Array[X,{"the row number of unknow","the column number of unknow"}]
Solve["left side of the equation"=="right side of the equation",Flatten[mX]]

mA=(({{2, 1, 3}, {1, 2, 1}, {2, 2, 2}}));
mB=(({{3, 2}, {4, 3}}));
mC=(({{-6, -1}, {5, 6}}));
mD=(({{3}, {4}}));
mE=(({{5}, {7}, {9}}));
mX=Array[X,{2,1}]
Solve[mB.mX+(({{7}, {6}}))==mD,Flatten[mX]]

mX=(({{-8}, {10}}))

11. Constructing a matrix given a rule for its ijth  term

mat=Table["Given Rule for i and j",{i,1,"Row number"},{j,1,"Column number"}];
mat//MatrixForm

mat=Table[2i-j+2,{i,1,2},{j,1,3}];
mat//MatrixForm

12. Matrices Multiplication Step by step with working out

nA=oA="the 1st matrix know";
nB=oB="the 2nd matrix know";
step1=MatrixForm[Inner[Inactive[Times],"the first matrix for multiplication e.g. nA","the first matrix for multiplication e.g. nB",Inactive[Plus]],TableSpacing->{3,3}]
step2=Activate[step1,Times]
Activate[step2]

nC=oC=(({{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}));
step1=MatrixForm[Inner[Inactive[Times],nC,nC,Inactive[Plus]],TableSpacing->{3,3}]
step2=Activate[step1,Times]
Activate[step2]