<?xml version="1.0" encoding="UTF-8"?>
<quiz>
  <question type="stack">
    <name>
      <text>test_5_cubic_spline</text>
    </name>
    <questiontext format="html">
      <text><![CDATA[<p>Consider the real function</p><p>\[ f(x) :=\left\{ \begin{array}{ll} {@f0@} &amp; \text{for } x\leq {@x0@}, \\ p(x) &amp; \text{for } {@x0@} &lt; x &lt; {@x1@}, \\ {@f1@} &amp; \text{for } {@x1@}\leq x.\end{array} \right. \]</p><p>{@plot(pg,[x,(x0-3),(x1+3)],[y,-3,3])@}</p><p>Find the cubic polynomial \(p(x)\) which makes \(f(x)\) continuously differentiable. </p><p>\(p(x)=\)[[input:ans1]]</p><div>[[validation:ans1]]</div>]]></text>
    </questiontext>
    <generalfeedback format="html">
      <text><![CDATA[<p>First we need to find the information which \(p(x)\) needs to satisfy.  This is</p><p>\[ p({@x0@})={@subst(x=x0,f0)@}.\]</p><p>\[ p({@x1@})={@subst(x=x1,f1)@}.\]</p><p>\[ p'({@x0@})={@subst(x=x0,diff(f0,x))@}.\]</p><p>\[ p'({@x1@})={@subst(x=x1,diff(f1,x))@}.\]</p><p>If we define \(p(x)\) to be the cubic </p><p>\[ p(x) = a_3 x^3 + a_2 x^2 + a_1 x + a_0,\]</p><p>We then set up the matrix equation</p><p>\[ {@CS@} {@CV@} = {@CT@} \]</p><p>Solving this gives the coefficients, from which we get the polynomial.</p><p>{@ta@}.</p>]]></text>
    </generalfeedback>
    <defaultgrade>1</defaultgrade>
    <penalty>0</penalty>
    <hidden>0</hidden>
    <idnumber/>
    <stackversion>
      <text/>
    </stackversion>
    <questionvariables>
      <text><![CDATA[x0 : -1;
f0 : 1;
x1 : 2;
f1 : sin(%pi*x)
/* Note, we should really use inf instead of 1000 here, but Maxima gives up plotting with the options used by STACK */
pg:if x<x0 then f0 else if x<x1 then 1000 else f1;
CS:matrix([1,x0,x0^2,x0^3],[0,1,2*x0,3*x0^2],[1,x1,x1^2,x1^3],[0,1,2*x1,3*x1^2])
CT:transpose(matrix([ev(f0,x=x0),subst(x=x0,diff(f0,x)),ev(f1,x=x1),subst(x=x1,diff(f1,x))]));
CV:transpose(matrix([a0,a1,a2,a3]));
CS2:invert(CS).CT;
ta : matrix([1,x,x^2,x^3]).CS2;]]></text>
    </questionvariables>
    <specificfeedback format="html">
      <text><![CDATA[<p>[[feedback:prt1]]</p>]]></text>
    </specificfeedback>
    <questionnote format="html">
      <text>{@ta@}</text>
    </questionnote>
    <questiondescription format="html">
      <text/>
    </questiondescription>
    <questionsimplify>1</questionsimplify>
    <assumepositive>0</assumepositive>
    <assumereal>0</assumereal>
    <prtcorrect format="html">
      <text><![CDATA[<p>Correct answer, well done.</p>]]></text>
    </prtcorrect>
    <prtpartiallycorrect format="html">
      <text><![CDATA[<p>Your answer is partially correct.</p>]]></text>
    </prtpartiallycorrect>
    <prtincorrect format="html">
      <text><![CDATA[<p>Incorrect answer.</p>]]></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>algebraic</type>
      <tans>ta</tans>
      <boxsize>15</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>1</showvalidation>
      <options/>
    </input>
    <prt>
      <name>prt1</name>
      <value>1.0000000</value>
      <autosimplify>1</autosimplify>
      <feedbackstyle>1</feedbackstyle>
      <feedbackvariables>
        <text><![CDATA[anspt : if (x>x0 and x<x1) then ans1 else 1000;]]></text>
      </feedbackvariables>
      <node>
        <name>0</name>
        <description/>
        <answertest>AlgEquiv</answertest>
        <sans>subst(x=x0,ans1)</sans>
        <tans>subst(x=x0,f0)</tans>
        <testoptions/>
        <quiet>0</quiet>
        <truescoremode>+</truescoremode>
        <truescore>0.2500000</truescore>
        <truepenalty/>
        <truenextnode>1</truenextnode>
        <trueanswernote>prt1-1-T</trueanswernote>
        <truefeedback format="html">
          <text/>
        </truefeedback>
        <falsescoremode>=</falsescoremode>
        <falsescore>0.0000000</falsescore>
        <falsepenalty/>
        <falsenextnode>1</falsenextnode>
        <falseanswernote>prt1-1-F</falseanswernote>
        <falsefeedback format="html">
          <text><![CDATA[<p>Your answer does not satisfy \({@p(x0)=subst(x=x0,f0)@}\).</p>]]></text>
        </falsefeedback>
      </node>
      <node>
        <name>1</name>
        <description/>
        <answertest>AlgEquiv</answertest>
        <sans>subst(x=x1,ans1)</sans>
        <tans>subst(x=x1,f1)</tans>
        <testoptions/>
        <quiet>0</quiet>
        <truescoremode>+</truescoremode>
        <truescore>0.2500000</truescore>
        <truepenalty/>
        <truenextnode>2</truenextnode>
        <trueanswernote>prt1-2-T</trueanswernote>
        <truefeedback format="html">
          <text/>
        </truefeedback>
        <falsescoremode>+</falsescoremode>
        <falsescore>0.0000000</falsescore>
        <falsepenalty/>
        <falsenextnode>2</falsenextnode>
        <falseanswernote>prt1-2-F</falseanswernote>
        <falsefeedback format="html">
          <text><![CDATA[<p>Your answer does not satisfy \({@p(x1)=subst(x=x1,f1)@}\).</p>]]></text>
        </falsefeedback>
      </node>
      <node>
        <name>2</name>
        <description/>
        <answertest>AlgEquiv</answertest>
        <sans>subst(x=x0,diff(ans1,x))</sans>
        <tans>subst(x=x0,diff(f0,x))</tans>
        <testoptions/>
        <quiet>0</quiet>
        <truescoremode>+</truescoremode>
        <truescore>0.2500000</truescore>
        <truepenalty/>
        <truenextnode>3</truenextnode>
        <trueanswernote>prt1-3-T</trueanswernote>
        <truefeedback format="html">
          <text/>
        </truefeedback>
        <falsescoremode>+</falsescoremode>
        <falsescore>0.0000000</falsescore>
        <falsepenalty/>
        <falsenextnode>3</falsenextnode>
        <falseanswernote>prt1-3-F</falseanswernote>
        <falsefeedback format="html">
          <text><![CDATA[<p>Your answer does not satisfy \(p'({@x0@})={@subst(x=x0,diff(f0,x))@}\).</p>]]></text>
        </falsefeedback>
      </node>
      <node>
        <name>3</name>
        <description/>
        <answertest>AlgEquiv</answertest>
        <sans>subst(x=x1,diff(ans1,x))</sans>
        <tans>subst(x=x1,diff(f1,x))</tans>
        <testoptions/>
        <quiet>0</quiet>
        <truescoremode>+</truescoremode>
        <truescore>0.2500000</truescore>
        <truepenalty/>
        <truenextnode>4</truenextnode>
        <trueanswernote>prt1-4-T</trueanswernote>
        <truefeedback format="html">
          <text/>
        </truefeedback>
        <falsescoremode>+</falsescoremode>
        <falsescore>0.0000000</falsescore>
        <falsepenalty/>
        <falsenextnode>4</falsenextnode>
        <falseanswernote>prt1-4-F</falseanswernote>
        <falsefeedback format="html">
          <text><![CDATA[<p>Your answer does not satisfy \(p'({@x1@})={@subst(x=x1,diff(f1,x))@}\).</p>]]></text>
        </falsefeedback>
      </node>
      <node>
        <name>4</name>
        <description/>
        <answertest>AlgEquiv</answertest>
        <sans>degree(ans1,x)</sans>
        <tans>3</tans>
        <testoptions/>
        <quiet>0</quiet>
        <truescoremode>+</truescoremode>
        <truescore>0.0000000</truescore>
        <truepenalty/>
        <truenextnode>5</truenextnode>
        <trueanswernote>prt1-5-T</trueanswernote>
        <truefeedback format="html">
          <text/>
        </truefeedback>
        <falsescoremode>=</falsescoremode>
        <falsescore>0.0000000</falsescore>
        <falsepenalty/>
        <falsenextnode>5</falsenextnode>
        <falseanswernote>prt1-5-F</falseanswernote>
        <falsefeedback format="html">
          <text><![CDATA[<p>Your answer is not a cubic!</p>]]></text>
        </falsefeedback>
      </node>
      <node>
        <name>5</name>
        <description/>
        <answertest>AlgEquiv</answertest>
        <sans>ans1</sans>
        <tans>ta</tans>
        <testoptions/>
        <quiet>0</quiet>
        <truescoremode>=</truescoremode>
        <truescore>1.0000000</truescore>
        <truepenalty/>
        <truenextnode>-1</truenextnode>
        <trueanswernote>prt1-6-T</trueanswernote>
        <truefeedback format="html">
          <text/>
        </truefeedback>
        <falsescoremode>+</falsescoremode>
        <falsescore>0.0000000</falsescore>
        <falsepenalty/>
        <falsenextnode>-1</falsenextnode>
        <falseanswernote>prt1-6-F</falseanswernote>
        <falsefeedback format="html">
          <text><![CDATA[<p>Your answer is plotted below, although part of your graph might appear out of range of the plot!</p><p>{@plot([pg,anspt],[x,(x0-3),(x1+3)],[y,-3,3])@}</p>]]></text>
        </falsefeedback>
      </node>
    </prt>
    <qtest>
      <testcase>1</testcase>
      <description/>
      <testinput>
        <name>ans1</name>
        <value>ta</value>
      </testinput>
      <expected>
        <name>prt1</name>
        <expectedscore>1.0000000</expectedscore>
        <expectedpenalty>0.0000000</expectedpenalty>
        <expectedanswernote>prt1-6-T</expectedanswernote>
      </expected>
    </qtest>
    <qtest>
      <testcase>2</testcase>
      <description/>
      <testinput>
        <name>ans1</name>
        <value>x^2</value>
      </testinput>
      <expected>
        <name>prt1</name>
        <expectedscore>0.0000000</expectedscore>
        <expectedpenalty>0.0000000</expectedpenalty>
        <expectedanswernote>prt1-6-F</expectedanswernote>
      </expected>
    </qtest>
    <qtest>
      <testcase>3</testcase>
      <description/>
      <testinput>
        <name>ans1</name>
        <value>(2*%pi/9+2/27)*x^3-x^2/9+(-2*%pi/3-4/9)*x-4*%pi/9+20/27</value>
      </testinput>
      <expected>
        <name>prt1</name>
        <expectedscore>0.7500000</expectedscore>
        <expectedpenalty>0.0000000</expectedpenalty>
        <expectedanswernote>prt1-6-F</expectedanswernote>
      </expected>
    </qtest>
  </question>
</quiz>
