// Numbas version: finer_feedback_settings {"name": "John's copy of Finding bases for the null space and row space of a matrix", "extensions": ["stats"], "custom_part_types": [], "resources": [], "navigation": {"allowregen": true, "showfrontpage": false, "preventleave": false, "typeendtoleave": false}, "question_groups": [{"pickingStrategy": "all-ordered", "questions": [{"tags": ["bases", "basis", "column space", "dimension", "echelon form", "linear algebra", "linear independence", "linearly dependent", "matrices", "matrix type", "null space", "nullity", "rank", "row operations", "row reduced", "row space", "row-reduced"], "name": "John's copy of Finding bases for the null space and row space of a matrix", "variable_groups": [], "rulesets": {}, "ungrouped_variables": ["echelonform", "ech", "echform", "testmatrix", "record", "rref1", "record_ops_matrix", "record_ops_message", "rank", "maxint", "steps", "rdmat", "deter", "nullity", "echmatrix", "trtestmatrix", "nbasis_column", "coordcol", "freecols", "rows", "columns", "column_basis", "sum", "null_basis", "ec", "chosen", "student_cols_matrix", "not_chosen_col", "othercols", "c0", "c1", "colmark", "z"], "parts": [{"variableReplacements": [], "prompt": "
Rank of $A=\\;$[[0]]
\nNullity of $A=\\;$[[1]]
", "scripts": {}, "marks": 0, "showCorrectAnswer": true, "type": "gapfill", "variableReplacementStrategy": "originalfirst", "gaps": [{"maxValue": "rank", "minValue": "rank", "correctAnswerFraction": false, "scripts": {}, "variableReplacementStrategy": "originalfirst", "marks": "0.5", "variableReplacements": [], "allowFractions": false, "showCorrectAnswer": true, "showPrecisionHint": false, "type": "numberentry"}, {"maxValue": "nullity", "minValue": "nullity", "correctAnswerFraction": false, "scripts": {}, "variableReplacementStrategy": "originalfirst", "marks": "0.5", "variableReplacements": [], "allowFractions": false, "showCorrectAnswer": true, "showPrecisionHint": false, "type": "numberentry"}]}, {"variableReplacements": [], "prompt": "Determine a basis of $\\operatorname{row}(A)$ consisting of rows of $R$ by clicking on the appropriate choices of rows of $R$.
\n[[0]]
", "scripts": {}, "marks": 0, "showCorrectAnswer": true, "type": "gapfill", "variableReplacementStrategy": "originalfirst", "gaps": [{"maxAnswers": 0, "minAnswers": 0, "shuffleChoices": false, "maxMarks": "1", "variableReplacements": [], "warningType": "none", "matrix": ["0.3", "0.3", "0.4", 0, 0, 0], "displayType": "checkbox", "scripts": {}, "choices": ["Row 1
", "Row 2
", "Row 3
", "Row 4
", "Row 5
", "Row 6
"], "minMarks": 0, "marks": 0, "variableReplacementStrategy": "originalfirst", "showCorrectAnswer": true, "displayColumns": 0, "type": "m_n_2", "distractors": ["", "", "", "", "", ""]}]}, {"maxAnswers": 0, "minAnswers": 0, "warningType": "none", "maxMarks": "1", "variableReplacements": [], "shuffleChoices": false, "variableReplacementStrategy": "originalfirst", "displayType": "checkbox", "prompt": "\nClick on the choices of columns of $A$ which form a basis for the column space.
\n\nNote that there are more than one possible choice of columns and if the columns you choose form a basis then this will be marked as correct. If you Reveal the answer you will see one possible such choice.
\n", "scripts": {"mark": {"script": "var trm=variables.trtestmatrix;\nvar echform=variables.echform;\nvar rank=variables.rank;\nvar trm=Numbas.util.copyarray(trm,true);\nthis.answered=true;\n\n\nvar tm=[];\nvar selected=[];\nvar not_selected=[];\nvar numTicks = 0;\nfor( var i=0;i<5;i++) {\n if(this.ticks[i][0]) {\n numTicks += 1;\n tm.push(trm[i]);\n selected.push(i+1);\n }\n else {not_selected.push(i+1);}\n}\n\nvar rank1 = question.functions.ref(tm);\nvar diff = false;\nvar explain = this.question.display.html.find('#explain');\nvar note = '';\nvar mess = '';\nfor(var i=0;i<3;i++) { \n if(echform[i]!=selected[i]) {\n diff=true;\n }\n}\nif(diff) {\n mess='You have chosen correctly, but the easiest choice to make is those columns which have pivots, in this case columns '+echform[0]+', '+echform[1]+', '+echform[2]+'. ';\n}\nif(numTicksColumn 1
", "Column 2
", "Column 3
", "Column 4
", "Column 5
"]}, {"variableReplacements": [], "prompt": "Express the following columns in terms of the columns $c_\\var{echform[0]}$, $c_\\var{echform[1]}$, $c_\\var{echform[2]}$
\n$c_{\\var{othercols[0]}}$=[[0]]$c_\\var{echform[0]}$+[[1]]$c_{\\var{echform[1]}}$+[[2]]$c_{\\var{echform[2]}}$
\n$c_{\\var{othercols[1]}}$=[[3]]$c_\\var{echform[0]}$+[[4]]$c_{\\var{echform[1]}}$+[[5]]$c_{\\var{echform[2]}}$
", "scripts": {}, "marks": 0, "showCorrectAnswer": true, "type": "gapfill", "variableReplacementStrategy": "originalfirst", "gaps": [{"maxValue": "c0[0]", "minValue": "c0[0]", "correctAnswerFraction": false, "scripts": {}, "variableReplacementStrategy": "originalfirst", "marks": "0.5", "variableReplacements": [], "allowFractions": false, "showCorrectAnswer": true, "showPrecisionHint": false, "type": "numberentry"}, {"maxValue": "c0[1]", "minValue": "c0[1]", "correctAnswerFraction": false, "scripts": {}, "variableReplacementStrategy": "originalfirst", "marks": "0.5", "variableReplacements": [], "allowFractions": false, "showCorrectAnswer": true, "showPrecisionHint": false, "type": "numberentry"}, {"maxValue": "c0[2]", "minValue": "c0[2]", "correctAnswerFraction": false, "scripts": {}, "variableReplacementStrategy": "originalfirst", "marks": "0.5", "variableReplacements": [], "allowFractions": false, "showCorrectAnswer": true, "showPrecisionHint": false, "type": "numberentry"}, {"maxValue": "c1[0]", "minValue": "c1[0]", "correctAnswerFraction": false, "scripts": {}, "variableReplacementStrategy": "originalfirst", "marks": "0.5", "variableReplacements": [], "allowFractions": false, "showCorrectAnswer": true, "showPrecisionHint": false, "type": "numberentry"}, {"maxValue": "c1[1]", "minValue": "c1[1]", "correctAnswerFraction": false, "scripts": {}, "variableReplacementStrategy": "originalfirst", "marks": "0.5", "variableReplacements": [], "allowFractions": false, "showCorrectAnswer": true, "showPrecisionHint": false, "type": "numberentry"}, {"maxValue": "c1[2]", "minValue": "c1[2]", "correctAnswerFraction": false, "scripts": {}, "variableReplacementStrategy": "originalfirst", "marks": "0.5", "variableReplacements": [], "allowFractions": false, "showCorrectAnswer": true, "showPrecisionHint": false, "type": "numberentry"}]}, {"allowResize": true, "correctAnswer": "transpose(matrix(null_basis))", "numColumns": "1", "variableReplacements": [], "allowFractions": false, "correctAnswerFractions": false, "variableReplacementStrategy": "originalfirst", "prompt": "Determine a basis for $\\operatorname{Null}(A)$.
\nEnter the basis elements as the columns of a matrix:
\nNote that any such basis will be marked as correct. If you Reveal the answer you will see one possible such basis.
\n", "scripts": {"mark": {"script": "var nullity=variables.nullity;\nvar columns=variables.columns;\nvar rows=variables.rows;\nvar testmatrix=variables.testmatrix;\nvar ans=this.studentAnswer;\nvar ans_rows=this.studentAnswerRows;\nthis.answered=true;\n\nif(ans_rows!=columns){\n this.setCredit(0,'These vectors are not of the correct dimension.')\n return;\n}\nvar ans_cols=this.studentAnswerColumns;\nif(ans_cols!=nullity){\n this.setCredit(0,'Not the correct number of vectors.')\n return;\n}\nvar dim_null_space_ans=question.functions.ref(ans);\nif(dim_null_space_ans!=nullity){\n this.setCredit(0, 'These vectors are not linearly independent.');\n return;\n}\nfunction check_in_kernel(m1,m2) {\n var d = 0;\n for(var i=0;iGiven a matrix in row reduced form use this to find bases for the null, column and row spaces of the matrix.
"}, "preamble": {"js": "question.functions={};\nquestion.functions.ref=function(m){\n \n m = util.copyarray(m,true);\n \n function finish() {\n\n return rank;\n }\n\n\n\n var lead = 0;\n var rank = 0;\n var echelon=[];\n var rows = m.length;\n for(var i=0;i=b,0,c)", "type": "number", "language": "jme"}, "echelon_form_matrix": {"parameters": [["n", "number"], ["r", "number"], ["m", "number"], ["max", "number"]], "definition": "\nfunction getRandomInt(min, max) {\n return Math.floor(Math.random() * (max - min + 1)) + min;\n};\n//generate a random echelon form\nfunction random_echelon_form(columns,rank){\nvar l=[];\nvar ech_form=[], ech_form1=[],b=[];\nfor(var i=1;i=ind?temp.push(getRandomInt(1,max)):temp.push(0);\n }\n for(var k=0;k ');\nvar n=matrix_list.length;\nvar m='';\nvar mess='';\nfor(var i=0;i '+mess+' ');\ntable.append('');\ntable.append(' '); \n}\nreturn table;\n", "type": "html", "language": "javascript"}}, "showQuestionGroupNames": false, "statement": " '+m+' The row-reduced echelon form $R$ of the following matrix $A$
\n$A=\\var{testmatrix}$ is given by $R=\\var{echmatrix}$.
\n", "variables": {"echmatrix": {"name": "echmatrix", "definition": "matrix(ech)", "group": "Ungrouped variables", "templateType": "anything", "description": ""}, "coordcol": {"name": "coordcol", "definition": "map(id(5)[nbasis_column[x]-1],x,0..length(nbasis_column)-1)", "group": "Ungrouped variables", "templateType": "anything", "description": ""}, "c0": {"name": "c0", "definition": "map(fill(echform[x]-1,othercols[0]-1,echmatrix[x][othercols[0]-1]),x,0..2)", "group": "Ungrouped variables", "templateType": "anything", "description": ""}, "echform": {"name": "echform", "definition": "map(x+1,x,echelonform[1])", "group": "Ungrouped variables", "templateType": "anything", "description": ""}, "echelonform": {"name": "echelonform", "definition": "echelon_form_matrix(rows,rank,columns,maxint)", "group": "Ungrouped variables", "templateType": "anything", "description": ""}, "columns": {"name": "columns", "definition": "5", "group": "Ungrouped variables", "templateType": "anything", "description": ""}, "record_ops_matrix": {"name": "record_ops_matrix", "definition": "record[0]", "group": "Ungrouped variables", "templateType": "anything", "description": ""}, "not_chosen_col": {"name": "not_chosen_col", "definition": "transpose(matrix(map(transpose(echmatrix)[n],n,filter(!chosen[j],j,0..4)))[0])", "group": "Ungrouped variables", "templateType": "anything", "description": ""}, "student_cols_matrix": {"name": "student_cols_matrix", "definition": "transpose(matrix(map(transpose(echmatrix)[n],n,filter(chosen[j],j,0..4))))", "group": "Ungrouped variables", "templateType": "anything", "description": ""}, "deter": {"name": "deter", "definition": "rref(rdmat,0)[3]", "group": "Ungrouped variables", "templateType": "anything", "description": ""}, "nullity": {"name": "nullity", "definition": "5-rank", "group": "Ungrouped variables", "templateType": "anything", "description": ""}, "rref1": {"name": "rref1", "definition": "rref1(list(testmatrix))[0]", "group": "Ungrouped variables", "templateType": "anything", "description": ""}, "column_basis": {"name": "column_basis", "definition": "set(map(trtestmatrix[x],x,echelonform[1]))", "group": "Ungrouped variables", "templateType": "anything", "description": ""}, "chosen": {"name": "chosen", "definition": "[true,true,false,true,false]", "group": "Ungrouped variables", "templateType": "anything", "description": ""}, "z": {"name": "z", "definition": "[0,0,0,0,0]", "group": "Ungrouped variables", "templateType": "anything", "description": ""}, "ec": {"name": "ec", "definition": "echmatrix", "group": "Ungrouped variables", "templateType": "anything", "description": ""}, "record_ops_message": {"name": "record_ops_message", "definition": "record[1]", "group": "Ungrouped variables", "templateType": "anything", "description": ""}, "freecols": {"name": "freecols", "definition": "map(transpose(echmatrix)[nbasis_column[x]-1][0..columns-1],x,0..length(nbasis_column)-1)", "group": "Ungrouped variables", "templateType": "anything", "description": ""}, "testmatrix": {"name": "testmatrix", "definition": "matrix(rdmat)*matrix(ech)", "group": "Ungrouped variables", "templateType": "anything", "description": ""}, "sum": {"name": "sum", "definition": "sum(echform)", "group": "Ungrouped variables", "templateType": "anything", "description": ""}, "nbasis_column": {"name": "nbasis_column", "definition": "list(set(1,2,3,4,5)-set(echform))", "group": "Ungrouped variables", "templateType": "anything", "description": ""}, "othercols": {"name": "othercols", "definition": "list(set(1,2,3,4,5)-set(echform))", "group": "Ungrouped variables", "templateType": "anything", "description": ""}, "maxint": {"name": "maxint", "definition": "4", "group": "Ungrouped variables", "templateType": "anything", "description": ""}, "rdmat": {"name": "rdmat", "definition": "rdmat(rows)", "group": "Ungrouped variables", "templateType": "anything", "description": ""}, "null_basis": {"name": "null_basis", "definition": "switch(sum=6,[[ec[0][2]*ec[2][3]-ec[0][3],ec[1][2]*ec[2][3]-ec[1][3],-ec[2][3],1,0],\n [ec[0][2]*ec[2][4]-ec[0][4],ec[1][2]*ec[2][4]-ec[1][4],-ec[2][4],0,1]],\n sum=7,[[-ec[0][2],-ec[1][2],1,0,0],[-ec[0][4],-ec[1][4],0,-ec[2][4],1]],\n (sum=8) and(5 in echform),[[-ec[0][2],-ec[1][2],1,0,0],[-ec[0][3],-ec[1][3],0,1,0]],\n sum=8,[[-ec[0][1],1,0,0,0],[-ec[0][4],0,-ec[1][4],-ec[2][4],1]],\n sum=9,[[-ec[0][1],1,0,0,0],[-ec[0][3],0,-ec[1][3],1,0]],\n [[-ec[0][1],1,0,0,0],[-ec[0][2],0,1,0,0]])", "group": "Ungrouped variables", "templateType": "anything", "description": ""}, "ech": {"name": "ech", "definition": "echelonform[0]", "group": "Ungrouped variables", "templateType": "anything", "description": ""}, "trtestmatrix": {"name": "trtestmatrix", "definition": "transpose(testmatrix)", "group": "Ungrouped variables", "templateType": "anything", "description": ""}, "c1": {"name": "c1", "definition": "map(fill(echform[x]-1,othercols[1]-1,echmatrix[x][othercols[1]-1]),x,0..2)", "group": "Ungrouped variables", "templateType": "anything", "description": ""}, "rows": {"name": "rows", "definition": "6", "group": "Ungrouped variables", "templateType": "anything", "description": ""}, "rank": {"name": "rank", "definition": "3\n", "group": "Ungrouped variables", "templateType": "anything", "description": ""}, "record": {"name": "record", "definition": "rref(list(testmatrix),0)", "group": "Ungrouped variables", "templateType": "anything", "description": ""}, "colmark": {"name": "colmark", "definition": "colmar(z,echform)", "group": "Ungrouped variables", "templateType": "anything", "description": ""}, "steps": {"name": "steps", "definition": "rref(list(testmatrix),0)[2]", "group": "Ungrouped variables", "templateType": "anything", "description": ""}}, "type": "question", "advice": "
a) The following shows how $A$ is reduced to row-echelon form.
\n\n{solution(record_ops_matrix,record_ops_message)}
\nThe rank of A is the number of columns of R with pivots, i.e. 3.
\nThe nullity of A is the number of columns of R without pivots, i.e. 2.
\nb) Given the row-echelon form we see that the first three rows of $R$ form a basis for the row space of $A$.
\nc) One basis for the column-space of $A$ is given by the original columns which in the row-reduced echelon form have a pivot.
\nFor example, $\\{c_i:i \\in \\var{set(echform)}\\}$
\n$\\var{column_basis}$
\nThere are other bases which you could have chosen and would also have been marked as correct.
\nd) If you look at the columns $c_{\\var{othercols[0]}}$ and $c_{\\var{othercols[1]}}$ we can simply read off these columns as combinations of the other columns by looking at the numbers above the pivot element in each of the columns $c_{\\var{othercols[0]}}$ and $c_{\\var{othercols[1]}}$.
\ne) Basis for the null-space.
\nThe dimension of the null-space is $2$ and so we should have $2$ vectors in the basis.
\nThe null space is given by $\\operatorname{Null}(A)=\\operatorname{Null}(R)= $ \\[\\left\\{(x_1,x_2,x_3,x_4,x_5):\\simplify{{ec}*vector(x_1,x_2,x_3,x_4,x_5)=vector(0,0,0,0,0,0)}\\right\\}\\]
\nThis gives three equations:
\n\\begin{align}\\simplify{{ec[0][0]}x_1+{ec[0][1]}x_2+{ec[0][2]}x_3+{ec[0][3]}x_4+{ec[0][4]}x_5}&=0\\\\\\simplify{{ec[1][0]}x_1+{ec[1][1]}x_2+{ec[1][2]}x_3+{ec[1][3]}x_4+{ec[1][4]}x_5}&=0\\\\\\simplify{{ec[2][0]}x_1+{ec[2][1]}x_2+{ec[2][2]}x_3+{ec[2][3]}x_4+{ec[2][4]}x_5}&=0 \\end{align}
\nThe free columns (without a pivot element) are $c_{\\var{nbasis_column[0]}},c_{\\var{nbasis_column[1]}}$
\nWe obtain $2$ vectors which are linearly independent by:
\n1) Setting: $x_{\\var{nbasis_column[0]}}=1,x_{\\var{nbasis_column[1]}}=0$ gives $\\var{rowvector(null_basis[0])}$ as a basis element for the null-space.
\n2) Setting: $x_{\\var{nbasis_column[0]}}=0,x_{\\var{nbasis_column[1]}}=1$ gives $\\var{rowvector(null_basis[1])}$ as another basis element for the null-space.
\nHence $\\{\\var{rowvector(null_basis[0])},\\var{rowvector(null_basis[1])}\\}$
\nis a basis for the null-space.
\nNote that this is just one possible basis, and if you input another correct basis for the null-space then it will be marked as correct.
\nAlternatively.
\nNote that on using the equations above, the variables $x_{\\var{echform[0]}},\\;x_{\\var{echform[1]}}$ and $x_{\\var{echform[2]}}$ can be expressed in terms of the variables $x_{\\var{nbasis_column[0]}},x_{\\var{nbasis_column[1]}}$.
\nIf we do so we find that:
\n$ (x_1,x_2,x_3,x_4,x_5) \\in \\operatorname{Null}(A) \\iff$ \\[(x_1,x_2,x_3,x_4,x_5)= x_{\\var{nbasis_column[0]}}\\var{rowvector(null_basis[0])}+x_{\\var{nbasis_column[1]}}\\var{rowvector(null_basis[1])}.\\]
\nAs $ x_{\\var{nbasis_column[0]}},\\;x_{\\var{nbasis_column[1]}}$ can take any values we see that the vectors
\n$\\{\\var{rowvector(null_basis[0])},\\var{rowvector(null_basis[1])}\\}$ form a basis as they span $\\operatorname{Null}(A)$ and there are $2$ vectors which agrees with the nullity.
\n\n", "contributors": [{"name": "Newcastle University Mathematics and Statistics", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/697/"}, {"name": "John Steele", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/2218/"}]}]}], "contributors": [{"name": "Newcastle University Mathematics and Statistics", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/697/"}, {"name": "John Steele", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/2218/"}]}