// Numbas version: finer_feedback_settings {"name": "Matrix transformations (WBQ 1.30 randomised)", "extensions": [], "custom_part_types": [], "resources": [], "navigation": {"allowregen": true, "showfrontpage": false, "preventleave": false, "typeendtoleave": false}, "question_groups": [{"pickingStrategy": "all-ordered", "questions": [{"name": "Matrix transformations (WBQ 1.30 randomised)", "tags": ["matrix multiplication", "matrix times vector", "matrix transformation"], "metadata": {"description": "
First compute matrix times vector for specific vectors. Then determine domain and codomain and general formula for the matrix transformation defined by the matrix.
\n\nRandomising the number of rows in the matrix, m, makes the marking algorithm for part c) slightly complicated: it checks whether it should include the third gap or not depending on the variable m. For the correct distribution of marks, it is then necessary to do \"you only get the marks if all gaps are correct\". Otherwise the student would only get 2/3 marks when m=2, so the third gap doesn't appear.
", "licence": "Creative Commons Attribution 4.0 International"}, "statement": "Let \\(A=\\var{A}\\), \\(B=\\var{B}\\), \\(u=\\var{u}\\) and \\(v=\\var{v}\\).
", "advice": "a) To calculate matrix times vector \\(Ax\\), we calculate this row by row: the first entry of the resulting vector is \"row 1 of the matrix times the vector\". In general:
\n\\[\\begin{pmatrix} a_{11} & a_{12} &a_{13} \\\\ a_{21} & a_{22} & a_{23}\\end{pmatrix} \\begin{pmatrix}x_1\\\\x_2\\\\x_3\\end{pmatrix}= \\begin{pmatrix} a_{11}x_1+a_{12}x_2 +a_{13}x_3\\\\ a_{21}x_1+a_{22}x_2 +a_{23}x_3\\end{pmatrix}\\]
\nSo the vector \\(x\\) needs to have as many entries as the matrix has columns, and the resulting vector \\(Ax\\) has as many entries as \\(A\\) has rows.
\n\\(\\var{A}\\var{u}=\\var{unresolvedAu}=\\var{A*u}\\)
\n\\(\\var{A}\\var{v}=\\var{unresolvedAv}=\\var{A*v}\\)
\n\\(\\var{B}\\var{u}=\\var{unresolvedBu}=\\var{B*u}\\)
\n\\(\\var{B}\\var{v}=\\var{unresolvedBv}=\\var{B*v}\\)
\nb) As explained above, the matrix \\(A\\) can take a vector \\(x\\) with \\(\\var{n}\\) entries as input, and gives a vector \\(Ax\\) with \\(\\var{m}\\) entries as output. This is a matrix transformation \\(T_A\\colon { \\mathbb{R}^{\\var{n}} \\to \\mathbb{R}^{\\var{m}}}\\), i.e. \\(n=\\var{n}\\) and \\(m=\\var{m}\\).
\nc) As \\(n=\\var{n}\\), we calculate \\(\\var{A}\\var{latexx} = \\var{latexAx}\\)
", "rulesets": {}, "extensions": [], "variables": {"A": {"name": "A", "group": "Ungrouped variables", "definition": "matrix(repeat(repeat(random(-3..3),n),m))", "description": "", "templateType": "anything"}, "B": {"name": "B", "group": "Ungrouped variables", "definition": "matrix([0,0,0],[0,0,0])", "description": "", "templateType": "anything"}, "u": {"name": "u", "group": "Ungrouped variables", "definition": "vector(repeat(random(-3..3),n))", "description": "", "templateType": "anything"}, "v": {"name": "v", "group": "Ungrouped variables", "definition": "vector(repeat(random(-3..3),n))", "description": "", "templateType": "anything"}, "rawunresolvedAu": {"name": "rawunresolvedAu", "group": "Ungrouped variables", "definition": "map(if({A[k][l]<0,'({A[k][l]})','{A[k][l]}')+'\\\\cdot'+if(u[l]<0,'({u[l]})','{u[l]}')+symbols(m,n)[k][l],[k,l],product(0..m-1,0..n-1))", "description": "collects the terms \\(a_{ij}\\cdot v_j\\) for the matrix times vector multiplication, with plus symbols or new line concatenated ready to put into latex code for the calulcation steps of the matrix.
\nAll the \"if\" things are to put brackets round negative numbers. not using simplify because i prefer \\(\\cdot\\) to \\(\\times\\).
\nWithout the need for brackets, it could just be map('{A[k][l]}\\\\cdot{va[l]}'+symbols(2,2)[k][l],[k,l],product(0..1,0..1))
\nThe \"symbols\" is a function giving the correct addition or new line symbols for the size of the matrix that is being used.
", "templateType": "anything"}, "m": {"name": "m", "group": "Ungrouped variables", "definition": "random(2..3)", "description": "", "templateType": "anything"}, "n": {"name": "n", "group": "Ungrouped variables", "definition": "random(2..4)", "description": "", "templateType": "anything"}, "rawunresolvedAv": {"name": "rawunresolvedAv", "group": "Ungrouped variables", "definition": "map(if({A[k][l]<0,'({A[k][l]})','{A[k][l]}')+'\\\\cdot'+if(v[l]<0,'({v[l]})','{v[l]}')+symbols(m,n)[k][l],[k,l],product(0..m-1,0..n-1))", "description": "collects the terms \\(a_{ij}\\cdot v_j\\) for the matrix times vector multiplication, with plus symbols or new line concatenated ready to put into latex code for the calulcation steps of the matrix.
\nAll the \"if\" things are to put brackets round negative numbers. not using simplify because i prefer \\(\\cdot\\) to \\(\\times\\).
\nWithout the need for brackets, it could just be map('{A[k][l]}\\\\cdot{va[l]}'+symbols(2,2)[k][l],[k,l],product(0..1,0..1))
\nThe \"symbols\" is a function giving the correct addition or new line symbols for the size of the matrix that is being used.
", "templateType": "anything"}, "rawunresolvedBu": {"name": "rawunresolvedBu", "group": "Ungrouped variables", "definition": "map(if({B[k][l]<0,'({B[k][l]})','{B[k][l]}')+'\\\\cdot'+if(u[l]<0,'({u[l]})','{u[l]}')+symbols(m,n)[k][l],[k,l],product(0..m-1,0..n-1))", "description": "collects the terms \\(a_{ij}\\cdot v_j\\) for the matrix times vector multiplication, with plus symbols or new line concatenated ready to put into latex code for the calulcation steps of the matrix.
\nAll the \"if\" things are to put brackets round negative numbers. not using simplify because i prefer \\(\\cdot\\) to \\(\\times\\).
\nWithout the need for brackets, it could just be map('{A[k][l]}\\\\cdot{va[l]}'+symbols(2,2)[k][l],[k,l],product(0..1,0..1))
\nThe \"symbols\" is a function giving the correct addition or new line symbols for the size of the matrix that is being used.
", "templateType": "anything"}, "rawunresolvedBv": {"name": "rawunresolvedBv", "group": "Ungrouped variables", "definition": "map(if({B[k][l]<0,'({B[k][l]})','{B[k][l]}')+'\\\\cdot'+if(v[l]<0,'({v[l]})','{v[l]}')+symbols(m,n)[k][l],[k,l],product(0..m-1,0..n-1))", "description": "collects the terms \\(a_{ij}\\cdot v_j\\) for the matrix times vector multiplication, with plus symbols or new line concatenated ready to put into latex code for the calulcation steps of the matrix.
\nAll the \"if\" things are to put brackets round negative numbers. not using simplify because i prefer \\(\\cdot\\) to \\(\\times\\).
\nWithout the need for brackets, it could just be map('{A[k][l]}\\\\cdot{va[l]}'+symbols(2,2)[k][l],[k,l],product(0..1,0..1))
\nThe \"symbols\" is a function giving the correct addition or new line symbols for the size of the matrix that is being used.
", "templateType": "anything"}, "unresolvedAu": {"name": "unresolvedAu", "group": "Ungrouped variables", "definition": "latex('\\\\begin{pmatrix}'+ concatstrings(rawunresolvedAu) +'\\\\end{'+'pmatrix}')", "description": "for the solution, the calculation steps written out unresolved.
", "templateType": "anything"}, "unresolvedAv": {"name": "unresolvedAv", "group": "Ungrouped variables", "definition": "latex('\\\\begin{pmatrix}'+ concatstrings(rawunresolvedAv) +'\\\\end{'+'pmatrix}')", "description": "for the solution, the calculation steps written out unresolved.
", "templateType": "anything"}, "unresolvedBu": {"name": "unresolvedBu", "group": "Ungrouped variables", "definition": "latex('\\\\begin{pmatrix}'+ concatstrings(rawunresolvedBu) +'\\\\end{'+'pmatrix}')", "description": "for the solution, the calculation steps written out unresolved.
", "templateType": "anything"}, "unresolvedBv": {"name": "unresolvedBv", "group": "Ungrouped variables", "definition": "latex('\\\\begin{pmatrix}'+ concatstrings(rawunresolvedBv) +'\\\\end{'+'pmatrix}')", "description": "for the solution, the calculation steps written out unresolved.
", "templateType": "anything"}, "x": {"name": "x", "group": "Ungrouped variables", "definition": "map('x_{k}',k,1..n)", "description": "general vector x. ['x_1','x_2','x_3'] As list because vector can only take numbers as entries.
", "templateType": "anything"}, "latexAx": {"name": "latexAx", "group": "Ungrouped variables", "definition": "latex('\\\\begin{pmatrix}'+ concatstrings(halfrawAx) +'\\\\end{'+'pmatrix}')", "description": "Ax as needed for latex string. I've done '\\\\end{'+'pmatrix}' instead of '\\\\end{pmatrix}' because the latter kept giving me errors about pmatrix not being a variable. It doesn't seem to be a problem for the begin bit, but this way at least is a work-around.
", "templateType": "anything"}, "rawAx": {"name": "rawAx", "group": "Ungrouped variables", "definition": "map('{A[k][l]}*'+x[{l}]+symbols2(m,n)[k][l],[k,l],product(0..m-1,0..n-1))", "description": "", "templateType": "anything"}, "halfrawAx": {"name": "halfrawAx", "group": "Ungrouped variables", "definition": "map(string(simplify(expression(concatstrings(rawAx[(n*k)..(n*k+n)])),\"all\"))+symbols3(m)[k],k,0..m-1)", "description": "", "templateType": "anything"}, "Ax": {"name": "Ax", "group": "Ungrouped variables", "definition": "map(simplify(expression(concatstrings(rawAx[(n*k)..(n*k+n)])),[\"all\",\"!noleadingminus\"]),k,0..m-1)", "description": "Ax as list, can be used as expected answer.
", "templateType": "anything"}, "xalt": {"name": "xalt", "group": "Ungrouped variables", "definition": "map('x{k}',k,1..n)", "description": "alternative way of writing the variables in mathematical expression for part c
", "templateType": "anything"}, "rawAxalt": {"name": "rawAxalt", "group": "Ungrouped variables", "definition": "map('{A[k][l]}*'+xalt[{l}]+symbols2(m,n)[k][l],[k,l],product(0..m-1,0..n-1))", "description": "alternative way of writing the variables in mathematical expression for part c
", "templateType": "anything"}, "Axalt": {"name": "Axalt", "group": "Ungrouped variables", "definition": "map(simplify(expression(concatstrings(rawAxalt[(n*k)..(n*k+n)])),[\"all\",\"!noleadingminus\"]),k,0..m-1)", "description": "alternative way of writing the variables in mathematical expression for part c
", "templateType": "anything"}, "latexx": {"name": "latexx", "group": "Ungrouped variables", "definition": "latex('\\\\begin{pmatrix}'+ concatstrings(halfrawx) +'\\\\end{'+'pmatrix}')", "description": "I've done '\\\\end{'+'pmatrix}' instead of '\\\\end{pmatrix}' because the latter kept giving me errors about pmatrix not being a variable. It doesn't seem to be a problem for the begin bit, but this way at least is a work-around.
", "templateType": "anything"}, "halfrawx": {"name": "halfrawx", "group": "Ungrouped variables", "definition": "map(x[k]+symbols3(n)[k],k,0..n-1)", "description": "", "templateType": "anything"}}, "variablesTest": {"condition": "", "maxRuns": 100}, "ungrouped_variables": ["A", "B", "u", "v", "m", "n", "rawunresolvedAu", "rawunresolvedAv", "rawunresolvedBu", "rawunresolvedBv", "unresolvedAu", "unresolvedAv", "unresolvedBu", "unresolvedBv", "x", "rawAx", "halfrawAx", "latexAx", "Ax", "xalt", "rawAxalt", "Axalt", "halfrawx", "latexx"], "variable_groups": [], "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;"}, "symbols": {"parameters": [["m", "number"], ["n", "number"]], "type": "list", "language": "jme", "definition": "repeat(repeat('+',n-1)+['\\\\\\\\'],m-1)+[repeat('+',n-1)+['']]"}, "symbols2": {"parameters": [["m", "number"], ["n", "number"]], "type": "list", "language": "jme", "definition": "repeat(repeat('+',n-1)+[''],m-1)+[repeat('+',n-1)+['']]"}, "symbols3": {"parameters": [["m", "number"]], "type": "list", "language": "jme", "definition": "repeat('\\\\\\\\',m-1)+['']"}}, "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:
\n\\(Au = \\) [[0]]
\n\\(Av= \\) [[1]]
\n\\(Bu= \\) [[2]]
\n\\(Bv= \\) [[3]]
", "gaps": [{"type": "matrix", "useCustomName": false, "customName": "", "marks": 1, "scripts": {}, "customMarkingAlgorithm": "", "extendBaseMarkingAlgorithm": true, "unitTests": [], "showCorrectAnswer": true, "showFeedbackIcon": true, "variableReplacements": [], "variableReplacementStrategy": "originalfirst", "nextParts": [], "suggestGoingBack": false, "adaptiveMarkingPenalty": 0, "exploreObjective": null, "correctAnswer": "A*u", "correctAnswerFractions": false, "numRows": 1, "numColumns": 1, "allowResize": true, "tolerance": 0, "markPerCell": true, "allowFractions": false, "minColumns": 1, "maxColumns": "1", "minRows": 1, "maxRows": 0}, {"type": "matrix", "useCustomName": false, "customName": "", "marks": 1, "scripts": {}, "customMarkingAlgorithm": "", "extendBaseMarkingAlgorithm": true, "unitTests": [], "showCorrectAnswer": true, "showFeedbackIcon": true, "variableReplacements": [], "variableReplacementStrategy": "originalfirst", "nextParts": [], "suggestGoingBack": false, "adaptiveMarkingPenalty": 0, "exploreObjective": null, "correctAnswer": "A*v", "correctAnswerFractions": false, "numRows": 1, "numColumns": 1, "allowResize": true, "tolerance": 0, "markPerCell": true, "allowFractions": false, "minColumns": 1, "maxColumns": "1", "minRows": 1, "maxRows": 0}, {"type": "matrix", "useCustomName": false, "customName": "", "marks": 1, "scripts": {}, "customMarkingAlgorithm": "", "extendBaseMarkingAlgorithm": true, "unitTests": [], "showCorrectAnswer": true, "showFeedbackIcon": true, "variableReplacements": [], "variableReplacementStrategy": "originalfirst", "nextParts": [], "suggestGoingBack": false, "adaptiveMarkingPenalty": 0, "exploreObjective": null, "correctAnswer": "B*u", "correctAnswerFractions": false, "numRows": 1, "numColumns": 1, "allowResize": true, "tolerance": 0, "markPerCell": true, "allowFractions": false, "minColumns": 1, "maxColumns": "1", "minRows": 1, "maxRows": 0}, {"type": "matrix", "useCustomName": false, "customName": "", "marks": 1, "scripts": {}, "customMarkingAlgorithm": "", "extendBaseMarkingAlgorithm": true, "unitTests": [], "showCorrectAnswer": true, "showFeedbackIcon": true, "variableReplacements": [], "variableReplacementStrategy": "originalfirst", "nextParts": [], "suggestGoingBack": false, "adaptiveMarkingPenalty": 0, "exploreObjective": null, "correctAnswer": "B*v", "correctAnswerFractions": false, "numRows": 1, "numColumns": 1, "allowResize": true, "tolerance": 0, "markPerCell": true, "allowFractions": false, "minColumns": 1, "maxColumns": "1", "minRows": 1, "maxRows": 0}], "sortAnswers": false}, {"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": "The matrix transformation of \\(A\\) is \\(T_A\\colon { \\mathbb{R}^n \\to \\mathbb{R}^m}\\) for which numbers \\(n\\) and \\(m\\)?
\n\\(n = \\) [[1]] and \\(m= \\) [[0]]
", "gaps": [{"type": "numberentry", "useCustomName": true, "customName": "m", "marks": 1, "scripts": {}, "customMarkingAlgorithm": "", "extendBaseMarkingAlgorithm": true, "unitTests": [], "showCorrectAnswer": true, "showFeedbackIcon": true, "variableReplacements": [], "variableReplacementStrategy": "originalfirst", "nextParts": [], "suggestGoingBack": false, "adaptiveMarkingPenalty": 0, "exploreObjective": null, "minValue": "m", "maxValue": "m", "correctAnswerFraction": false, "allowFractions": false, "mustBeReduced": false, "mustBeReducedPC": 0, "showFractionHint": true, "notationStyles": ["plain", "en", "si-en"], "correctAnswerStyle": "plain"}, {"type": "numberentry", "useCustomName": true, "customName": "n", "marks": 1, "scripts": {}, "customMarkingAlgorithm": "", "extendBaseMarkingAlgorithm": true, "unitTests": [], "showCorrectAnswer": true, "showFeedbackIcon": true, "variableReplacements": [], "variableReplacementStrategy": "originalfirst", "nextParts": [], "suggestGoingBack": false, "adaptiveMarkingPenalty": 0, "exploreObjective": null, "minValue": "n", "maxValue": "n", "correctAnswerFraction": false, "allowFractions": false, "mustBeReduced": false, "mustBeReducedPC": 0, "showFractionHint": true, "notationStyles": ["plain", "en", "si-en"], "correctAnswerStyle": "plain"}], "sortAnswers": false}, {"type": "gapfill", "useCustomName": false, "customName": "", "marks": 0, "scripts": {}, "customMarkingAlgorithm": "mygaps (Pick the correct number of gaps depending on the variable m):\n gaps[0..m]\n\nmystudentAnswer (Pick the correct number of gaps in student answer):\n studentAnswer[0..m]\n\nmarked_original_order (Mark the gaps in the original order, mainly to establish if every gap has a valid answer):\n map(\n mark_part(gap[\"path\"],studentAnswer),\n [gap,studentAnswer],\n zip(mygaps,mystudentAnswer)\n )\n\n\ngap_order:\n if(settings[\"sortAnswers\"],\n sort_destinations(interpreted_answers)\n ,\n list(0..len(mygaps)-1)\n )\n\ngap_feedback (Feedback on each of the gaps):\n map(\n let(result,submit_part(mygaps[gap_number][\"path\"],answer),\n feedback(translate('part.gapfill.feedback header',[\"index\":index]));\n concat_feedback(result[\"feedback\"], result[\"marks\"]/marks);\n result\n ),\n [gap_number,answer,index],\n zip(gap_order,mystudentAnswer,list(1..len(mygaps)))\n )\n\ngap_correct:\n map(result[\"credit\"]=1,result,gap_feedback)\n\n\nall_correct:\n correctif(all(gap_correct))\n\n\nmark:\n assert(all_valid, fail(translate(\"question.can not submit\")));\n apply(answers); \n apply(all_correct)\n", "extendBaseMarkingAlgorithm": true, "unitTests": [], "showCorrectAnswer": true, "showFeedbackIcon": true, "variableReplacements": [], "variableReplacementStrategy": "originalfirst", "nextParts": [], "suggestGoingBack": false, "adaptiveMarkingPenalty": 0, "exploreObjective": null, "prompt": "For a general vector \\(x=\\begin{pmatrix}x_1\\\\x_2\\\\\\vdots \\\\x_n\\end{pmatrix}\\), determine \\(T_A(x)\\). Input \\(x_1\\) as x_1
or x1
, etc. Use the same notation for all variables, don't mix it.
\\(T_A(x)= \\left(\\begin{matrix} \\phantom{.}\\\\\\phantom{.}\\\\\\phantom{.}\\end{matrix} \\right. \\) | \n[[0]] | \n\\(\\left.\\begin{matrix} \\phantom{.}\\\\\\phantom{.}\\\\\\phantom{.}\\end{matrix} \\right) \\) | \n
[[1]] | \n
\\(T_A(x)= \\left(\\begin{matrix} \\phantom{.}\\\\\\phantom{.}\\\\\\phantom{.}\\\\\\phantom{.}\\end{matrix} \\right. \\) | \n[[0]] | \n\\(\\left.\\begin{matrix} \\phantom{.}\\\\\\phantom{.}\\\\\\phantom{.}\\\\\\phantom{.}\\end{matrix} \\right) \\) | \n
[[1]] | \n||
[[2]] | \n