<?xml version="1.0" encoding="UTF-8"?>
<quiz>
  <question type="stack">
    <name>
      <text>27.2.5.2 Integration Over Quadrilateral Exercise</text>
    </name>
    <questiontext format="moodle_auto_format">
      <text><![CDATA[<p class="HELM_exercise">Exercise</p>
<p>Evaluate the following functions over the quadrilateral with vertices at \((0,0)\), \(({@dd@},0)\), \(({@bb@},{@cc@})\) and \((0,{@aa@})\).</p>
<p><ol class="HELM_parts">
<li><p> \(xy\) </p>
<p> \(I_1 =\) [[input:ans1]] [[validation:ans1]] [[feedback:prt1]]</p></li>
<li><p> \(xy+3y^2\)</p>
<p> \(I_2 =\) [[input:ans2]] [[validation:ans2]] [[feedback:prt2]]</p></li>]]></text>
    </questiontext>
    <generalfeedback format="moodle_auto_format">
      <text><![CDATA[<p> Both integrations take place over the quadrilateral shown below</p>
[[jsxgraph]]

        var board = JXG.JSXGraph.initBoard(divid, { // STACK: when moving to STACK change 'jxgboard' for divid
            boundingbox: [-0.25, {#aa +1#}, {#dd+0.5#}, -1],
            keepaspectratio: true,
            axis: true,
            showCopyright: false,
			showNavigation: false,
			grid: false
		});
		
		// Hide tick labels and ticks on x-axis but label it
		board.defaultAxes.x.setAttribute({
		  ticks: {
			drawLabels: false, // hide numbers
			majorHeight: 0,
			minorHeight: 0
		  },
		  name: 'x',
		  withLabel: true,
		  label: {
			position: 'rt',
			offset: [8, -10]
		  }
		});

		// Hide tick labels and ticks on y-axis but label it
		board.defaultAxes.y.setAttribute({
		  ticks: {
			drawLabels: false,
			majorHeight: 0,
			minorHeight: 0
		  },
		  name: 'y',
		  withLabel: true,
		  label: {
			position: 'rt',
			offset: [-15, 0]
		  }
		});
		
		
		// points
		var bl = board.create('point', [0,0], {fixed: true, withLabel:false, visible: false});
		var br = board.create('point', [{#dd#},0], {fixed: true, withLabel:false, visible: false});
		var tr = board.create('point', [{#bb#},{#cc#}], {fixed: true, withLabel:false, visible: false});
		var tl = board.create('point', [0,{#aa#}], {fixed: true, withLabel:false, visible: false});
		var quadrilateral = board.create('polygon', [bl, br, tr, tl],{name:"Quadrilateral",withLabel:false, color: 'white'});
		
		// Set all edges (borders) to black
		quadrilateral.borders.forEach(line => {
			line.setAttribute({strokeColor: 'black'});
		});
		
		// Label coordinates dynamically
		[bl, br, tr, tl].forEach((pt) => {
			board.create('text', [
				() => pt.X() + 0.1,
				() => pt.Y() + 0.1,
				() => `(${pt.X()}, ${pt.Y()})`
			], {
				fontSize: 12,
				fixed: true,
				highlight: false
			});
		});


// Vertical dashed line segment inside quadrilateral from (bb,0) to (bb,cc)
var vline_start = board.create('point', [{#bb#}, 0], {visible:false});
var vline_end = board.create('point', [{#bb#}, {#cc#}], {visible:false});

board.create('segment', [vline_start, vline_end], {
    strokeColor: 'black',
    dash: 2,
    strokeWidth: 1,
    fixed: true,
    highlight: false
});
[[/jsxgraph]]

<p> (a) It is not possible to represent the given quadrilateral by means of limits on an inner integral and an the outer integral. However, it can be split at \(x={@bb@}\) into 2 regions, allowing us to represent it as the sum of the integrals over each region. </p>
<p> So then </p>
<p> \(\qquad \displaystyle I_1 = \int\int_\text{Region 1} xy \; \mathrm{d}A + \int\int_\text{Region2} xy \; \mathrm{d}A \) </p>
<p> Let the left hand region of the quadrilateral be called Region 1, and the right hand region be called Region 2. </p>
<br>

<p> We first determine the limits of integration for Region 1. </p>
<p>Considering variable \(x\) on the outer integral and variable \(y\) on the inner integral, Region 1 has an extent in \(x\) of \(x=0\) to \(x={@bb@}\). So, the limits on the outer integral (limits on \(x\)) are \(x=0\) and \(x={@bb@}\).</p>

<p>For each value of \(x\), \(y\) varies from \(y = 0\) to \(y = {@ee*x + aa@}\) (line joining \((0,{@aa@})\) and \(({@bb@},{@cc@})\)). So the limits on the inner integral (limits on \(y\)) are \(y = 0 \) to \(y = {@ee*x + aa@}\).</p>
<p> So we have </p>
<p>\( \qquad \displaystyle \int\int_\text{Region 1} xy \; \mathrm{d}A = \int_{0}^{@bb@} \int_{0}^{@upp1@}  \; \mathrm{d}y \, \mathrm{d}x \) </p>
<p>\(\begin{align}
\qquad \text{Inner}\hspace{0.1cm} \text{Integral} &= \int_{0}^{@upp1@} xy \; \mathrm{d}y \\
&= \left[\dfrac{xy^2}{2}\right]_{0}^{@upp1@} \\
&= \dfrac{x\left({@upp1@}\right)^2}{2} - 0 \\
&= \dfrac{x\left({@ee^2*x^2 + 2*aa*ee*x + aa^2@}\right)}{2} \\ 
&= \dfrac{1}{2}\left({@ee^2*x^3 + 2*aa*ee*x^2 + aa^2*x@} \right) \end{align}\)</p>

<p> And so </p>
<p>\(\begin{align}
\qquad \displaystyle \int\int_\text{Region 1}  xy \; \mathrm{d}A &= \int_{0}^{@bb@} \dfrac{1}{2}\left({@ee^2*x^3 + 2*aa*ee*x^2 + aa^2*x@} \right) \; \mathrm{d}x \\
&= \dfrac{1}{2} \int_{0}^{@bb@} \left({@ee^2*x^3 + 2*aa*ee*x^2 + aa^2*x@} \right) \; \mathrm{d}x \\
&= \dfrac{1}{2} \left[{@(ee^2/4)*x^4 + ((2*aa*ee)/3)*x^3 + (aa^2/2)*x^2@} \right]_{0}^{@bb@} \\
&= \dfrac{1}{2} \left({@ee^2/4@}({@bb@})^4  {@(2*aa*ee)/3@}({@bb@})^3 + {@aa^2/2@}({@bb@})^2 - \left(0\right) \right) \\
&= {@reg1@}. \end{align}\) </p>
<br>


<p> Now we come to our integral for Region 2. </p>
<p> Again, we first determine the limits of integration for this region. </p>
<p>Considering variable \(x\) on the outer integral and variable \(y\) on the inner integral, Region 2 has an extent in \(x\) of \(x={@bb@}\) to \(x={@dd@}\). So, the limits on the outer integral (limits on \(x\)) are \(x={@bb@}\) and \(x={@dd@}\).</p>

<p>For each value of \(x\), \(y\) varies from \(y = 0\) to \(y = {@ff*x + gg@}\) (line joining \(({@bb@},{@cc@})\) and \(({@dd@},0)\)). So the limits on the inner integral (limits on \(y\)) are \(y = 0 \) to \(y = {@ff*x + gg@}\).</p>
<p> So we have </p>
<p>\( \qquad \displaystyle \int\int_\text{Region 2} xy \; \mathrm{d}A = \int_{@bb@}^{@dd@} \int_{0}^{@upp2@} xy \; \mathrm{d}y \, \mathrm{d}x \) </p>
<p>\(\begin{align}
\qquad \text{Inner}\hspace{0.1cm} \text{Integral} &= \int_{0}^{@upp2@} xy \; \mathrm{d}y \\
&= \left[\dfrac{xy^2}{2}\right]_{0}^{@upp2@} \\
&= \dfrac{x\left({@upp2@}\right)^2}{2} - 0 \\
&= \dfrac{x\left({@ff^2*x^2 + 2*gg*ff*x + gg^2@}\right)}{2} \\ 
&= \dfrac{1}{2}\left({@ff^2*x^3 + 2*gg*ff*x^2 + gg^2*x@} \right) \end{align}\)</p>

<p> And so </p>
<p>\(\begin{align}
\qquad \displaystyle \int\int_\text{Region 2} xy \; \mathrm{d}A  &= \int_{@bb@}^{@dd@} \dfrac{1}{2}\left({@ff^2*x^3 + 2*gg*ff*x^2 + gg^2*x@} \right) \; \mathrm{d}x \\
&= \dfrac{1}{2} \int_{{@bb@}}^{@dd@} \left({@ff^2*x^3 + 2*gg*ff*x^2 + gg^2*x@} \right) \; \mathrm{d}x \\
&= \dfrac{1}{2} \left[{@(ff^2/4)*x^4 + ((2*gg*ff)/3)*x^3 + (gg^2/2)*x^2@} \right]_{0}^{@bb@} \\
&= \dfrac{1}{2} \left({@ff^2/4@}({@bb@})^4  {@(2*gg*ff)/3@}({@bb@})^3 + {@gg^2/2@}({@bb@})^2 - \left(0\right) \right) \\
&= {@reg2@}. \end{align}\) </p>

<p> And so finally, we have </p>
<p>\(\begin{align}
\qquad \displaystyle  I_1 &= \int\int_\text{Region 1} xy \; \mathrm{d}A + \int\int_\text{Region2} xy \; \mathrm{d}A \\
&= {@reg1@} + {@reg2@} \\ 
&= {@ta1@}. \end{align}\)</p>
<br>
<br>

<p> (b) Now, we already have our regions and limits of integration from part (a) - these remain the same even if the function changes. </p>
<p> We again have  </p>
<p> \(\qquad \displaystyle I_2 = \int\int_\text{Region 1} \left(xy + 3y^2\right) \; \mathrm{d}A + \int\int_\text{Region2} \left(xy + 3y^2\right) \; \mathrm{d}A\) </p>
<p> So, for Region 1, here we have: </p>
<p>\( \qquad \displaystyle \int\int_\text{Region 1}  \left(xy + 3y^2\right) \; \mathrm{d}A = \int_{0}^{@bb@} \int_{0}^{@upp1@} \left(xy + 3y^2\right) \; \mathrm{d}y \, \mathrm{d}x \) </p>
<p> To simplify the evaluation, this can be split as follows: </p>
<p>\( \qquad \displaystyle \int\int_\text{Region 1}  \left(xy + 3y^2\right) \; \mathrm{d}A = \int_{0}^{@bb@} \int_{0}^{@upp1@} xy  \; \mathrm{d}y \, \mathrm{d}x + \int_{0}^{@bb@} \int_{0}^{@upp1@} 3y^2 \; \mathrm{d}y \, \mathrm{d}x \) </p>
<p> Notice that we have already computed the first integral in part (a): </p>
<p> \(\qquad \displaystyle \text{First} = \int_{0}^{@bb@} \int_{0}^{@upp1@} xy  \; \mathrm{d}y \, \mathrm{d}x = {@reg1@} \) </p>

<p> So, computing the second: </p>
<p> \(\qquad \displaystyle \text{Second} = \int_{0}^{@bb@} \int_{0}^{@upp1@} 3y^2 \; \mathrm{d}y \, \mathrm{d}x \) </p>
<p>\(\begin{align}
\qquad \text{Inner}\hspace{0.1cm} \text{Integral} &= \int_{0}^{@upp1@} 3y^2 \; \mathrm{d}y \\
&= \left[y^3\right]_{0}^{@upp1@} \\
&= \left({@upp1@}\right)^3 - 0 \\
&= {@ee^3*x^3 + 3*ee^2*aa*x^2 + 3*ee^2*aa*x^2 + aa^3@} \end{align}\)</p>

<p> And so </p>
<p>\(\begin{align}
\qquad \text{Second} &= \int_{0}^{@bb@} \left({@ee^3*x^3 + 3*ee^2*aa*x^2 + 3*ee^2*aa*x^2 + aa^3@}\right) \; \mathrm{d}x \\
&=  \left[{@(ee^3/4)*x^4 + (ee^2*aa)*x^3 + ((3*ee*aa^2)/2)*x^2 + (aa^3)*x@} \right]_{0}^{@bb@} \\
&=  \left({@ee^3/4@}({@bb@})^4 + {@ee^2*aa@}({@bb@})^3 {@(3*ee*aa^2)/2@}({@bb@})^2 + {@aa^3@}({@bb@})- \left(0\right) \right) \\
&= {@rega@}. \end{align}\) </p>

<p> And therefore we now have </p>
<p>\(\begin{align}
\qquad \displaystyle \int\int_\text{Region 1} \left(xy + 3y^2\right) \; \mathrm{d}A &= \text{First} + \text{Second} \\
&= {@reg1@} + {@rega@} \\ 
&= {@reg1 + rega@} \end{align}\)</p>
<br>

<p> Now we come to our integral for Region 2. </p>
<p> Again, we have our limits of integration already, so we have </p>
<p>\( \qquad \displaystyle \int\int_\text{Region 2} \left(xy + 3y^2\right) \; \mathrm{d}A  = \int_{@bb@}^{@dd@} \int_{0}^{@upp2@} \left(xy + 3y^2\right) \; \mathrm{d}y \, \mathrm{d}x \) </p>
<p> Again, to simplify the evaluation, we may split this integral as follows: </p>
<p>\( \qquad \displaystyle \int\int_\text{Region 2} \left(xy + 3y^2\right) \; \mathrm{d}A = \int_{@bb@}^{@dd@} \int_{0}^{@upp2@} xy \; \mathrm{d}y \, \mathrm{d}x  + \int_{@bb@}^{@dd@} \int_{0}^{@upp2@} 3y^2 \; \mathrm{d}y \, \mathrm{d}x \) </p>

<p> Again, notice that we computed the first integral already in part (a): </p>
\(\qquad \displaystyle \text{First} = \int_{@bb@}^{@dd@} \int_{0}^{@upp2@} xy \; \mathrm{d}y \, \mathrm{d}x = {@reg2@} \) </p>

<p> So, computing the second: </p>
<p> \(\qquad \displaystyle \text{Second} = \int_{@bb@}^{@dd@} \int_{0}^{@upp2@} 3y^2 \; \mathrm{d}y \, \mathrm{d}x \) </p>
<p>\(\begin{align}
\text{Inner}\hspace{0.1cm} \text{Integral} &= \int_{0}^{@upp2@} 3y^2 \; \mathrm{d}y \\
&= \displaystyle \left[y^3\right]_{0}^{@upp2@} \\
&= \left({@ff*x + gg@}\right)^3 - 0 \\
&= {@ff^3*x^3 + 3*ff^2*gg*x^2 + 3*ff*gg^2*x + gg^3@} \end{align}\)</p>

<p> And so </p>
<p>\(\begin{align}
\qquad \text{Second} &=  \int_{@bb@}^{@dd@} \left({@ff^3*x^3 + 3*ff^2*gg*x^2 + 3*ff*gg^2*x + gg^3@}\right) \; \mathrm{d}x \\
&= \left[{@(ff^3)/4*x^4 + ff^2*gg*x^3 + (3/2)*ff*gg^2*x^2 + gg^3*x@}\right]_{@bb@}^{@dd@} \\
&= {@ff^3/4@}({@dd@})^4 + {@ff^2*gg@}({@dd@})^3  {@3*ff*gg^2/2@}({@dd@})^2 + {@gg^3@}({@dd@}) - \left({@ff^3/4@}({@bb@})^4 + {@ff^2*gg@}({@bb@})^3  {@3*ff*gg^2/2@}({@bb@})^2 + {@gg^3@}({@bb@})\right) \\
&= {@regb@} \end{align}\) </p>

<p> And so </p>
<p>\( \qquad \displaystyle \int\int_\text{Region 2} \left(xy + 3y^2\right) \; \mathrm{d}A = {@reg2@} + {@regb@} = {@reg2 + regb@}\) </p>

<p> And finally, we then have </p>
<p>\(\begin{align}
\qquad \displaystyle  I_2 &= \int\int_\text{Region 1} \left(xy + 3y^2\right) \; \mathrm{d}A + \int\int_\text{Region 2} \left(xy + 3y^2\right) \; \mathrm{d}A \\
&= {@reg1 + rega@} + {@reg2 + regb@} \\ 
&= {@ta2@}. \end{align}\)</p>]]></text>
    </generalfeedback>
    <defaultgrade>1</defaultgrade>
    <penalty>0.1</penalty>
    <hidden>0</hidden>
    <idnumber/>
    <stackversion>
      <text>2025040100</text>
    </stackversion>
    <questionvariables>
      <text>coords: [
  [2,2,4,3],
  [2,3,4,5], [2,3,4,6], [2,3,5,4], [2,4,5,6],
  [3,2,4,5], [3,2,5,4], [3,2,6,4],
  [2,3,4,4], [2,4,5,4], [2,4,5,5], [2,4,6,4], [2,4,6,5],
  [3,2,4,4], [3,3,4,4], [3,3,4,5], [3,3,4,6], [3,3,5,4]
];
index: rand(length(coords));
[bb, cc, aa, dd]: coords[index + 1];
ee: (cc-aa)/bb;
ff: -cc/(dd-bb);
gg: (cc*dd)/(dd-bb);
exp1: x*y;
upp1: ee*x +aa;
inn1: int(exp1,y,0,upp1);
reg1: int(inn1,x,0,bb);
upp2: ff*x + gg;
inn2: int(exp1,y,0,upp2);
reg2: int(inn2,x,bb,dd);
exp2: 3*y^2;
exp3: exp1 + exp2
inn3: int(exp3,y,0,upp1);
reg3: int(inn3,x,0,bb);
inn4: int(exp3,y,0,upp2);
reg4: int(inn4,x,bb,dd);
inna: int(exp2, y, 0, upp1);
rega: int(inna, x, 0, bb);
innb: int(exp2, y, 0, upp2);
regb: int(innb, x, bb, dd);
ta1: reg1 + reg2;
ta2: reg3 + reg4;</text>
    </questionvariables>
    <specificfeedback format="html">
      <text/>
    </specificfeedback>
    <questionnote format="html">
      <text><![CDATA[<p>Vertices: \((0,0)\), \(({@dd@},0)\), \(({@bb@},{@cc@})\) and \((0,{@aa@})\). </p>
<p>\(I_1 = {@ta1@}, I_2 = {@ta2@}\) </p>]]></text>
    </questionnote>
    <questiondescription format="html">
      <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>algebraic</type>
      <tans>ta1</tans>
      <boxsize>5</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>algebraic</type>
      <tans>ta2</tans>
      <boxsize>5</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/>
      </feedbackvariables>
      <node>
        <name>0</name>
        <description/>
        <answertest>AlgEquiv</answertest>
        <sans>ans1</sans>
        <tans>ta1</tans>
        <testoptions/>
        <quiet>0</quiet>
        <truescoremode>=</truescoremode>
        <truescore>1</truescore>
        <truepenalty/>
        <truenextnode>-1</truenextnode>
        <trueanswernote>prt1-1-T</trueanswernote>
        <truefeedback format="html">
          <text/>
        </truefeedback>
        <falsescoremode>=</falsescoremode>
        <falsescore>0</falsescore>
        <falsepenalty/>
        <falsenextnode>-1</falsenextnode>
        <falseanswernote>prt1-1-F</falseanswernote>
        <falsefeedback format="html">
          <text/>
        </falsefeedback>
      </node>
    </prt>
    <prt>
      <name>prt2</name>
      <value>1.0000000</value>
      <autosimplify>1</autosimplify>
      <feedbackstyle>1</feedbackstyle>
      <feedbackvariables>
        <text/>
      </feedbackvariables>
      <node>
        <name>0</name>
        <description/>
        <answertest>AlgEquiv</answertest>
        <sans>ans2</sans>
        <tans>ta2</tans>
        <testoptions/>
        <quiet>0</quiet>
        <truescoremode>=</truescoremode>
        <truescore>1</truescore>
        <truepenalty/>
        <truenextnode>-1</truenextnode>
        <trueanswernote>prt2-1-T</trueanswernote>
        <truefeedback format="html">
          <text/>
        </truefeedback>
        <falsescoremode>=</falsescoremode>
        <falsescore>0</falsescore>
        <falsepenalty/>
        <falsenextnode>-1</falsenextnode>
        <falseanswernote>prt2-1-F</falseanswernote>
        <falsefeedback format="html">
          <text/>
        </falsefeedback>
      </node>
    </prt>
    <deployedseed>1639547161</deployedseed>
    <deployedseed>348860446</deployedseed>
    <deployedseed>241014111</deployedseed>
    <deployedseed>1324059660</deployedseed>
    <deployedseed>584659221</deployedseed>
    <deployedseed>998241318</deployedseed>
    <deployedseed>235441913</deployedseed>
    <deployedseed>26250567</deployedseed>
    <deployedseed>1239603184</deployedseed>
    <deployedseed>8317089</deployedseed>
    <deployedseed>1066748273</deployedseed>
    <deployedseed>1599549362</deployedseed>
    <qtest>
      <testcase>1</testcase>
      <description>Test case assuming the teacher's input gets full marks.</description>
      <testinput>
        <name>ans1</name>
        <value>ta1</value>
      </testinput>
      <testinput>
        <name>ans2</name>
        <value>ta2</value>
      </testinput>
      <expected>
        <name>prt1</name>
        <expectedscore>1.0000000</expectedscore>
        <expectedpenalty>0.0000000</expectedpenalty>
        <expectedanswernote>prt1-1-T</expectedanswernote>
      </expected>
    </qtest>
    <qtest>
      <testcase>2</testcase>
      <description/>
      <testinput>
        <name>ans1</name>
        <value>ta1+1</value>
      </testinput>
      <testinput>
        <name>ans2</name>
        <value>ta2+1</value>
      </testinput>
      <expected>
        <name>prt1</name>
        <expectedscore>0.0000000</expectedscore>
        <expectedpenalty/>
        <expectedanswernote>prt1-1-F</expectedanswernote>
      </expected>
    </qtest>
    <tags>
      <tag><text>jsxgraph_solution</text>
</tag>
    </tags>
  </question>
</quiz>
