<?xml version="1.0" encoding="UTF-8"?>
<quiz>
  <question type="stack">
    <name>
      <text>HELM 31.4 E2 Newton-Raphson</text>
    </name>
    <questiontext format="markdown">
      <text><![CDATA[**31.4 E2 Newton-Raphson**

Consider a simple electronic circuit with an input voltage \\\(V_{in}\\\), a resistor \\\(R\\\) and a diode with saturation current \\\(I_s\\\) and thermal voltage \\\(V_{th}\\\) can be shown that the voltage \\\(V_D=x\\\) across the diode can be found as the single
positive zero of

\\\[ {@'f('x)=f(x)@}.\\\]

Calculate the derivative

\\\(f'(x)=\\\) [[input:S_df]] [[validation:S_df]] [[feedback:df]]

Find the zero for the following data:

- \\\({@V_in=ev(V_in, v)@}\,\rm{V}\\\)
- \\\({@R=ev(R, v)@}\,\rm{\Omega}\\\)
- \\\({@I_s=scientific_notation(ev(I_s, v),1)@}\,\rm{A}\\\)
- \\\({@V_th=ev(V_th, v)@}\,\rm{V}\\\)

<p>{@plot(ev(f(x),v), [x,0,0.8], [y,float(ev(f(0),v)),0.01], [xlabel,"x in V"], [ylabel,"f(x) in A"])@}</p>

Use the Newton-Raphson method with an initial value of {@'x0=x0@}. Perform the first two iterations:

\\\(x^{(1)}/\rm V=\\\) [[input:S_x1]], [[validation:S_x1]] [[feedback:x1]]

\\\(x^{(2)}/\rm V=\\\) [[input:S_x2]], [[validation:S_x2]] [[feedback:x2]]]]></text>
    </questiontext>
    <generalfeedback format="markdown">
      <text/>
    </generalfeedback>
    <defaultgrade>1</defaultgrade>
    <penalty>0.1</penalty>
    <hidden>0</hidden>
    <idnumber/>
    <stackversion>
      <text>2024072400</text>
    </stackversion>
    <questionvariables>
      <text><![CDATA[simp:false;
f(x):=I_s*exp(x/V_th)-(V_in-x)/R;
simp:true;
df(x):=at(diff(f(xx),xx),xx=x);
vv: [
 [I_s=10^(-14), R=1000, V_in= 2, V_th=0.026, x0=0.75],
 [I_s=10^(-13), R=1100, V_in= 3, V_th=0.028, x0=0.7],
 [I_s=10^(-12), R=900,  V_in= 2, V_th=0.027, x0=0.65],
 [I_s=10^(-14), R=1100, V_in= 2, V_th=0.026, x0=0.7],
 [I_s=2*10^(-14), R=900, V_in= 2, V_th=0.027, x0=0.75],
 [I_s=3*10^(-14), R=1000, V_in= 3, V_th=0.025, x0=0.65]
];

v: rand(vv)


x0: ev(x0,v);
x1: x0-ev(f(x0)/df(x0), v);
x2: x1-ev(f(x1)/df(x1), v);


stack_include("https://raw.githubusercontent.com/mkraska/meclib/main/Maxima/fb_value_EN.mac");]]></text>
    </questionvariables>
    <specificfeedback format="markdown">
      <text/>
    </specificfeedback>
    <questionnote format="moodle_auto_format">
      <text>{@v@}</text>
    </questionnote>
    <questiondescription format="markdown">
      <text/>
    </questiondescription>
    <questionsimplify>1</questionsimplify>
    <assumepositive>0</assumepositive>
    <assumereal>0</assumereal>
    <prtcorrect format="markdown">
      <text>Richtige Antwort, gut gemacht!</text>
    </prtcorrect>
    <prtpartiallycorrect format="markdown">
      <text>Ihre Antwort ist teilweise korrekt.</text>
    </prtpartiallycorrect>
    <prtincorrect format="markdown">
      <text>Falsche Antwort.</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>S_df</name>
      <type>algebraic</type>
      <tans>df(x)</tans>
      <boxsize>20</boxsize>
      <strictsyntax>1</strictsyntax>
      <insertstars>3</insertstars>
      <syntaxhint>Expression</syntaxhint>
      <syntaxattribute>1</syntaxattribute>
      <forbidwords/>
      <allowwords/>
      <forbidfloat>0</forbidfloat>
      <requirelowestterms>0</requirelowestterms>
      <checkanswertype>0</checkanswertype>
      <mustverify>1</mustverify>
      <showvalidation>3</showvalidation>
      <options/>
    </input>
    <input>
      <name>S_x1</name>
      <type>numerical</type>
      <tans>x1</tans>
      <boxsize>8</boxsize>
      <strictsyntax>1</strictsyntax>
      <insertstars>0</insertstars>
      <syntaxhint>6 s.f.</syntaxhint>
      <syntaxattribute>1</syntaxattribute>
      <forbidwords/>
      <allowwords/>
      <forbidfloat>0</forbidfloat>
      <requirelowestterms>0</requirelowestterms>
      <checkanswertype>0</checkanswertype>
      <mustverify>1</mustverify>
      <showvalidation>3</showvalidation>
      <options/>
    </input>
    <input>
      <name>S_x2</name>
      <type>numerical</type>
      <tans>x2</tans>
      <boxsize>8</boxsize>
      <strictsyntax>1</strictsyntax>
      <insertstars>0</insertstars>
      <syntaxhint>6 s.f.</syntaxhint>
      <syntaxattribute>1</syntaxattribute>
      <forbidwords/>
      <allowwords/>
      <forbidfloat>0</forbidfloat>
      <requirelowestterms>0</requirelowestterms>
      <checkanswertype>0</checkanswertype>
      <mustverify>1</mustverify>
      <showvalidation>3</showvalidation>
      <options/>
    </input>
    <prt>
      <name>df</name>
      <value>1.0000000</value>
      <autosimplify>1</autosimplify>
      <feedbackstyle>2</feedbackstyle>
      <feedbackvariables>
        <text/>
      </feedbackvariables>
      <node>
        <name>0</name>
        <description/>
        <answertest>Diff</answertest>
        <sans>S_df</sans>
        <tans>df(x)</tans>
        <testoptions>x</testoptions>
        <quiet>0</quiet>
        <truescoremode>=</truescoremode>
        <truescore>1</truescore>
        <truepenalty/>
        <truenextnode>-1</truenextnode>
        <trueanswernote>df-1-T</trueanswernote>
        <truefeedback format="html">
          <text/>
        </truefeedback>
        <falsescoremode>=</falsescoremode>
        <falsescore>0</falsescore>
        <falsepenalty/>
        <falsenextnode>-1</falsenextnode>
        <falseanswernote>df-1-F</falseanswernote>
        <falsefeedback format="html">
          <text>{@fb_vars(S_df, df(x), [])@}</text>
        </falsefeedback>
      </node>
    </prt>
    <prt>
      <name>x1</name>
      <value>1.0000000</value>
      <autosimplify>1</autosimplify>
      <feedbackstyle>2</feedbackstyle>
      <feedbackvariables>
        <text/>
      </feedbackvariables>
      <node>
        <name>0</name>
        <description/>
        <answertest>NumRelative</answertest>
        <sans>S_x1</sans>
        <tans>x1</tans>
        <testoptions>0.000005</testoptions>
        <quiet>0</quiet>
        <truescoremode>=</truescoremode>
        <truescore>1</truescore>
        <truepenalty/>
        <truenextnode>-1</truenextnode>
        <trueanswernote>x1-1-T</trueanswernote>
        <truefeedback format="markdown">
          <text/>
        </truefeedback>
        <falsescoremode>=</falsescoremode>
        <falsescore>0</falsescore>
        <falsepenalty/>
        <falsenextnode>-1</falsenextnode>
        <falseanswernote>x1-1-F</falseanswernote>
        <falsefeedback format="markdown">
          <text/>
        </falsefeedback>
      </node>
    </prt>
    <prt>
      <name>x2</name>
      <value>1.0000000</value>
      <autosimplify>1</autosimplify>
      <feedbackstyle>2</feedbackstyle>
      <feedbackvariables>
        <text/>
      </feedbackvariables>
      <node>
        <name>0</name>
        <description/>
        <answertest>NumRelative</answertest>
        <sans>S_x2</sans>
        <tans>x2</tans>
        <testoptions>0.000005</testoptions>
        <quiet>0</quiet>
        <truescoremode>=</truescoremode>
        <truescore>1</truescore>
        <truepenalty/>
        <truenextnode>-1</truenextnode>
        <trueanswernote>x2-1-T</trueanswernote>
        <truefeedback format="markdown">
          <text/>
        </truefeedback>
        <falsescoremode>=</falsescoremode>
        <falsescore>0</falsescore>
        <falsepenalty/>
        <falsenextnode>-1</falsenextnode>
        <falseanswernote>x2-1-F</falseanswernote>
        <falsefeedback format="markdown">
          <text/>
        </falsefeedback>
      </node>
    </prt>
    <deployedseed>1587513181</deployedseed>
    <deployedseed>2004592882</deployedseed>
    <deployedseed>527247886</deployedseed>
    <deployedseed>1607512437</deployedseed>
    <qtest>
      <testcase>1</testcase>
      <description>Test case assuming the teacher's input gets full marks.</description>
      <testinput>
        <name>S_df</name>
        <value>df(x)</value>
      </testinput>
      <testinput>
        <name>S_x1</name>
        <value>x1</value>
      </testinput>
      <testinput>
        <name>S_x2</name>
        <value>x2</value>
      </testinput>
      <expected>
        <name>df</name>
        <expectedscore>1.0000000</expectedscore>
        <expectedpenalty>0.0000000</expectedpenalty>
        <expectedanswernote>df-1-T</expectedanswernote>
      </expected>
      <expected>
        <name>x1</name>
        <expectedscore>1.0000000</expectedscore>
        <expectedpenalty>0.0000000</expectedpenalty>
        <expectedanswernote>x1-1-T</expectedanswernote>
      </expected>
      <expected>
        <name>x2</name>
        <expectedscore>1.0000000</expectedscore>
        <expectedpenalty>0.0000000</expectedpenalty>
        <expectedanswernote>x2-1-T</expectedanswernote>
      </expected>
    </qtest>
    <qtest>
      <testcase>2</testcase>
      <description>Test case assuming the teacher's input gets full marks.</description>
      <testinput>
        <name>S_df</name>
        <value>df(x)</value>
      </testinput>
      <testinput>
        <name>S_x1</name>
        <value>x1</value>
      </testinput>
      <testinput>
        <name>S_x2</name>
        <value>x2</value>
      </testinput>
      <expected>
        <name>df</name>
        <expectedscore>1.0000000</expectedscore>
        <expectedpenalty>0.0000000</expectedpenalty>
        <expectedanswernote>df-1-T</expectedanswernote>
      </expected>
      <expected>
        <name>x1</name>
        <expectedscore>1.0000000</expectedscore>
        <expectedpenalty>0.0000000</expectedpenalty>
        <expectedanswernote>x1-1-T</expectedanswernote>
      </expected>
      <expected>
        <name>x2</name>
        <expectedscore>1.0000000</expectedscore>
        <expectedpenalty>0.0000000</expectedpenalty>
        <expectedanswernote>x2-1-T</expectedanswernote>
      </expected>
    </qtest>
    <qtest>
      <testcase>3</testcase>
      <description>Test case assuming the teacher's input gets full marks.</description>
      <testinput>
        <name>S_df</name>
        <value>df(x)</value>
      </testinput>
      <testinput>
        <name>S_x1</name>
        <value>x1</value>
      </testinput>
      <testinput>
        <name>S_x2</name>
        <value>x2</value>
      </testinput>
      <expected>
        <name>df</name>
        <expectedscore>1.0000000</expectedscore>
        <expectedpenalty>0.0000000</expectedpenalty>
        <expectedanswernote>df-1-T</expectedanswernote>
      </expected>
      <expected>
        <name>x1</name>
        <expectedscore>1.0000000</expectedscore>
        <expectedpenalty>0.0000000</expectedpenalty>
        <expectedanswernote>x1-1-T</expectedanswernote>
      </expected>
      <expected>
        <name>x2</name>
        <expectedscore>1.0000000</expectedscore>
        <expectedpenalty>0.0000000</expectedpenalty>
        <expectedanswernote>x2-1-T</expectedanswernote>
      </expected>
    </qtest>
  </question>
</quiz>
