<?xml version="1.0" encoding="UTF-8"?>
<quiz>
  <question type="stack">
    <name>
      <text>22.2.4.1 1st order diff Exercise (a)</text>
    </name>
    <questiontext format="html">
      <text><![CDATA[<p>Solve by decoupling the following first order system:
<p>\(\dfrac{d \underline{x}}{dt}=A\underline{x}\) where \(A={@matA@}, \underline{x}(0)={@init_a@}\).</p>
\(\underline{x}=\) [[input:ans1]] [[validation:ans1]] [[feedback:prt1]]]]></text>
    </questiontext>
    <generalfeedback format="html">
      <text><![CDATA[We calculate that {@matA@} has eigenvalues {@eval_a1@} and {@eval_a2@}, with corresponding eigenvectors \({@evec_a1@}^T\) and \({@evec_a2@}^T\). Hence we make the substitution \(\underline{x}=P\underline{y}\) with \(P={@p_a@}\) to get \(\dot{\underline{y}}=D\underline{y}\), where \(D={@matD_a@}\). <br>This is then a decoupled equation, with general solution \(\underline{y}={@soly_1@}\). To get the solution in terms of \(\underline{x}\), we use the equation \(\underline{x}=P\underline{y}={@p_a@}{@soly_1@}={@sol1_gen@}\). 
<br>We then find the particular solution by letting \(t=0\) and solving \(\underline{x}(0)={@sol1_subst@}={@init_a@}\). This is solved by \({@kl[1][1]@},{@kl[1][2]@}\), leading to the specific solution \(\underline{x}={@sol1@}\).]]></text>
    </generalfeedback>
    <defaultgrade>1</defaultgrade>
    <penalty>0.1</penalty>
    <hidden>0</hidden>
    <idnumber/>
    <stackversion>
      <text>2024072400</text>
    </stackversion>
    <questionvariables>
      <text>/*part (a)*/
/*I find it easier to pick A from a list of nice matrices. */
simp:true;

matrices_a:[matrix([3,4],[4,-3]),matrix([5,-4],[6,-5]),matrix([1,2],[3,6]),matrix([5,-1],[3,1]),matrix([-2,-3],[4,5]),matrix([7,-4],[6,-3]),matrix([7,-1],[3,3]),matrix([2,3],[4,-2]),matrix([1,4],[2,-1])];
index:rand(9)+1;
matA:matrices_a[index];
evecs_a:eigenvectors(matA);
evals_a:eigenvalues(matA);
evec_a1:evecs_a[2][1][1];
evec_a2:evecs_a[2][2][1];

eval_a1:evals_a[1][1];
eval_a2:evals_a[1][2];

/*Modal matrix*/
p_a:matrix([evec_a1[1],evec_a2[1]],[evec_a1[2],evec_a2[2]]);
matD_a:matrix([eval_a1,0],[0,eval_a2]);

/*Select initial conditions*/
xa0:rand_with_prohib(-4,4,[0]);
xa1:rand_with_prohib(-4,4,[0,xa0]);
init_a:matrix([xa0],[xa1]);

/*Deduce the solution by finding the general form...*/
soly_1:matrix([K*e^(eval_a1*t)],[L*e^(eval_a2*t)]);
sol1_gen:p_a.soly_1;
/*...Deducing a particular solution by substituting t=0...*/
sol1_subst:subst(t=0,sol1_gen);
/*...finding K,L s.t. it equals the initial conditions...*/
kl:solve([sol1_subst[1,1]=init_a[1,1],sol1_subst[2,1]=init_a[2,1]],[K,L]);
/*... and substituting back into the general form*/
sol1:subst(kl[1][1],subst(kl[1][2],sol1_gen));

/*Other variables used for testing*/
null2:matrix([0],[0]);
null3:matrix([0],[0],[0]);</text>
    </questionvariables>
    <specificfeedback format="html">
      <text/>
    </specificfeedback>
    <questionnote format="moodle_auto_format">
      <text><![CDATA[\(A={@matA@}, P={@p_a@}\), evals:\({@eval_a1@},{@eval_a2@}\),solution\(= {@sol1@}\)<br>]]></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>sol1</tans>
      <boxsize>18</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>ans1_prime:matrix([diff(ans1[1,1],t)],[diff(ans1[2,1],t)])
ans1_subst:subst(t=0,ans1)</text>
      </feedbackvariables>
      <node>
        <name>2</name>
        <description/>
        <answertest>AlgEquiv</answertest>
        <sans>ans1_prime</sans>
        <tans>matA.ans1</tans>
        <testoptions>t</testoptions>
        <quiet>1</quiet>
        <truescoremode>=</truescoremode>
        <truescore>0.5</truescore>
        <truepenalty/>
        <truenextnode>3</truenextnode>
        <trueanswernote>x_correct</trueanswernote>
        <truefeedback format="html">
          <text><![CDATA[Your answer satisfies \(\dot{\underline{x}}= A\underline{x}\).<br>]]></text>
        </truefeedback>
        <falsescoremode>-</falsescoremode>
        <falsescore>0</falsescore>
        <falsepenalty/>
        <falsenextnode>-1</falsenextnode>
        <falseanswernote>x_wrong</falseanswernote>
        <falsefeedback format="html">
          <text><![CDATA[Your answer should satisfy \(\dot{\underline{x}}= A\underline{x}\). In your case,
<br>\(\dot{\underline{x}}={@ans1_prime@}\),
<br>\(A\underline{x}={@matA.ans1@}\).
<br>Please try again.]]></text>
        </falsefeedback>
      </node>
      <node>
        <name>3</name>
        <description/>
        <answertest>AlgEquiv</answertest>
        <sans>ans1_subst</sans>
        <tans>init_a</tans>
        <testoptions/>
        <quiet>1</quiet>
        <truescoremode>+</truescoremode>
        <truescore>0.5</truescore>
        <truepenalty/>
        <truenextnode>-1</truenextnode>
        <trueanswernote>prt1-4-T</trueanswernote>
        <truefeedback format="html">
          <text><![CDATA[Your answer satisfies \(\underline{x}(0)={@init_a@}\).<br>
Hence your answer is correct. Well done.]]></text>
        </truefeedback>
        <falsescoremode>-</falsescoremode>
        <falsescore>0</falsescore>
        <falsepenalty/>
        <falsenextnode>4</falsenextnode>
        <falseanswernote>prt1-4-F</falseanswernote>
        <falsefeedback format="html">
          <text/>
        </falsefeedback>
      </node>
      <node>
        <name>4</name>
        <description/>
        <answertest>SubstEquiv</answertest>
        <sans>ans1</sans>
        <tans>sol1_gen</tans>
        <testoptions/>
        <quiet>1</quiet>
        <truescoremode>+</truescoremode>
        <truescore>0</truescore>
        <truepenalty/>
        <truenextnode>-1</truenextnode>
        <trueanswernote>prt1-5-T</trueanswernote>
        <truefeedback format="html">
          <text><![CDATA[However, it looks like you forgot to use the initial conditions to find a specific solution. <br>Please try again.]]></text>
        </truefeedback>
        <falsescoremode>-</falsescoremode>
        <falsescore>0</falsescore>
        <falsepenalty/>
        <falsenextnode>-1</falsenextnode>
        <falseanswernote>prt1-5-F</falseanswernote>
        <falsefeedback format="html">
          <text><![CDATA[However, your answer should satisfy \(\underline{x}(0)={@init_a@}\), when in your case \(\underline{x}(0)={@ans1_subst@}\). <br>Please try again.]]></text>
        </falsefeedback>
      </node>
    </prt>
    <deployedseed>1481223745</deployedseed>
    <deployedseed>741675709</deployedseed>
    <deployedseed>536262777</deployedseed>
    <deployedseed>1749166373</deployedseed>
    <deployedseed>938872589</deployedseed>
    <deployedseed>1040050332</deployedseed>
    <deployedseed>1775712125</deployedseed>
    <qtest>
      <testcase>1</testcase>
      <description/>
      <testinput>
        <name>ans1</name>
        <value>sol1</value>
      </testinput>
      <expected>
        <name>prt1</name>
        <expectedscore>1.0000000</expectedscore>
        <expectedpenalty>0.0000000</expectedpenalty>
        <expectedanswernote>prt1-4-T</expectedanswernote>
      </expected>
    </qtest>
    <qtest>
      <testcase>2</testcase>
      <description/>
      <testinput>
        <name>ans1</name>
        <value>sol1_gen</value>
      </testinput>
      <expected>
        <name>prt1</name>
        <expectedscore>0.5000000</expectedscore>
        <expectedpenalty>0.1000000</expectedpenalty>
        <expectedanswernote>prt1-5-T</expectedanswernote>
      </expected>
    </qtest>
    <qtest>
      <testcase>3</testcase>
      <description/>
      <testinput>
        <name>ans1</name>
        <value>null2</value>
      </testinput>
      <expected>
        <name>prt1</name>
        <expectedscore>0.5000000</expectedscore>
        <expectedpenalty>0.1000000</expectedpenalty>
        <expectedanswernote>prt1-5-F</expectedanswernote>
      </expected>
    </qtest>
  </question>
</quiz>
