Permalink
Browse files

Sample matrix question added.

  • Loading branch information...
sangwinc committed Jun 27, 2012
1 parent 68579f6 commit f74dfb95b8ac4c2365ba6cec44159763ba3236bd
@@ -20,6 +20,10 @@ A rectangle has length 6cm greater than its width. If it has an area of 27cm$^2$
This is a multi-part question which illustrates _follow-through marking_. Get the first part wrong, but the second part correct based on the first part to see the feedback.
+### `test_3_matrix.xml` ###
+
+This question creates two random matrices and asks students to multiply them together. See the notes on [matrices](../CAS/Matrix.md).
+
### `railways.xml` ###
In a railway journey of 90km an increase of 5 kilometers per hour in the speed decreases the time taken by 15 minutes.
View
@@ -39,6 +39,17 @@ The above equation is then generated by the CASText
\[ @A@+@B@=@C@=@D@.\]
+A similar procedure is needed for showing working when multiplying matrices. Here we need to loop over the matrices, but there must be a more elegant way to do this.
+
+ A:ev(rand(matrix([5,5],[5,5]))+matrix([2,2],[2,2]),simp);
+ B:ev(rand(matrix([5,5],[5,5]))+matrix([2,2],[2,2]),simp);
+ BT:transpose(B);
+ C:zeromatrix (first(matrix_size(A)), second(matrix_size(A)));
+ S:for a:1 thru first(matrix_size(A)) do for b:1 thru second(matrix_size(A)) do C[ev(a,simp),ev(b,simp)]:apply("+",zip_with("*",A[ev(a,simp)],BT[ev(b,simp)]));
+ D:ev(C,simp);
+
+Notice we need to simplify the arguments before we take indices of expressions. This is one problem with `simp:false`.
+
## Vectors ##
If you are trying to use the vector notation such as \(3i+4j\) you will probably want to redefine \(i\) to be an abstract symbol, not a complex number.
@@ -0,0 +1,212 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<quiz>
+<!-- question: 94 -->
+ <question type="stack">
+ <name>
+ <text>test_3_matrix</text>
+ </name>
+ <questiontext format="html">
+ <text><![CDATA[<p>Calculate \[ @A@.@B@\]</p>
+<p> [[input:ans1]] [[validation:ans1]]</p>]]></text>
+ </questiontext>
+ <generalfeedback format="html">
+ <text><![CDATA[<p>To multiply matrices $A$ and $B$ we need to remember that the $(i,j)$th entry is the scalar product of the $i$th row of $A$ with the $j$th column of $B$.</p>
+<p>\[ @A@.@B@ = @C@ = @D@.\]</p>]]></text>
+ </generalfeedback>
+ <defaultgrade>1.0000000</defaultgrade>
+ <penalty>0.1000000</penalty>
+ <hidden>0</hidden>
+ <questionvariables>
+ <text><![CDATA[A:ev(rand(matrix([5,5],[5,5]))+matrix([2,2],[2,2]),simp);
+B:ev(rand(matrix([5,5],[5,5]))+matrix([2,2],[2,2]),simp);
+TA:ev(A.B,simp);
+TB:ev(A*B,simp);
+BT:transpose(B);
+C:zeromatrix (first(matrix_size(A)), second(matrix_size(A)));
+S:for a:1 thru first(matrix_size(A)) do for b:1 thru second(matrix_size(A)) do C[ev(a,simp),ev(b,simp)]:apply("+",zip_with("*",A[ev(a,simp)],BT[ev(b,simp)]));
+D:ev(C,simp);]]></text>
+ </questionvariables>
+ <specificfeedback format="html">
+ <text><![CDATA[<p>[[feedback:prt1]]</p>]]></text>
+ </specificfeedback>
+ <questionnote>
+ <text>$@A@.@B@=@TA@$</text>
+ </questionnote>
+ <questionsimplify>0</questionsimplify>
+ <assumepositive>0</assumepositive>
+ <prtcorrect format="html">
+ <text><![CDATA[<p><span class="correct">Correct answer, well done.</span></p>]]></text>
+ </prtcorrect>
+ <prtpartiallycorrect format="html">
+ <text><![CDATA[<p><span class="partially">Your answer is partially correct.</span></p>]]></text>
+ </prtpartiallycorrect>
+ <prtincorrect format="html">
+ <text><![CDATA[<p><span class="incorrect">Incorrect answer.</span></p>]]></text>
+ </prtincorrect>
+ <multiplicationsign>dot</multiplicationsign>
+ <sqrtsign>1</sqrtsign>
+ <complexno>i</complexno>
+ <variantsselectionseed></variantsselectionseed>
+ <input>
+ <name>ans1</name>
+ <type>matrix</type>
+ <tans>TA</tans>
+ <boxsize>3</boxsize>
+ <strictsyntax>1</strictsyntax>
+ <insertstars>0</insertstars>
+ <syntaxhint></syntaxhint>
+ <forbidwords></forbidwords>
+ <forbidfloat>1</forbidfloat>
+ <requirelowestterms>1</requirelowestterms>
+ <checkanswertype>1</checkanswertype>
+ <mustverify>1</mustverify>
+ <showvalidation>1</showvalidation>
+ </input>
+ <prt>
+ <name>prt1</name>
+ <value>1.0000000</value>
+ <autosimplify>1</autosimplify>
+ <feedbackvariables>
+ <text></text>
+ </feedbackvariables>
+ <node>
+ <name>0</name>
+ <answertest>AlgEquiv</answertest>
+ <sans>ans1</sans>
+ <tans>TA</tans>
+ <testoptions></testoptions>
+ <quiet>1</quiet>
+ <truescoremode>=</truescoremode>
+ <truescore>1.0000000</truescore>
+ <truepenalty></truepenalty>
+ <truenextnode>-1</truenextnode>
+ <trueanswernote>1-0-T </trueanswernote>
+ <truefeedback format="html">
+ <text></text>
+ </truefeedback>
+ <falsescoremode>=</falsescoremode>
+ <falsescore>0.0000000</falsescore>
+ <falsepenalty></falsepenalty>
+ <falsenextnode>1</falsenextnode>
+ <falseanswernote>1-0-F</falseanswernote>
+ <falsefeedback format="html">
+ <text></text>
+ </falsefeedback>
+ </node>
+ <node>
+ <name>1</name>
+ <answertest>AlgEquiv</answertest>
+ <sans>ans1</sans>
+ <tans>TB</tans>
+ <testoptions></testoptions>
+ <quiet>1</quiet>
+ <truescoremode>=</truescoremode>
+ <truescore>0.0000000</truescore>
+ <truepenalty></truepenalty>
+ <truenextnode>-1</truenextnode>
+ <trueanswernote>1-1-T </trueanswernote>
+ <truefeedback format="html">
+ <text><![CDATA[<p>Remember, you don't multiply matrices by multiplying the corresponding entries! A quite different process is needed.</p>]]></text>
+ </truefeedback>
+ <falsescoremode>=</falsescoremode>
+ <falsescore>0.0000000</falsescore>
+ <falsepenalty></falsepenalty>
+ <falsenextnode>2</falsenextnode>
+ <falseanswernote>1-1-F </falseanswernote>
+ <falsefeedback format="html">
+ <text></text>
+ </falsefeedback>
+ </node>
+ <node>
+ <name>2</name>
+ <answertest>AlgEquiv</answertest>
+ <sans>ans1</sans>
+ <tans>A+B</tans>
+ <testoptions></testoptions>
+ <quiet>1</quiet>
+ <truescoremode>=</truescoremode>
+ <truescore>0.0000000</truescore>
+ <truepenalty></truepenalty>
+ <truenextnode>-1</truenextnode>
+ <trueanswernote>1-3-T</trueanswernote>
+ <truefeedback format="html">
+ <text><![CDATA[<p>Please multiply the matrices. It looks like you have added them instead!</p>]]></text>
+ </truefeedback>
+ <falsescoremode>=</falsescoremode>
+ <falsescore>0.0000000</falsescore>
+ <falsepenalty></falsepenalty>
+ <falsenextnode>-1</falsenextnode>
+ <falseanswernote>1-3-F</falseanswernote>
+ <falsefeedback format="html">
+ <text></text>
+ </falsefeedback>
+ </node>
+ </prt>
+ <qtest>
+ <testcase>1</testcase>
+ <testinput>
+ <name>ans1</name>
+ <value>TA</value>
+ </testinput>
+ <expected>
+ <name>prt1</name>
+ <expectedscore>1.0000000</expectedscore>
+ <expectedpenalty>0.0000000</expectedpenalty>
+ <expectedanswernote>1-0-T </expectedanswernote>
+ </expected>
+ </qtest>
+ <qtest>
+ <testcase>2</testcase>
+ <testinput>
+ <name>ans1</name>
+ <value>TB</value>
+ </testinput>
+ <expected>
+ <name>prt1</name>
+ <expectedscore>0.0000000</expectedscore>
+ <expectedpenalty>0.1000000</expectedpenalty>
+ <expectedanswernote>1-1-T</expectedanswernote>
+ </expected>
+ </qtest>
+ <qtest>
+ <testcase>3</testcase>
+ <testinput>
+ <name>ans1</name>
+ <value>A+B</value>
+ </testinput>
+ <expected>
+ <name>prt1</name>
+ <expectedscore>0.0000000</expectedscore>
+ <expectedpenalty>0.1000000</expectedpenalty>
+ <expectedanswernote>1-3-T</expectedanswernote>
+ </expected>
+ </qtest>
+ <qtest>
+ <testcase>4</testcase>
+ <testinput>
+ <name>ans1</name>
+ <value>1</value>
+ </testinput>
+ <expected>
+ <name>prt1</name>
+ <expectedscore></expectedscore>
+ <expectedpenalty></expectedpenalty>
+ <expectedanswernote>NULL</expectedanswernote>
+ </expected>
+ </qtest>
+ <qtest>
+ <testcase>5</testcase>
+ <testinput>
+ <name>ans1</name>
+ <value>A</value>
+ </testinput>
+ <expected>
+ <name>prt1</name>
+ <expectedscore>0.0000000</expectedscore>
+ <expectedpenalty>0.1000000</expectedpenalty>
+ <expectedanswernote>1-3-F</expectedanswernote>
+ </expected>
+ </qtest>
+ </question>
+
+</quiz>
Oops, something went wrong.

0 comments on commit f74dfb9

Please sign in to comment.