<?xml version="1.0" encoding="UTF-8"?>
<quiz>
  <question type="stack">
    <name>
      <text>22.2.1.6 Finding modal matrices</text>
    </name>
    <questiontext format="html">
      <text><![CDATA[<p class="HELM_exercise">Exercise</p>
<p>For each of the following matrices, find a modal matrix \(P\):</p>
<ol class="HELM_parts">
<li><div>\(A={@matA@}\)</div><br><div>\( P=\) [[input:ans1]] [[validation:ans1]] [[feedback:prt1]]</div></li><br>
<li><div>\(A={@matB@}\)</div><br><div>\( P=\) [[input:ans2]] [[validation:ans2]] [[feedback:prt2]]</div></li><br>
</ol>]]></text>
    </questiontext>
    <generalfeedback format="html">
      <text><![CDATA[<ol class="HELM_parts">
<li>
The eigenvalues of \(A={@matA@}\) are \({@eval1@}\) and \({@eval2@}\), with corresponding eigenvectors \({@evec1@}\) and \({@evec2@}\), respectively. Hence a modal matrix to \({@matA@}\) is \(P={@p1@}\). <br>We can confirm that 
<br>\(\qquad P^{-1}AP={@invert(p1)@}{@matA@}{@p1@}={@matD@},\)
<br>hence \({@p1@}\) is a modal matrix of \(A\).
</li><li> For \(A={@matB@}\) we find eigenvalues \({@eval3@},{@eval4@}\), and \({@eval5@}\) with corresponding eigenvectors \({@evec3@},{@evec4@}\), and \({@evec5@}\). Hence a modal matrix is \(P={@p2@}\). <br>We can confirm that 
<br>\(\qquad P^{-1}AP={@invert(p2)@}{@matB@}{@p2@}={@matD2@},\)
<br>hence \({@p2@}\) is a modal matrix of \(A\).</li>]]></text>
    </generalfeedback>
    <defaultgrade>1</defaultgrade>
    <penalty>0.1</penalty>
    <hidden>0</hidden>
    <idnumber/>
    <stackversion>
      <text>2024072400</text>
    </stackversion>
    <questionvariables>
      <text>/*(a) Generate evecs and evals*/
evec1:rand(matrix([4],[4]))+matrix([1],[0]);
evec2:rand(matrix([4],[4]))+matrix([0],[1]);

eval1:rand_with_prohib(-4,4,[0]);
eval2:rand_with_prohib(-4,4,[0,eval1]);

/*Deduce matrix A*/
p1:matrix([evec1[1,1],evec2[1,1]],[evec1[2,1],evec2[2,1]]);
p1inv:invert(p1);

matD:matrix([eval1,0],[0,eval2]);
matA:p1.matD.p1inv;

/*(b) Generate evecs and evals*/
evec3:rand(matrix([3],[3],[3]))+matrix([1],[1],[1]);
evec4:rand(matrix([1],[3],[3]))+matrix([0],[1],[1]);
evec5:rand(matrix([1],[1],[3]))+matrix([0],[0],[1])

eval3:rand_with_prohib(-4,4,[0]);
eval4:rand_with_prohib(-4,4,[0,eval3]);
eval5:rand_with_prohib(-4,4,[0,eval4,eval3]);

/*Deduce matrix A*/
p2:matrix([evec3[1,1],evec4[1,1],evec5[1,1]],[evec3[2,1],evec4[2,1],evec5[2,1]],[evec3[3,1],evec4[3,1],evec5[3,1]]);
p2inv:invert(p2);

matD2:matrix([eval3,0,0],[0,eval4,0],[0,0,eval5]);
matB:p2.matD2.p2inv;</text>
    </questionvariables>
    <specificfeedback format="html">
      <text/>
    </specificfeedback>
    <questionnote format="moodle_auto_format">
      <text>\(A={@matA@}\)
\(P_1={@p1@}\)
\(D_1={@matD@}\)
\(A_2={@matB@}\)
\(P_2={@p2@}\)
\(D_2={@matD2@}\)</text>
    </questionnote>
    <questiondescription format="moodle_auto_format">
      <text/>
    </questiondescription>
    <questionsimplify>1</questionsimplify>
    <assumepositive>0</assumepositive>
    <assumereal>0</assumereal>
    <prtcorrect format="html">
      <text><![CDATA[<span style="font-size: 1.5em; color:green;"><i class="fa fa-check"></i></span> Correct answer, well done.]]></text>
    </prtcorrect>
    <prtpartiallycorrect format="html">
      <text><![CDATA[<span style="font-size: 1.5em; color:orange;"><i class="fa fa-adjust"></i></span> Your answer is partially correct.]]></text>
    </prtpartiallycorrect>
    <prtincorrect format="html">
      <text><![CDATA[<span style="font-size: 1.5em; color:red;"><i class="fa fa-times"></i></span> Incorrect answer.]]></text>
    </prtincorrect>
    <decimals>.</decimals>
    <scientificnotation>*10</scientificnotation>
    <multiplicationsign>dot</multiplicationsign>
    <sqrtsign>1</sqrtsign>
    <complexno>i</complexno>
    <inversetrig>cos-1</inversetrig>
    <logicsymbol>lang</logicsymbol>
    <matrixparens>[</matrixparens>
    <isbroken>0</isbroken>
    <variantsselectionseed/>
    <input>
      <name>ans1</name>
      <type>matrix</type>
      <tans>p1</tans>
      <boxsize>3</boxsize>
      <strictsyntax>1</strictsyntax>
      <insertstars>0</insertstars>
      <syntaxhint/>
      <syntaxattribute>0</syntaxattribute>
      <forbidwords/>
      <allowwords/>
      <forbidfloat>1</forbidfloat>
      <requirelowestterms>0</requirelowestterms>
      <checkanswertype>0</checkanswertype>
      <mustverify>1</mustverify>
      <showvalidation>3</showvalidation>
      <options/>
    </input>
    <input>
      <name>ans2</name>
      <type>matrix</type>
      <tans>p2</tans>
      <boxsize>3</boxsize>
      <strictsyntax>1</strictsyntax>
      <insertstars>0</insertstars>
      <syntaxhint/>
      <syntaxattribute>0</syntaxattribute>
      <forbidwords/>
      <allowwords/>
      <forbidfloat>1</forbidfloat>
      <requirelowestterms>0</requirelowestterms>
      <checkanswertype>0</checkanswertype>
      <mustverify>1</mustverify>
      <showvalidation>3</showvalidation>
      <options/>
    </input>
    <prt>
      <name>prt1</name>
      <value>1.0000000</value>
      <autosimplify>1</autosimplify>
      <feedbackstyle>1</feedbackstyle>
      <feedbackvariables>
        <text>simp:true
sdiag: invert(ans1).matA.ans1
isdiag: sdiag[1,2]^2+sdiag[2,1]^2
diagentries:set(sdiag[1,1],sdiag[2,2])
simp:false</text>
      </feedbackvariables>
      <node>
        <name>2</name>
        <description/>
        <answertest>AlgEquiv</answertest>
        <sans>isdiag</sans>
        <tans>0</tans>
        <testoptions/>
        <quiet>0</quiet>
        <truescoremode>+</truescoremode>
        <truescore>0.67</truescore>
        <truepenalty/>
        <truenextnode>-1</truenextnode>
        <trueanswernote>prt1-evals_on_diagonal_perfect_score</trueanswernote>
        <truefeedback format="html">
          <text><![CDATA[<p>Furthermore, Your matrix \(P={@ans1@}\) has the property that \(P^{-1}AP={@sdiag@}\), which is diagonal with the eigenvalues of \(A\) along the diagonal. Hence \(P\) is modal of \(A\). Well done.</p>]]></text>
        </truefeedback>
        <falsescoremode>-</falsescoremode>
        <falsescore>0</falsescore>
        <falsepenalty/>
        <falsenextnode>-1</falsenextnode>
        <falseanswernote>prt1-not_evals_on_diagonal</falseanswernote>
        <falsefeedback format="html">
          <text><![CDATA[<p>However, your matrix \(P={@ans1@}\) is not modal, as it does not satisfy the property that \(P^{-1}AP\) is diagonal. In your case \(PAP^{-1}={@ans1@}{@matA@}{@invert(ans1)@}={@sdiag@}\), which is not diagonal. Please try again.]]></text>
        </falsefeedback>
      </node>
      <node>
        <name>3</name>
        <description/>
        <answertest>AlgEquiv</answertest>
        <sans>determinant(ans1)</sans>
        <tans>0</tans>
        <testoptions/>
        <quiet>0</quiet>
        <truescoremode>+</truescoremode>
        <truescore>0</truescore>
        <truepenalty/>
        <truenextnode>-1</truenextnode>
        <trueanswernote>prt1-determinant_zero</trueanswernote>
        <truefeedback format="html">
          <text><![CDATA[<p>The column vectors of your Matrix \(P\) are not linearly independent, as \(\det(P)= 0\). Hence your matrix is not modal. Please try again.</p>]]></text>
        </truefeedback>
        <falsescoremode>+</falsescoremode>
        <falsescore>0.33</falsescore>
        <falsepenalty/>
        <falsenextnode>2</falsenextnode>
        <falseanswernote>prt1-determinant_not_zero</falseanswernote>
        <falsefeedback format="html">
          <text><![CDATA[<p>The column vectors of your Matrix \(P\) are linearly independent, as \(\det(P)\neq 0\).</p>]]></text>
        </falsefeedback>
      </node>
    </prt>
    <prt>
      <name>prt2</name>
      <value>1.0000000</value>
      <autosimplify>1</autosimplify>
      <feedbackstyle>1</feedbackstyle>
      <feedbackvariables>
        <text>simp:true
sdiag: invert(ans2).matB.ans2
isdiag: sdiag[1,2]^2+sdiag[1,3]^2+sdiag[2,1]^2+sdiag[2,3]^2+sdiag[3,1]^2+sdiag[3,2]^2
diagentries:set(sdiag[1,1],sdiag[2,2],sdiag[3,3])
simp:false</text>
      </feedbackvariables>
      <node>
        <name>0</name>
        <description/>
        <answertest>AlgEquiv</answertest>
        <sans>determinant(ans2)</sans>
        <tans>0</tans>
        <testoptions/>
        <quiet>0</quiet>
        <truescoremode>=</truescoremode>
        <truescore>0</truescore>
        <truepenalty/>
        <truenextnode>-1</truenextnode>
        <trueanswernote>prt2-determinant_zero</trueanswernote>
        <truefeedback format="html">
          <text><![CDATA[<p>The column vectors of your Matrix \(P\) are not linearly independent, as \(\det(P)= 0\). Hence your matrix is not modal. Please try again.</p>]]></text>
        </truefeedback>
        <falsescoremode>+</falsescoremode>
        <falsescore>0.33</falsescore>
        <falsepenalty/>
        <falsenextnode>2</falsenextnode>
        <falseanswernote>prt2-determinant_nonzer</falseanswernote>
        <falsefeedback format="html">
          <text><![CDATA[<p>The column vectors of your Matrix \(P\) are linearly independent, as \(\det(P)\neq 0\).</p>]]></text>
        </falsefeedback>
      </node>
      <node>
        <name>2</name>
        <description/>
        <answertest>AlgEquiv</answertest>
        <sans>isdiag</sans>
        <tans>0</tans>
        <testoptions/>
        <quiet>0</quiet>
        <truescoremode>+</truescoremode>
        <truescore>0.67</truescore>
        <truepenalty/>
        <truenextnode>-1</truenextnode>
        <trueanswernote>prt2-evals_on_diagonal_perfect_score</trueanswernote>
        <truefeedback format="html">
          <text><![CDATA[<p>Furthermore, your matrix \(P={@ans2@}\) has the property that \(P^{-1}AP={@sdiag@}\) is diagonal where the diagonal entries are exactly the eigenvalues of \(A\). Hence your \(P\) is modal of \(A\). Well done.</p>]]></text>
        </truefeedback>
        <falsescoremode>-</falsescoremode>
        <falsescore>0</falsescore>
        <falsepenalty/>
        <falsenextnode>-1</falsenextnode>
        <falseanswernote>prt2-not_evals_on_diagonal</falseanswernote>
        <falsefeedback format="html">
          <text><![CDATA[<p>However, your matrix \(P={@ans2@}\) is not modal, as it does not satisfy the property that \(P^{-1}AP\) is diagonal. In your case \(P^{-1}AP={@ans2@}{@matB@}{@invert(ans2)@}={@sdiag@}\), which is not diagonal. Please try again.]]></text>
        </falsefeedback>
      </node>
    </prt>
    <deployedseed>1355024501</deployedseed>
    <deployedseed>659645835</deployedseed>
    <deployedseed>2141970867</deployedseed>
    <deployedseed>1308504826</deployedseed>
    <deployedseed>1100536150</deployedseed>
    <deployedseed>1262812987</deployedseed>
    <deployedseed>110172828</deployedseed>
    <qtest>
      <testcase>1</testcase>
      <description/>
      <testinput>
        <name>ans1</name>
        <value>p1</value>
      </testinput>
      <testinput>
        <name>ans2</name>
        <value>p2</value>
      </testinput>
      <expected>
        <name>prt1</name>
        <expectedscore>1.0000000</expectedscore>
        <expectedpenalty>0.0000000</expectedpenalty>
        <expectedanswernote>prt1-evals_on_diagonal_perfect_score</expectedanswernote>
      </expected>
      <expected>
        <name>prt2</name>
        <expectedscore>1.0000000</expectedscore>
        <expectedpenalty>0.0000000</expectedpenalty>
        <expectedanswernote>prt2-evals_on_diagonal_perfect_score</expectedanswernote>
      </expected>
    </qtest>
    <qtest>
      <testcase>2</testcase>
      <description/>
      <testinput>
        <name>ans1</name>
        <value>matrix([0,0],[1,0])</value>
      </testinput>
      <testinput>
        <name>ans2</name>
        <value>matrix([0,0,0],[1,0,0],[0,0,0])</value>
      </testinput>
      <expected>
        <name>prt1</name>
        <expectedscore>0.0000000</expectedscore>
        <expectedpenalty>0.1000000</expectedpenalty>
        <expectedanswernote>prt1-determinant_zero</expectedanswernote>
      </expected>
      <expected>
        <name>prt2</name>
        <expectedscore>0.0000000</expectedscore>
        <expectedpenalty>0.1000000</expectedpenalty>
        <expectedanswernote>prt2-determinant_zero</expectedanswernote>
      </expected>
    </qtest>
    <qtest>
      <testcase>3</testcase>
      <description/>
      <testinput>
        <name>ans1</name>
        <value>matrix([1,0],[0,1])</value>
      </testinput>
      <testinput>
        <name>ans2</name>
        <value>matrix([1,0,0],[0,1,0],[0,0,1])</value>
      </testinput>
      <expected>
        <name>prt1</name>
        <expectedscore>0.3300000</expectedscore>
        <expectedpenalty>0.1000000</expectedpenalty>
        <expectedanswernote>prt1-not_evals_on_diagonal</expectedanswernote>
      </expected>
      <expected>
        <name>prt2</name>
        <expectedscore>0.3300000</expectedscore>
        <expectedpenalty>0.1000000</expectedpenalty>
        <expectedanswernote>prt2-not_evals_on_diagonal</expectedanswernote>
      </expected>
    </qtest>
  </question>
</quiz>
