<?xml version="1.0" encoding="UTF-8"?>
<quiz>
  <question type="stack">
    <name>
      <text>LU Decomposition</text>
    </name>
    <questiontext format="html">
      <text><![CDATA[<p>Find an \(LU\) decomposition for the matrix \[ A = {@AA@} \] <strong>Do not</strong> use pivoting.</p>
<table>
<tbody>
<tr>
<td>\(L = \)</td>
<td>[[input:stu_L]]</td>
<td>[[validation:stu_L]] [[feedback:prt_L]]</td>
</tr>
</tbody>
</table>
<p></p>
<table>
<tbody>
<tr>
<td>\(U = \)</td>
<td>[[input:stu_U]]</td>
<td>[[validation:stu_U]] [[feedback:prt_U]]</td>
</tr>
</tbody>
</table>
<p>[[feedback:prt_LU]]<br>[[hint title="How might I check my answer?"]]</p>
<p>Your \(L\) should be lower triangular with ones on the diagonal and \(U\) should be upper triangular. To check that they are correct, multiply \(LU\) and check that you get \(A\).</p>
<p>[[/hint]]</p>]]></text>
    </questiontext>
    <generalfeedback format="html">
      <text/>
    </generalfeedback>
    <defaultgrade>1</defaultgrade>
    <penalty>0.5</penalty>
    <hidden>0</hidden>
    <idnumber/>
    <stackversion>
      <text>2025042500</text>
    </stackversion>
    <questionvariables>
      <text><![CDATA[stack_linear_algebra_declare(true);
stack_include_contrib("matrix.mac");
stack_include_contrib("rand_matrix.mac");

sol_L: rand_tril(3,3,4);
sol_L: setdiagmx(1,sol_L);
sol_U: rand_triu(3,3,4);

AA: sol_L . sol_U;]]></text>
    </questionvariables>
    <specificfeedback format="html">
      <text/>
    </specificfeedback>
    <questionnote format="moodle_auto_format">
      <text>\({@sol_L@}{@sol_U@} = {@AA@}\)</text>
    </questionnote>
    <questiondescription format="html">
      <text/>
    </questiondescription>
    <questionsimplify>1</questionsimplify>
    <assumepositive>0</assumepositive>
    <assumereal>0</assumereal>
    <prtcorrect format="html">
      <text><![CDATA[<p><i class="fa fa-check"></i> Correct answer, well done.</p>]]></text>
    </prtcorrect>
    <prtpartiallycorrect format="html">
      <text><![CDATA[<p><i class="fa fa-adjust"></i> Your answer is partially correct.</p>]]></text>
    </prtpartiallycorrect>
    <prtincorrect format="html">
      <text><![CDATA[<p><i class="fa fa-times"></i> Incorrect answer.</p>]]></text>
    </prtincorrect>
    <decimals>.</decimals>
    <scientificnotation>*10</scientificnotation>
    <multiplicationsign>onum</multiplicationsign>
    <sqrtsign>1</sqrtsign>
    <complexno>i</complexno>
    <inversetrig>cos-1</inversetrig>
    <logicsymbol>lang</logicsymbol>
    <matrixparens>[</matrixparens>
    <isbroken>0</isbroken>
    <variantsselectionseed/>
    <input>
      <name>stu_L</name>
      <type>matrix</type>
      <tans>sol_L</tans>
      <boxsize>2</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>stu_U</name>
      <type>matrix</type>
      <tans>sol_U</tans>
      <boxsize>2</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>prt_L</name>
      <value>0.0000000</value>
      <autosimplify>1</autosimplify>
      <feedbackstyle>0</feedbackstyle>
      <feedbackvariables>
        <text/>
      </feedbackvariables>
      <node>
        <name>0</name>
        <description/>
        <answertest>AlgEquiv</answertest>
        <sans>stu_L</sans>
        <tans>sol_L</tans>
        <testoptions/>
        <quiet>0</quiet>
        <truescoremode>=</truescoremode>
        <truescore>1</truescore>
        <truepenalty/>
        <truenextnode>-1</truenextnode>
        <trueanswernote>prt_L-1-T</trueanswernote>
        <truefeedback format="html">
          <text/>
        </truefeedback>
        <falsescoremode>=</falsescoremode>
        <falsescore>0</falsescore>
        <falsepenalty/>
        <falsenextnode>-1</falsenextnode>
        <falseanswernote>prt_L-1-F</falseanswernote>
        <falsefeedback format="html">
          <text/>
        </falsefeedback>
      </node>
    </prt>
    <prt>
      <name>prt_LU</name>
      <value>1.0000000</value>
      <autosimplify>1</autosimplify>
      <feedbackstyle>1</feedbackstyle>
      <feedbackvariables>
        <text/>
      </feedbackvariables>
      <node>
        <name>0</name>
        <description/>
        <answertest>AlgEquiv</answertest>
        <sans>trilp(stu_L)</sans>
        <tans>true</tans>
        <testoptions/>
        <quiet>0</quiet>
        <truescoremode>=</truescoremode>
        <truescore>0</truescore>
        <truepenalty/>
        <truenextnode>1</truenextnode>
        <trueanswernote>prt_LU-1-T</trueanswernote>
        <truefeedback format="html">
          <text/>
        </truefeedback>
        <falsescoremode>-</falsescoremode>
        <falsescore>1</falsescore>
        <falsepenalty/>
        <falsenextnode>1</falsenextnode>
        <falseanswernote>prt_LU-1-F</falseanswernote>
        <falsefeedback format="html">
          <text><![CDATA[<p>Your \(L\) is not lower triangular.</p>]]></text>
        </falsefeedback>
      </node>
      <node>
        <name>1</name>
        <description/>
        <answertest>AlgEquiv</answertest>
        <sans>diag_entries(stu_L)</sans>
        <tans>[1,1,1]</tans>
        <testoptions/>
        <quiet>1</quiet>
        <truescoremode>+</truescoremode>
        <truescore>0</truescore>
        <truepenalty/>
        <truenextnode>2</truenextnode>
        <trueanswernote>prt_LU-2-T</trueanswernote>
        <truefeedback format="html">
          <text/>
        </truefeedback>
        <falsescoremode>-</falsescoremode>
        <falsescore>1</falsescore>
        <falsepenalty/>
        <falsenextnode>2</falsenextnode>
        <falseanswernote>prt_LU-2-F</falseanswernote>
        <falsefeedback format="html">
          <text><![CDATA[<p dir="ltr" style="text-align: left;">Your \(L\) does not have only ones on the diagonal.</p>]]></text>
        </falsefeedback>
      </node>
      <node>
        <name>2</name>
        <description/>
        <answertest>AlgEquiv</answertest>
        <sans>triup(stu_U)</sans>
        <tans>true</tans>
        <testoptions/>
        <quiet>0</quiet>
        <truescoremode>+</truescoremode>
        <truescore>0</truescore>
        <truepenalty/>
        <truenextnode>3</truenextnode>
        <trueanswernote>prt_LU-3-T</trueanswernote>
        <truefeedback format="html">
          <text/>
        </truefeedback>
        <falsescoremode>-</falsescoremode>
        <falsescore>1</falsescore>
        <falsepenalty/>
        <falsenextnode>3</falsenextnode>
        <falseanswernote>prt_LU-3-F</falseanswernote>
        <falsefeedback format="html">
          <text><![CDATA[<p dir="ltr" style="text-align: left;">Your \(U\) is not upper triangular</p>]]></text>
        </falsefeedback>
      </node>
      <node>
        <name>3</name>
        <description/>
        <answertest>AlgEquiv</answertest>
        <sans>stu_L . stu_U</sans>
        <tans>AA</tans>
        <testoptions/>
        <quiet>1</quiet>
        <truescoremode>+</truescoremode>
        <truescore>1</truescore>
        <truepenalty/>
        <truenextnode>-1</truenextnode>
        <trueanswernote>prt_LU-4-T</trueanswernote>
        <truefeedback format="html">
          <text><![CDATA[<p dir="ltr" style="text-align: left;">Your \(L\) and \(U\) multiply together to get \(A\).</p>]]></text>
        </truefeedback>
        <falsescoremode>=</falsescoremode>
        <falsescore>0</falsescore>
        <falsepenalty/>
        <falsenextnode>-1</falsenextnode>
        <falseanswernote>prt_LU-4-F</falseanswernote>
        <falsefeedback format="html">
          <text><![CDATA[<p dir="ltr" style="text-align: left;">Your \(L\) and \(U\) multiply together to give \({@stu_L@}{@stu_U@} = {@sremove("\\]",sremove("\\[",split(ATAlgEquiv(ev(stu_L.stu_U,expand,simp),AA)[4],"!")[3]))@} \neq {@AA@}\).</p>]]></text>
        </falsefeedback>
      </node>
    </prt>
    <prt>
      <name>prt_U</name>
      <value>0.0000000</value>
      <autosimplify>1</autosimplify>
      <feedbackstyle>0</feedbackstyle>
      <feedbackvariables>
        <text/>
      </feedbackvariables>
      <node>
        <name>0</name>
        <description/>
        <answertest>AlgEquiv</answertest>
        <sans>stu_U</sans>
        <tans>sol_U</tans>
        <testoptions/>
        <quiet>0</quiet>
        <truescoremode>=</truescoremode>
        <truescore>1</truescore>
        <truepenalty/>
        <truenextnode>-1</truenextnode>
        <trueanswernote>prt_U-1-T</trueanswernote>
        <truefeedback format="html">
          <text/>
        </truefeedback>
        <falsescoremode>=</falsescoremode>
        <falsescore>0</falsescore>
        <falsepenalty/>
        <falsenextnode>-1</falsenextnode>
        <falseanswernote>prt_U-1-F</falseanswernote>
        <falsefeedback format="html">
          <text/>
        </falsefeedback>
      </node>
    </prt>
    <deployedseed>1861305182</deployedseed>
    <deployedseed>1786259148</deployedseed>
    <deployedseed>782859426</deployedseed>
    <deployedseed>512066017</deployedseed>
    <deployedseed>1177681064</deployedseed>
    <deployedseed>1955501925</deployedseed>
    <deployedseed>746697987</deployedseed>
    <deployedseed>2116685166</deployedseed>
    <qtest>
      <testcase>1</testcase>
      <description>Test case assuming the teacher's input gets full marks.</description>
      <testinput>
        <name>stu_L</name>
        <value>sol_L</value>
      </testinput>
      <testinput>
        <name>stu_U</name>
        <value>sol_U</value>
      </testinput>
      <expected>
        <name>prt_LU</name>
        <expectedscore>1.0000000</expectedscore>
        <expectedpenalty>0.0000000</expectedpenalty>
        <expectedanswernote>prt_LU-4-T</expectedanswernote>
      </expected>
    </qtest>
    <qtest>
      <testcase>2</testcase>
      <description/>
      <testinput>
        <name>stu_L</name>
        <value>ident(3)</value>
      </testinput>
      <testinput>
        <name>stu_U</name>
        <value>AA</value>
      </testinput>
      <expected>
        <name>prt_LU</name>
        <expectedscore>0.0000000</expectedscore>
        <expectedpenalty/>
        <expectedanswernote>prt_LU-4-T</expectedanswernote>
      </expected>
    </qtest>
    <qtest>
      <testcase>3</testcase>
      <description/>
      <testinput>
        <name>stu_L</name>
        <value>AA</value>
      </testinput>
      <testinput>
        <name>stu_U</name>
        <value>ident(3)</value>
      </testinput>
      <expected>
        <name>prt_LU</name>
        <expectedscore>0.0000000</expectedscore>
        <expectedpenalty/>
        <expectedanswernote>prt_LU-4-T</expectedanswernote>
      </expected>
    </qtest>
  </question>
</quiz>
