// Numbas version: exam_results_page_options {"name": "Demo of automatically generating unresolved matrix product output", "extensions": [], "custom_part_types": [], "resources": [], "navigation": {"allowregen": true, "showfrontpage": false, "preventleave": false, "typeendtoleave": false}, "question_groups": [{"pickingStrategy": "all-ordered", "questions": [{"name": "Demo of automatically generating unresolved matrix product output", "tags": ["calculation steps", "matrix multiplication", "unresolved matrix product"], "metadata": {"description": "

Matrix multiplication. Contains a function that will let you print the calculation steps of matrix multiplication, e.g. in the Advice.

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

With this function, you can write the calculation steps of a matrix multiplication, without having to make lots of complicated variables or writing lots of things out. (You'd normally write this in \"Advice\", but this is just a demo.)

\n

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

\n

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

\n

If the sizes don't match, it will tell you:

\n

\\(CD=\\var{C}\\var{D}=\\var{unresolvedproduct(C,D)}\\)

\n

You can also do matrix times \"vector\", but only if you code the vector as a matrix. See how it is done in the variables.

\n

\\(Cv=\\var{C}\\var{v}=\\var{unresolvedproduct(C,v)}\\)

\n

There is also a general one. This one does use a bit more in variables.

\n

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

\n

You can find the functions under \"Extensions & scripts\".

", "advice": "", "rulesets": {}, "extensions": [], "variables": {"A": {"name": "A", "group": "Original matrices", "definition": "matrix(repeat(repeat(random(-5..5),k),m))", "description": "

mxk matrix

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

kxn matrix

", "templateType": "anything"}, "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"}, "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"}, "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"}, "generalB": {"name": "generalB", "group": "General matrices for Advice", "definition": "latex('\\\\begin{pmatrix}'+ concatstrings(rawgeneralB) +'\\\\end{'+'pmatrix}')", "description": "", "templateType": "anything"}, "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"}, "generalAB": {"name": "generalAB", "group": "General matrices for Advice", "definition": "latex('\\\\begin{pmatrix}'+ concatstrings(rawgeneralAB) +'\\\\end{'+'pmatrix}')", "description": "", "templateType": "anything"}, "m": {"name": "m", "group": "Original matrices", "definition": "random(2..4)", "description": "", "templateType": "anything"}, "k": {"name": "k", "group": "Original matrices", "definition": "random(2..4)", "description": "", "templateType": "anything"}, "n": {"name": "n", "group": "Original matrices", "definition": "random(2..4)", "description": "", "templateType": "anything"}, "C": {"name": "C", "group": "Original matrices", "definition": "matrix(repeat(repeat(random(-5..5),k),k+1))", "description": "", "templateType": "anything"}, "D": {"name": "D", "group": "Original matrices", "definition": "matrix(repeat(repeat(random(-5..5),k),k+1))", "description": "", "templateType": "anything"}, "v": {"name": "v", "group": "Original matrices", "definition": "matrix(repeat([random(-5..5)],k))", "description": "", "templateType": "anything"}}, "variablesTest": {"condition": "", "maxRuns": 100}, "ungrouped_variables": [], "variable_groups": [{"name": "Original matrices", "variables": ["A", "B", "m", "k", "n", "C", "D", "v"]}, {"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": [], "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", "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/"}]}