// Numbas version: finer_feedback_settings {"name": "Demo automatically generate latex for matrix/vector calculation", "extensions": [], "custom_part_types": [], "resources": [], "navigation": {"allowregen": true, "showfrontpage": false, "preventleave": false, "typeendtoleave": false}, "question_groups": [{"pickingStrategy": "all-ordered", "questions": [{"name": "Demo automatically generate latex for matrix/vector calculation", "tags": ["automatically generated latex", "demo", "latex", "latex for matrix"], "metadata": {"description": "
Demo of automatically generating latex strings to out put vectors/matrices of variable size and that are calculated by some formula.
", "licence": "Creative Commons Attribution 4.0 International"}, "statement": "Let \\(A=\\var{A}\\), \\(u=\\var{u}\\). \\(m=\\var{m}\\) and \\(n=\\var{n}\\) give the variable size of \\(A\\).
", "advice": "", "rulesets": {}, "extensions": [], "variables": {"A": {"name": "A", "group": "Ungrouped variables", "definition": "matrix(repeat(repeat(random(-3..3),n),m))", "description": "", "templateType": "anything"}, "u": {"name": "u", "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"}, "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"}, "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"}, "halfrawx": {"name": "halfrawx", "group": "Ungrouped variables", "definition": "map(x[k]+symbols3(n)[k],k,0..n-1)", "description": "", "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"}, "rawgeneralA": {"name": "rawgeneralA", "group": "Ungrouped variables", "definition": "map('a_{'+'{k}'+'{l}}'+symbols4(m,n)[k-1][l-1],[k,l],product(1..m,1..n))", "description": "", "templateType": "anything"}, "generalA": {"name": "generalA", "group": "Ungrouped variables", "definition": "latex('\\\\begin{pmatrix}'+ concatstrings(rawgeneralA) +'\\\\end{'+'pmatrix}')", "description": "", "templateType": "anything"}, "rawunresolvedA1": {"name": "rawunresolvedA1", "group": "Ungrouped variables", "definition": "map('{k}+{l}'+symbols4(m,n)[k-1][l-1],[k,l],product(1..m,1..n))", "description": "", "templateType": "anything"}, "latexA1": {"name": "latexA1", "group": "Ungrouped variables", "definition": "latex('\\\\begin{pmatrix}'+ concatstrings(rawunresolvedA1) +'\\\\end{'+'pmatrix}')", "description": "", "templateType": "anything"}, "rawA1": {"name": "rawA1", "group": "Ungrouped variables", "definition": "map(k+l,[k,l],product(1..m,1..n))", "description": "", "templateType": "anything"}, "A1": {"name": "A1", "group": "Ungrouped variables", "definition": "matrix(map(rawA1[k..k+n],k,list(vector(0..m-1)*n)))", "description": "", "templateType": "anything"}}, "variablesTest": {"condition": "", "maxRuns": 100}, "ungrouped_variables": ["A", "u", "m", "n", "rawunresolvedAu", "unresolvedAu", "x", "rawAx", "halfrawAx", "latexAx", "halfrawx", "latexx", "rawgeneralA", "generalA", "rawunresolvedA1", "latexA1", "rawA1", "A1"], "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)+['']"}, "symbols4": {"parameters": [["m", "number"], ["n", "number"]], "type": "list", "language": "jme", "definition": "repeat(repeat('&',n-1)+['\\\\\\\\'],m-1)+[repeat('&',n-1)+['']]"}}, "preamble": {"js": "", "css": ""}, "parts": [{"type": "information", "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": "To demonstrate matrix times vector:
\n\\(\\var{A}\\var{u}=\\var{unresolvedAu}=\\var{A*u}\\)
\n(Note: I prefer \\(\\cdot\\) to \\(\\times\\) for multiplication, and didn't need any other simplification rules than brackets, so I did it this way rather than use the inbuilt simplify function.)
\nFor a general vector:
\n\\(\\var{A}\\var{latexx} = \\var{latexAx}\\)
\n"}, {"type": "information", "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": "A general matrix of random size: \\(\\var{generalA}\\)
\nWith some unresolved calculations: \\(\\var{latexA1}\\)
\nAnd the same thing resolved: \\(\\var{A1}\\).
\nYou can see more complex things in the question called \"Find matrix from entry formula ( WBQ 1.23 randomized size and formula)\", which is in Chapter 1 Vectors and Matrices in Linear Algebra Y1.
"}], "partsMode": "all", "maxMarks": 0, "objectives": [], "penalties": [], "objectiveVisibility": "always", "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/"}]}