Quizfile_7_MatrixMultiplication

Functions

FormatVector[v_]:=Module[{i,t},
t=Flatten[Join[{"<"},{#,","}&/@Drop[v,-1]]];
AppendTo[t,Last[v]];
AppendTo[t,">"];
Return[DisplayForm[RowBox[t]]]
]

VectorSymbol[v_]:=DisplayForm[Overscript[v,"⇀"]]

VectorAssign[v_,u_]:={VectorSymbol[v]," = ",FormatVector[u]};

We put a + sign before a positive term, the negative terms carry their own - sign

PlsMin[u_]:=If[#<0," "," + "]&/@DeleteCases[u,0]

Use Riffle to interleave the + signs between the terms
The last element of u represents the constant term on the right hand side of
  (Subscript[u, 1]) (Subscript[x, 1])+(Subscript[u, 2])(Subscript[x, 2])+...+(Subscript[u, n])(Subscript[x, n])=(Subscript[u, n+1])

xs[i_]:=Subscript[x,i];

LHS[u_]:=Riffle[DeleteCases[Table[u[[i]] Subscript[x,i],{i,Length[u]-1}],0],Rest@PlsMin[Drop[u,-1]]];

R2E[u_]:=Row@Join[LHS[u],{" = ",Last[u]}]

Form a linear equation for each row

MatrixToEquations[m_]:=R2E/@m;

VectorEquation[m_]:=Join[Riffle[Flatten[Table[{Subscript[x,i],m[[All,{i}]]},{i,Length[m\[Transpose]]-1}],1]," + ",3],{" = ",m[[All,{Length[m\[Transpose]]}]]}]

MatrixEquation[m_]:=Module[{r,c},
{r,c}=Dimensions[m];
Return[{Drop[m\[Transpose],-1]\[Transpose],Table[{Subscript[x,i]},{i,1,c-1}]," = ",m[[All,{c}]]}]
];

MatrixOfEquations[m_]:=Module[{r,c,a},
{r,c}=Dimensions[m];
a=Row[LHS[#]]&/@(Drop[m\[Transpose],-1]\[Transpose]);
Return[{{a}\[Transpose]," = ",m[[All,{c}]]}]
];

MatrixLHS[m_]:=Module[{r,c},
{r,c}=Dimensions[m];
Return[{Drop[m\[Transpose],-1]\[Transpose],Table[{Subscript[x,i]},{i,1,c-1}]}]
];

m=(({{1, 2, 3, 4}, {5, 0, 7, 8}, {-7, -6, -5, 4}}));

Dimensions[m]

Row[MatrixOfEquations[m]]

Column[MatrixToEquations[m]]

Row[VectorEquation[m]]

Row[MatrixEquation[m]]

Clear[a,b,c,d,S,A,F,U,V,x,y,z]

Questions

Q1={Row[{TraditionalForm[Inactivate[S=(({{9}, {1}, {0}}))]],Spacer[20],TraditionalForm[Inactivate[A=(({{1, 3, 0}, {5, 2, 9}}))]], " \n Evaluate ",HoldForm[A S]}],{3,"m"},
{{Row[{TraditionalForm[(({{12}, {47}}))]}],True,"Correct!"},
{"Undefined. These matrices cannot be multiplied due to their dimensions",False,"Incorrect. In vector-matrix multiplication, the vector S must have the same number of rows as matrix A has columns. \n Matrix A has 3 columns here, and column vector S has 3 rows. These matrices are conformable."},
{Row[{TraditionalForm[(59)]}],False, "Incorrect. Do not add the values of the resulting matrix together."},
{Row[{TraditionalForm[(({{9, 27, 0}, {5, 2, 9}}))]}],False,"Incorrect. The vector column S is multiplied with matrix A \n by multiplying each value of S going down the column by each value of A going from left to right."},
{Row[{TraditionalForm[(({{0, 3, 0}, {0, 2, 81}}))]}], False,"Incorrect. The vector column S is multiplied with matrix A \n by multiplying each value of S going down the column by each value of A going from left to right."}
}};

Q2={Column[{
Row[{"Write the augmented matrix for this system of equations. \n"}],
Row[{TraditionalForm[R2E[{2,-3,10,-2}]]}] ,
Row[{TraditionalForm[R2E[{1,-2,3,-2}]]}],
Row[{TraditionalForm[R2E[{-1,3,1,4}]]}]
}],{3,"g"} (**value of question**),
{{Row[{TraditionalForm[(({{2, -3, 10, -2}, {1, -2, 3, -2}, {-1, 3, 1, 4}}))]}],True,"Correct!"},
{"Undefined.",False,"Incorrect. Any system of linear equations can be turned into an augmented matrix."},
{Row[{TraditionalForm[(({{-4, 6, -20, -2}, {-2, 4, 6, -2}, {-4, 12, 4, 4}}))]}], False, "Incorrect. The values in a linear equation can be thought of as a row in a matrix. In the first linear equation, for example, the 2, -3, 10, and -2 will form a row in an augmented matrix."},
{Row[{TraditionalForm[(({{2, 1, -1}, {-3, -2, 3}, {10, 3, 1}, {-2, -2, 4}}))]}], False,"Incorrect. This matrix does not have the correct dimensions."},
{Row[{TraditionalForm[(({{2, -3, 10, 2}, {1, -2, 3, 2}, {-1, 3, 1, -4}}))]}], False,"Incorrect. Do not 'solve' the system by bring the value to the right of the '=' sign over to the other side of the linear equation."}
}};

Q5={Row[{TraditionalForm[Inactivate[A=(({{1, 3, 0}, {5, 2, 9}}))]], Spacer[20],TraditionalForm[Inactivate[V=(({{2, 4, 1, 4, 1}, {2, 0, 1, 8, 1}}))]], "\n Evaluate ",HoldForm[ A\[Transpose]V]}],{3,"g"},
{{Row[{TraditionalForm[(({{12, 4, 6, 44, 6}, {10, 12, 5, 28, 5}, {18, 0, 9, 72, 9}}))]}],True,"Correct!"},
{"Undefined. These matrices cannot be added due to their dimensions",False,"Incorrect. In matrix multiplication, our matrix D must have the same number of rows as matrix (A^T) has columns. \n Matrix (A^T) has two columns here, and matrix D has two rows. These matrices are conformable."},
{Row[{TraditionalForm[(({{2, 20, 1, 4, 1}, {6, 0, 1, 8, 1}, {0, 9, 0, 0, 0}}))]}], False, "Incorrect. The product matrix should have dimensions 3X5. In matrix multiplication, when distributing the rows of matrix (A^T) with the columns of matrix D, the operation is row X column. \n The first row of matrix (A^T) must be distributed to each column of matrix D before moving onto the next row of matrix (A^T) to distribute its values."},
{Row[{TraditionalForm[(({{12, 4, 7, 34, 6}, {10, 16, 5, 22, 5}, {18, 0, 4, 72, 9}}))]}], False,"Incorrect. Complete your math!"},
{Row[{TraditionalForm[(({{2, 10, 4, 0, 1, 5, 4, 40}, {6, 4, 12, 0, 3, 2, 12, 16}, {0, 18, 0, 0, 0, 9, 0, 72}}))]}], False,"Incorrect. The product matrix should have dimensions 3X5. In matrix multiplication, when distributing the rows of matrix (A^T) with the columns of matrix D, the operation is row X column. \n The first row of matrix (A^T) must be distributed to each column of matrix D before moving onto the next row of matrix (A^T) to distribute its values. When you obtain two values while completing a row X column operation, add the two values together to form one value in a matrix."}
}};

Q6={Row[{TraditionalForm[Inactivate[W=(({{0, 3, 0}, {5, 7, 4}, {1, 4, -19}, {9, -4, 15}}))]], Spacer[20],TraditionalForm[Inactivate[V=(({{-1, 3, 23, -4, 7, 0}, {3, -8, 15, 42, 9, 0}, {0, 6, 72, 1, 3, 0}}))]],
 " \n What are the dimensions of",HoldForm[ W V],"?"}],{3,"m"},
{{"4 X 6",True,"Correct!"},
{"Undefined. These matrices cannot be added due to their dimensions",False,"Incorrect. W has dimensions 4 X 3, and V has dimensions 3 X 6. If the number of rows in V is the same as the number of columns in W, the matrices are conformable."},
{"6 X 4", False, "Incorrect. The dimensions of a matrix are Rows X Columns."},
{"4 X 5", False,"Incorrect. The last column in matrix V may have values of all zeros but they are still values in the matrix. They cannot be ignored from the dimensions of the matrix."},
{"3 X 3", False,"Incorrect. The dimensions of a matrix are Rows X Columns (n X m)."}
}};

m8=(({{4, -2, -7, 13}, {-2, -4, 12, 5}, {5, 4, -1, 4}}));

Q8={Column[{
Row[{"Convert this vector equation into a matrix-vector equation"}],
TraditionalForm@Row[VectorEquation[m8]]
}],{3,"g"}(**value of question**),
{{TraditionalForm@Row[MatrixEquation[m8]],True,"Correct!"},
{"Undefined.",False,"Incorrect. Any system of linear equations can be turned into an augmented matrix."},
{TraditionalForm@Row[MatrixOfEquations[m8]], False, "Incorrect. The variables in the system of equations must be given their own vector column. Do not include the variables inside the matrix containing the equation's given values."},
{Row[{TraditionalForm[m8]}], False,"Incorrect. This is an augmented matrix."},
{TraditionalForm@Row[MatrixLHS[m8]], False,"Incorrect. Do not forget to include the values to the right of the '='."}
}};

MatrixLHS[m8]

qlist7={Q1,Q2,Q5,Q6,Q8};

path=NotebookDirectory[];

fname=path<>"quizfile_7.m"

DeleteFile[fname];

Save[fname,qlist7]

Length[qlist7]

NOTE: Save, put an extra Attribute command at the end of the file, this must be deleted!

Recall

qpool=Get[fname];

Length[qpool]

qpool[[5,3,4]]