// Numbas version: finer_feedback_settings {"name": "Luis's copy of Approximate the integral of a quadratic by Riemann sums,", "extensions": ["jsxgraph"], "custom_part_types": [], "resources": [], "navigation": {"allowregen": true, "showfrontpage": false, "preventleave": false, "typeendtoleave": false}, "question_groups": [{"pickingStrategy": "all-ordered", "questions": [{"advice": "\n

$f(x)$ is a quadratic and its stationary point is given by $\\frac{df}{dx}=0$ which after solving gives the minimum point  $x=-\\simplify[all]{{a}/2}$.

\n

{plotf(a,b,c)}

\n

We see that the function is increasing in the range $[0,\\var{c}]$ and it follows that the lower sums are given by taking the value of $f$ on the left hand side of each interval, multiplying by the interval length and summing up over all intervals. The upper sums by taking the right hand side of each interval etc.

\n

The following diagrams illustrate this. Move the slider to see the effect on the upper and lower sums by varying the number $n$ of subintervals.

\n

{riemann(c,n,a,b)}

\n

Finding the Upper and Lower sums Directly.

\n

First you have to know the following sums of sequences:

\n

\\[\\begin{eqnarray*}\\sum_{r=1}^m r &=& \\frac{m(m+1)}{2}\\\\ \\sum_{r=1}^{m} r^2&=&\\frac{m(m+1)(2m+1)}{6}\\end{eqnarray*}\\]

\n

Also the interval points between $0$ and $\\var{c}$ are given by $x_j=\\simplify[all,fractionNumbers]{({c}/{n})j},\\;j=0,\\dots,\\var{n}$

\n

For the lower sums, each rectangle with base the interval $[x_r,x_{r+1}]$ contributes an area $f(x_r)(x_{r+1}-x_r)=\\simplify[all,fractionNumbers]{f({c}/{n}*r)*({c}/{n})},\\;r=0,\\ldots,\\var{n-1}$.

\n

We sum from $r=0$ to $r=\\var{n-1}$ as we have to take the left value of each interval.

\n

So the lower sum is:

\n

\\[\\begin{eqnarray}\\mbox{LS}=\\sum_{r=0}^{\\var{n-1}}\\simplify[all,fractionNumbers]{f(({c}/{n})*r)*({c}/{n})}&=&\\sum_{r=0}^{\\var{n-1}}\\simplify[all,fractionNumbers,!collectNumbers]{((({c}/{n})*r)^2+{a}*(({c}/{n})*r)+{b})*({c}/{n})}\\\\
&=&\\sum_{r=0}^{\\var{n-1}}\\simplify[all,fractionNumbers,!collectNumbers]{({c}/{n})^3*r^2}+\\var{a}\\sum_{r=0}^{\\var{n-1}}\\simplify[all,fractionNumbers,!collectNumbers]{({c}/{n})^2*r}+\\var{b}\\sum_{r=0}^{\\var{n-1}}\\simplify[all,fractionNumbers,!collectNumbers]{({c}/{n})}\\\\
&=&\\simplify[all,fractionNumbers]{({c}/{n})^3}\\sum_{r=0}^{\\var{n-1}}r^2+\\var{a}\\times\\simplify[all,fractionNumbers]{({c}/{n})^2}\\sum_{r=0}^{\\var{n-1}}r+\\var{b}\\times\\var{c}\\end{eqnarray}\\]

\n

Using \\[\\sum_{r=0}^{\\var{n-1}}r=\\frac{\\var{n-1}\\times \\var{n}}{2}=\\var{(n-1)*n/2},\\;\\;\\;\\sum_{r=0}^{\\var{n-1}}r^2=\\frac{\\var{n-1}\\times \\var{n}\\times \\var{2*n-1}}{6}=\\var{(n-1)*n*(2*n-1)/6}\\]

\n

and substituting into the above equation we obtain:

\n

LS = $\\var{tlowersum}=\\var{lowersum}$ to 3 decimal places.

\n

As for the upper sum we have $\\mbox{US}=\\mbox{LS}+(f(\\var{c})-f(0))\\times\\simplify[all,fractionNumbers]{{c}/{n}}=\\mbox{LS}+(\\var{c^2+a*c+b}-\\var{b})\\times \\simplify[all,fractionNumbers]{{c}/{n}}=\\var{tlowersum}+\\var{tuppersum-tlowersum}=\\var{tuppersum}=\\var{uppersum}$ to 3 decimal places .

\n

Or if we take the more long-winded approach using the same method as for LS we have:

\n

\\[\\begin{eqnarray}\\mbox{US}=\\sum_{r=1}^{\\var{n}}\\simplify[all,fractionNumbers]{f(({c}/{n})*r)*({c}/{n})}&=&\\sum_{r=1}^{\\var{n}}\\simplify[all,fractionNumbers,!collectNumbers]{((({c}/{n})*r)^2+{a}*(({c}/{n})*r)+{b})*({c}/{n})}\\\\&=&\\sum_{r=1}^{\\var{n}}\\simplify[all,fractionNumbers,!collectNumbers]{({c}/{n})^3*r^2}+\\var{a}\\sum_{r=1}^{\\var{n}}\\simplify[all,fractionNumbers,!collectNumbers]{({c}/{n})^2*r}+\\var{b}\\sum_{r=1}^{\\var{n}}\\simplify[all,fractionNumbers,!collectNumbers]{({c}/{n})}\\\\&=&\\simplify[all,fractionNumbers]{({c}/{n})^3}\\sum_{r=1}^{\\var{n}}r^2+\\var{a}\\times\\simplify[all,fractionNumbers]{({c}/{n})^2}\\sum_{r=1}^{\\var{n}}r+\\var{b}\\times\\var{c}\\\\&=&\\var{tuppersum}=\\var{uppersum}\\end{eqnarray}\\]

\n

to 3 decimal places.

\n

The true value is given by the integral

\n

\\[\\int_{0}^{\\var{c}} \\simplify[all]{x^2+{a}*x+{b}}\\;dx=\\left[\\simplify[all]{x^3/3+{a}/2*x^2+{b}*x}\\right]_{0}^{\\var{c}}=\\var{theint}\\] to 3 decimal places.

\n

\n

For $\\var{2*n}$ intervals we obtain:

\n

$\\mbox{LS}=\\var{lowersum2}$.

\n

$\\mbox{US}=\\var{uppersum2}$.

\n

Both to 3 decimal places.

\n

\n

\n

\n

\n

\n", "preamble": {"css": "", "js": ""}, "question_groups": [{"questions": [], "pickingStrategy": "all-ordered", "pickQuestions": 0, "name": ""}], "name": "Luis's copy of Approximate the integral of a quadratic by Riemann sums,", "variable_groups": [], "type": "question", "functions": {"plotf1": {"language": "javascript", "type": "html", "definition": "\nvar f = function(x){ return x*x+a*x+b; };\nvar div = Numbas.extensions.jsxgraph.makeBoard('200px','200px', {axis:true,showNavigation:false, boundingbox:[-a/2-5,f(-a/2+5),-a/2+5,Math.min(f(-a/2),-4)]});\n\nvar brd=div.board;\n\nvar plot = brd.create('functiongraph',[f,-a/2-5,-a/2+5]);\n\n//brd.create('text',[c,-2,c]);\n//var i1 = brd.create('integral', [[0, c], plot]);\n\nreturn div;\n", "parameters": [["a", "number"], ["b", "number"], ["c", "number"]]}, "riemann": {"language": "javascript", "type": "html", "definition": "\nvar div = Numbas.extensions.jsxgraph.makeBoard('400px','400px', {axis:false,showNavigation:true, boundingbox:[-2-c-1,(c+1)*(c+1)+(c+1)*a+b+15,c+2,-15]});\nvar brd=div.board;\n//This slider varies the number of partitions. Start off with n\nvar s = brd.create('slider',[[-1,(c+1)*(c+1)+(c+1)*a+b+10],[1,(c+1)*(c+1)+(c+1)*a+b+10],[0,n,50]],{name:'n',snapWidth:1});\nn=s.Value();\n//The function for which we are estimating the integral. \n//This dispays to the right\nvar f = function(x){ return x*x+a*x+b; };\n//Same function but displaced to the left for the lower sum\nvar f1=function(x){return (x+2+c+1)*(x+2+c+1)+a*(x+2+c+1)+b;};\nvar plot = brd.create('functiongraph',[f,0,c+1]);\nvar plot1=brd.create('functiongraph',[f1,-2-c-1,-2]);\n//Two diagrams created using built in function.\nvar os = brd.create('riemannsum',[f,function(){return s.Value();},'upper',0, c ], \n{fillColor:'#ffff00', fillOpacity:0.3});\nvar os1 = brd.create('riemannsum',[f1,function(){return s.Value();},'lower',-2-c-1, -3 ], \n{fillColor:'#ffff00', fillOpacity:0.3});\n//Unfortunately the uppersum calculation in jsxgraph does not agree with mine!\n//So have written the function which gives the same result as the question.\n//Have checked this and is OK - still could be checked.\nvar usm=function(c,n,a,b){\n var s=Math.pow(c,3)*(n+1)*(2*n+1)/(6*Math.pow(n,2))+a*Math.pow(c,2)*(n+1)/(2*n)+b*c;\ns=Numbas.math.precround(Numbas.math.niceNumber(s),3);\nreturn s;}\n//This gives the lower sum using the inbuilt Jsx calculations.\n//Agrees with the question calculations.\nbrd.create('text',\n[-2-c-1,(c+1)*(c+1)+(c+1)*a+b+5,function(){ return 'Sum='+(JXG.Math.Numerics.riemannsum(f1,s.Value(),'lower',-2-c-1,-3)).toFixed(3); }]);\nbrd.create('text',\n[-2-c-1,-5,'Lower Sum']);\nbrd.create('text',[-2-c-1,-1,0]);\nbrd.create('text',[-3,-1,c]);\n//Custom calculation of the upper bound.\nbrd.create('text',\n[0,(c+1)*(c+1)+(c+1)*a+b+5,function(){ return 'Sum='+usm(c,s.Value(),a,b); }]);\nbrd.create('text',[0,-5,'Upper Sum']);\nbrd.create('text',[0,-1,0]);\nbrd.create('text',[c,-1,c]);\nreturn div;\n", "parameters": [["c", "number"], ["n", "number"], ["a", "number"], ["b", "number"]]}, "plotf": {"language": "javascript", "type": "html", "definition": "\nvar f = function(x){ return x*x+a*x+b; };\nvar div = Numbas.extensions.jsxgraph.makeBoard('400px','400px', {axis:true,showNavigation:false, boundingbox:[-a/2-2,f(c+1),c+4,Math.min(f(-a/2)-2,-5)]});\n\nvar brd=div.board;\n\nvar plot = brd.create('functiongraph',[f,-5,c+5]);\n//var p1=brd.create('point',[0,0],{visible:false,fixed:true});\n//var p2=brd.create('point',[c,-1],{visible:true,fixed:true,size:1,name:c});\n//var p3=brd.create('point',[c,f(c)],{visible:false,fixed:true,size:1,name:''});\n//var p4=brd.create('point',[0,f(0)],{visible:false,fixed:true,size:1,name:''});\n//var c1=brd.create('line',[p1,p2]);\n//var c2=brd.create('line',[p2,p3]);\n\nbrd.create('text',[c,-2,c]);\nvar i1 = brd.create('integral', [[0, c], plot]);\n\nreturn div;\n", "parameters": [["a", "number"], ["b", "number"], ["c", "number"]]}}, "variablesTest": {"maxRuns": 100, "condition": ""}, "statement": "\n

Let $f: \\mathbb{R} \\rightarrow  \\mathbb{R}$ be the function $f(x)=\\simplify{x^2+{a}*x+{b}}$.

\n

{plotf1(a,b,c)}

\n

\n

\n

\n", "parts": [{"prompt": "

Find $a$ such that $f$ is an increasing function for $x \\ge a$ and a decreasing function for $x \\le a$.

\n

$a=\\;$[[0]] (input as a decimal).

", "scripts": {}, "type": "gapfill", "gaps": [{"allowFractions": false, "correctAnswerFraction": false, "minValue": "-a/2", "maxValue": "-a/2", "scripts": {}, "type": "numberentry", "showCorrectAnswer": true, "marks": 1, "showPrecisionHint": false}], "showCorrectAnswer": true, "marks": 0}, {"prompt": "\n

Compute the upper and lower sums over the interval for the partition $[0,\\var{c}]$ into subintervals each of length $\\simplify[all]{{c}/{n}}$

\n

\\[\\Delta = \\{0,\\;\\simplify[all]{{c}/{n}},\\;\\simplify[all]{{2*c}/{n}},\\ldots,\\;\\var{c}\\}\\]

\n

\n

Upper sum = ?[[0]] (Input to 3 decimal places.)

\n

Lower sum = ?[[1]] (Input to 3 decimal places.)

\n", "scripts": {}, "type": "gapfill", "gaps": [{"allowFractions": false, "correctAnswerFraction": false, "minValue": "uppersum-tol", "maxValue": "uppersum+tol", "scripts": {}, "type": "numberentry", "showCorrectAnswer": true, "marks": 2, "showPrecisionHint": false}, {"allowFractions": false, "correctAnswerFraction": false, "minValue": "lowersum-tol", "maxValue": "lowersum+tol", "scripts": {}, "type": "numberentry", "showCorrectAnswer": true, "marks": 2, "showPrecisionHint": false}], "showCorrectAnswer": true, "marks": 0}, {"prompt": "

Suppose we refine the partition into $\\var{2*n}$ subintervals, each of length $\\simplify[all]{{c}/{2*n}}$.

\n

Find the new values of the upper and lower sums:

\n

Upper sum = ?[[0]]  (Input to 3 decimal places).

\n

Lowersum = ?[[1]]   (Input to 3 decimal places).

", "scripts": {}, "type": "gapfill", "gaps": [{"allowFractions": false, "correctAnswerFraction": false, "minValue": "uppersum2-tol", "maxValue": "uppersum2+tol", "scripts": {}, "type": "numberentry", "showCorrectAnswer": true, "marks": 2, "showPrecisionHint": false}, {"allowFractions": false, "correctAnswerFraction": false, "minValue": "lowersum2-tol", "maxValue": "lowersum2+tol", "scripts": {}, "type": "numberentry", "showCorrectAnswer": true, "marks": 2, "showPrecisionHint": false}], "showCorrectAnswer": true, "marks": 0}], "ungrouped_variables": ["a", "tuppersum", "c", "b", "uppersum2", "theint", "n", "lowersum", "lowersum2", "tlowersum", "tol", "uppersum"], "metadata": {"notes": "\n\t\t

06/12/2013:

\n\t\t

Started - to be finished with a fully interactive jsxgraph in Advice (or Steps).

\n\t\t

09/12/2013:

\n\t\t

First version finished.

\n\t\t", "description": "

Approximating integral of a quadratic by Riemann sums . Includes an interactive graph in Advice showing the approximations given by the upper and lower sums and how they vary as we increase the number of intervals.

", "licence": "Creative Commons Attribution 4.0 International"}, "tags": ["approximating integrals", "checked2015", "interactive", "Jsxgraph", "jsxgraph", "JSXgraph", "lower sum", "MAS1601", "MAS2224", "numerics", "quadratic", "Riemann sums", "upper sum"], "showQuestionGroupNames": false, "rulesets": {}, "variables": {"uppersum2": {"templateType": "anything", "group": "Ungrouped variables", "description": "", "name": "uppersum2", "definition": "precround(c^3*(2*n+1)*(4*n+1)/(24*n^2)+a*c^2*(2*n+1)/(4*n)+b*c,3)"}, "lowersum": {"templateType": "anything", "group": "Ungrouped variables", "description": "", "name": "lowersum", "definition": "precround(tlowersum,3)"}, "b": {"templateType": "anything", "group": "Ungrouped variables", "description": "", "name": "b", "definition": "random(1..9)"}, "theint": {"templateType": "anything", "group": "Ungrouped variables", "description": "", "name": "theint", "definition": "precround(c^3/3+a*c^2/2+b*c,3)"}, "n": {"templateType": "anything", "group": "Ungrouped variables", "description": "", "name": "n", "definition": "random(5..20#5)"}, "a": {"templateType": "anything", "group": "Ungrouped variables", "description": "", "name": "a", "definition": "random(1..9)"}, "c": {"templateType": "anything", "group": "Ungrouped variables", "description": "", "name": "c", "definition": "random(1..5)"}, "tlowersum": {"templateType": "anything", "group": "Ungrouped variables", "description": "", "name": "tlowersum", "definition": "c^3*(n-1)*(2n-1)/(6*n^2)+a*c^2*(n-1)/(2*n)+b*c"}, "tuppersum": {"templateType": "anything", "group": "Ungrouped variables", "description": "", "name": "tuppersum", "definition": "c^3*(n+1)*(2n+1)/(6*n^2)+a*c^2*(n+1)/(2*n)+b*c"}, "lowersum2": {"templateType": "anything", "group": "Ungrouped variables", "description": "", "name": "lowersum2", "definition": "precround(c^3*(2*n-1)*(4*n-1)/(24*n^2)+a*c^2*(2*n-1)/(4*n)+b*c,3)"}, "tol": {"templateType": "anything", "group": "Ungrouped variables", "description": "", "name": "tol", "definition": "0.001"}, "uppersum": {"templateType": "anything", "group": "Ungrouped variables", "description": "", "name": "uppersum", "definition": "precround(tuppersum,3)"}}, "contributors": [{"name": "Newcastle University Mathematics and Statistics", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/697/"}, {"name": "Luis Hernandez", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/2870/"}]}]}], "contributors": [{"name": "Newcastle University Mathematics and Statistics", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/697/"}, {"name": "Luis Hernandez", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/2870/"}]}