// Numbas version: finer_feedback_settings {"name": " Matrix multiplication", "extensions": [], "custom_part_types": [], "resources": [], "navigation": {"allowregen": true, "showfrontpage": false, "preventleave": false, "typeendtoleave": false}, "question_groups": [{"pickingStrategy": "all-ordered", "questions": [{"name": " Matrix multiplication", "tags": ["advanced Numbas implementation", "matrix multiplication"], "metadata": {"description": "

Matrix multiplication. Has automatically generated \"unresolved\" matrix product to write in the solution, which is the interesting part of this implementation.

", "licence": "Creative Commons Attribution 4.0 International"}, "statement": "

Let \\(A=\\var{A}\\), \\(B=\\var{B}\\).

\n

", "advice": "

To compute the product, we work out \"row \\(i\\) of first matrix times column \\(j\\) of second matrix\" for each entry \\(i,j\\) of the product. So in general:

\n

\\[\\var{generalA}\\var{generalB}=\\var{generalAB}.\\]

\n

So we have:

\n

\\(AB=\\var{A}\\var{B}=\\)

\n

\\(\\var{unresolvedproduct(A,B)}=\\var{A*B}\\).

", "rulesets": {}, "extensions": [], "builtin_constants": {"e": true, "pi,\u03c0": true, "i": true}, "constants": [], "variables": {"A": {"name": "A", "group": "Original matrices", "definition": "matrix(repeat(repeat(random(-5..5),k),m))", "description": "

mxk matrix

", "templateType": "anything", "can_override": false}, "B": {"name": "B", "group": "Original matrices", "definition": "matrix(repeat(repeat(random(-5..5),n),k))", "description": "

kxn matrix

", "templateType": "anything", "can_override": false}, "rawgeneralA": {"name": "rawgeneralA", "group": "General matrices for Advice", "definition": "map('a_{'+'{j}'+'{l}}'+symbols(m,k)[j-1][l-1],[j,l],product(1..m,1..k))", "description": "

to print out a 2x2 matrix A in the advice. Size can be changed here

", "templateType": "anything", "can_override": false}, "rawgeneralB": {"name": "rawgeneralB", "group": "General matrices for Advice", "definition": "map('b_{'+'{j}'+'{l}}'+symbols(k,n)[j-1][l-1],[j,l],product(1..k,1..n))", "description": "

to print out a 2x2 matrix B in the advice. Size can be changed here

", "templateType": "anything", "can_override": false}, "generalA": {"name": "generalA", "group": "General matrices for Advice", "definition": "latex('\\\\begin{pmatrix}'+ concatstrings(rawgeneralA) +'\\\\end{'+'pmatrix}')", "description": "

to print out a 2x2 matrix A in the advice.

", "templateType": "anything", "can_override": false}, "generalB": {"name": "generalB", "group": "General matrices for Advice", "definition": "latex('\\\\begin{pmatrix}'+ concatstrings(rawgeneralB) +'\\\\end{'+'pmatrix}')", "description": "", "templateType": "anything", "can_override": false}, "rawgeneralAB": {"name": "rawgeneralAB", "group": "General matrices for Advice", "definition": "map('a_\\{{r+1}{t+1}\\}'+'\\\\cdot'+' b_\\{{t+1}{s+1}\\}'+symbolsAB(m,k,n)[r][s][t],[r,s,t],product(0..(m-1),0..(n-1),0..(k-1)))", "description": "

to print out general product of matrices in Advice.

", "templateType": "anything", "can_override": false}, "generalAB": {"name": "generalAB", "group": "General matrices for Advice", "definition": "latex('\\\\begin{pmatrix}'+ concatstrings(rawgeneralAB) +'\\\\end{'+'pmatrix}')", "description": "", "templateType": "anything", "can_override": false}, "m": {"name": "m", "group": "Original matrices", "definition": "random(2..4)", "description": "", "templateType": "anything", "can_override": false}, "k": {"name": "k", "group": "Original matrices", "definition": "random(2..4)", "description": "", "templateType": "anything", "can_override": false}, "n": {"name": "n", "group": "Original matrices", "definition": "random(2..4)", "description": "", "templateType": "anything", "can_override": false}}, "variablesTest": {"condition": "", "maxRuns": 100}, "ungrouped_variables": [], "variable_groups": [{"name": "Original matrices", "variables": ["A", "B", "m", "k", "n"]}, {"name": "General matrices for Advice", "variables": ["rawgeneralA", "generalA", "rawgeneralB", "generalB", "rawgeneralAB", "generalAB"]}], "functions": {"concatstrings": {"parameters": [["input", "list"]], "type": "string", "language": "javascript", "definition": "var output = '';\nvar i;\nfor (i = 0; i < input.length; i++) {\n output += input[i];\n} \nreturn output;"}, "symbolsAB": {"parameters": [["m", "number"], ["k", "number"], ["n", "number"]], "type": "list", "language": "jme", "definition": "repeat(repeat(repeat('+',k-1)+['&'],n-1)+[repeat('+',k-1)+['\\\\\\\\']],m-1)+[repeat(repeat('+',k-1)+['&'],n-1)+[repeat('+',k-1)+['']]]"}, "rawunresolvedproduct": {"parameters": [["A", "matrix"], ["B", "matrix"], ["m", "number"], ["k", "number"], ["n", "number"]], "type": "string", "language": "jme", "definition": "map(if({A[r][t]<0,'({A[r][t]})','{A[r][t]}')+'\\\\cdot'+if(B[t][s]<0,'({B[t][s]})','{B[t][s]}')+symbolsAB(m,k,n)[r][s][t],[r,s,t],product(0..m-1,0..n-1,0..k-1))"}, "symbols": {"parameters": [["m", "number"], ["n", "number"]], "type": "list", "language": "jme", "definition": "repeat(repeat('&',n-1)+['\\\\\\\\'],m-1)+[repeat('&',n-1)+['']]"}, "unresolvedproduct": {"parameters": [["A", "matrix"], ["B", "matrix"]], "type": "string", "language": "jme", "definition": "if(numcolumns(A)=numrows(B),latex('\\\\begin{pmatrix}'+ concatstrings(rawunresolvedproduct(A,B,numrows(A),numrows(B),numcolumns(B))) +'\\\\end{'+'pmatrix}'),'Cannot multiply')"}}, "preamble": {"js": "", "css": ""}, "parts": [{"type": "gapfill", "useCustomName": false, "customName": "", "marks": 0, "scripts": {}, "customMarkingAlgorithm": "", "extendBaseMarkingAlgorithm": true, "unitTests": [], "showCorrectAnswer": true, "showFeedbackIcon": true, "variableReplacements": [], "variableReplacementStrategy": "originalfirst", "nextParts": [], "suggestGoingBack": false, "adaptiveMarkingPenalty": 0, "exploreObjective": null, "prompt": "

Compute \\(AB = \\) [[0]]

", "gaps": [{"type": "matrix", "useCustomName": false, "customName": "", "marks": "3", "scripts": {}, "customMarkingAlgorithm": "", "extendBaseMarkingAlgorithm": true, "unitTests": [], "showCorrectAnswer": true, "showFeedbackIcon": true, "variableReplacements": [], "variableReplacementStrategy": "originalfirst", "nextParts": [], "suggestGoingBack": false, "adaptiveMarkingPenalty": 0, "exploreObjective": "Multiply matrices", "correctAnswer": "A*B", "correctAnswerFractions": false, "numRows": 1, "numColumns": 1, "allowResize": true, "tolerance": 0, "markPerCell": false, "allowFractions": false, "minColumns": 1, "maxColumns": 0, "minRows": 1, "maxRows": 0}], "sortAnswers": false}], "partsMode": "all", "maxMarks": "28", "objectives": [{"name": "Determine whether matrix product exists.", "limit": "5", "mode": "sum"}, {"name": "Multiply matrices", "limit": "16", "mode": "sum"}, {"name": "Transpose a matrix", "limit": "5", "mode": "sum"}, {"name": "Understand some theory", "limit": "2", "mode": "sum"}], "penalties": [], "objectiveVisibility": "when-active", "penaltyVisibility": "always", "type": "question", "contributors": [{"name": "Julia Goedecke", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/5121/"}]}]}], "contributors": [{"name": "Julia Goedecke", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/5121/"}]}