// Numbas version: finer_feedback_settings {"name": "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": [{"variable_groups": [], "variables": {"tol": {"templateType": "anything", "group": "Ungrouped variables", "definition": "0.001", "description": "", "name": "tol"}, "lowersum2": {"templateType": "anything", "group": "Ungrouped variables", "definition": "precround(c^3*(2*n-1)*(4*n-1)/(24*n^2)+a*c^2*(2*n-1)/(4*n)+b*c,3)", "description": "", "name": "lowersum2"}, "c": {"templateType": "anything", "group": "Ungrouped variables", "definition": "random(1..5)", "description": "", "name": "c"}, "uppersum": {"templateType": "anything", "group": "Ungrouped variables", "definition": "precround(tuppersum,3)", "description": "", "name": "uppersum"}, "uppersum2": {"templateType": "anything", "group": "Ungrouped variables", "definition": "precround(c^3*(2*n+1)*(4*n+1)/(24*n^2)+a*c^2*(2*n+1)/(4*n)+b*c,3)", "description": "", "name": "uppersum2"}, "theint": {"templateType": "anything", "group": "Ungrouped variables", "definition": "precround(c^3/3+a*c^2/2+b*c,3)", "description": "", "name": "theint"}, "lowersum": {"templateType": "anything", "group": "Ungrouped variables", "definition": "precround(tlowersum,3)", "description": "", "name": "lowersum"}, "a": {"templateType": "anything", "group": "Ungrouped variables", "definition": "random(1..9)", "description": "", "name": "a"}, "n": {"templateType": "anything", "group": "Ungrouped variables", "definition": "random(5..20#5)", "description": "", "name": "n"}, "tlowersum": {"templateType": "anything", "group": "Ungrouped variables", "definition": "c^3*(n-1)*(2n-1)/(6*n^2)+a*c^2*(n-1)/(2*n)+b*c", "description": "", "name": "tlowersum"}, "b": {"templateType": "anything", "group": "Ungrouped variables", "definition": "random(1..9)", "description": "", "name": "b"}, "tuppersum": {"templateType": "anything", "group": "Ungrouped variables", "definition": "c^3*(n+1)*(2n+1)/(6*n^2)+a*c^2*(n+1)/(2*n)+b*c", "description": "", "name": "tuppersum"}}, "ungrouped_variables": ["a", "tuppersum", "c", "b", "uppersum2", "theint", "n", "lowersum", "lowersum2", "tlowersum", "tol", "uppersum"], "question_groups": [{"pickingStrategy": "all-ordered", "questions": [], "name": "", "pickQuestions": 0}], "name": "Approximate the integral of a quadratic by Riemann sums, ", "functions": {"plotf1": {"type": "html", "language": "javascript", "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": {"type": "html", "language": "javascript", "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": {"type": "html", "language": "javascript", "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"]]}}, "showQuestionGroupNames": false, "parts": [{"scripts": {}, "gaps": [{"showCorrectAnswer": true, "allowFractions": false, "scripts": {}, "type": "numberentry", "maxValue": "-a/2", "minValue": "-a/2", "correctAnswerFraction": false, "marks": 1, "showPrecisionHint": false}], "type": "gapfill", "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).
", "showCorrectAnswer": true, "marks": 0}, {"scripts": {}, "gaps": [{"showCorrectAnswer": true, "allowFractions": false, "scripts": {}, "type": "numberentry", "maxValue": "uppersum+tol", "minValue": "uppersum-tol", "correctAnswerFraction": false, "marks": 2, "showPrecisionHint": false}, {"showCorrectAnswer": true, "allowFractions": false, "scripts": {}, "type": "numberentry", "maxValue": "lowersum+tol", "minValue": "lowersum-tol", "correctAnswerFraction": false, "marks": 2, "showPrecisionHint": false}], "type": "gapfill", "prompt": "\nCompute 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\nUpper sum = ?[[0]] (Input to 3 decimal places.)
\nLower sum = ?[[1]] (Input to 3 decimal places.)
\n", "showCorrectAnswer": true, "marks": 0}, {"scripts": {}, "gaps": [{"showCorrectAnswer": true, "allowFractions": false, "scripts": {}, "type": "numberentry", "maxValue": "uppersum2+tol", "minValue": "uppersum2-tol", "correctAnswerFraction": false, "marks": 2, "showPrecisionHint": false}, {"showCorrectAnswer": true, "allowFractions": false, "scripts": {}, "type": "numberentry", "maxValue": "lowersum2+tol", "minValue": "lowersum2-tol", "correctAnswerFraction": false, "marks": 2, "showPrecisionHint": false}], "type": "gapfill", "prompt": "Suppose we refine the partition into $\\var{2*n}$ subintervals, each of length $\\simplify[all]{{c}/{2*n}}$.
\nFind the new values of the upper and lower sums:
\nUpper sum = ?[[0]] (Input to 3 decimal places).
\nLowersum = ?[[1]] (Input to 3 decimal places).
", "showCorrectAnswer": true, "marks": 0}], "statement": "\nLet $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", "tags": ["approximating integrals", "checked2015", "interactive", "Jsxgraph", "jsxgraph", "JSXgraph", "lower sum", "MAS1601", "MAS2224", "numerics", "quadratic", "Riemann sums", "upper sum"], "rulesets": {}, "preamble": {"css": "", "js": ""}, "type": "question", "metadata": {"notes": "\n\t\t06/12/2013:
\n\t\tStarted - to be finished with a fully interactive jsxgraph in Advice (or Steps).
\n\t\t09/12/2013:
\n\t\tFirst version finished.
\n\t\t", "licence": "Creative Commons Attribution 4.0 International", "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.
"}, "variablesTest": {"condition": "", "maxRuns": 100}, "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)}
\nWe 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.
\nThe 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)}
\nFinding the Upper and Lower sums Directly.
\nFirst 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*}\\]
\nAlso the interval points between $0$ and $\\var{c}$ are given by $x_j=\\simplify[all,fractionNumbers]{({c}/{n})j},\\;j=0,\\dots,\\var{n}$
\nFor 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}$.
\nWe sum from $r=0$ to $r=\\var{n-1}$ as we have to take the left value of each interval.
\nSo 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}\\]
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}\\]
\nand substituting into the above equation we obtain:
\nLS = $\\var{tlowersum}=\\var{lowersum}$ to 3 decimal places.
\nAs 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 .
\nOr 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}\\]
\nto 3 decimal places.
\nThe 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\nFor $\\var{2*n}$ intervals we obtain:
\n$\\mbox{LS}=\\var{lowersum2}$.
\n$\\mbox{US}=\\var{uppersum2}$.
\nBoth to 3 decimal places.
\n\n\n\n\n\n", "contributors": [{"name": "Newcastle University Mathematics and Statistics", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/697/"}]}]}], "contributors": [{"name": "Newcastle University Mathematics and Statistics", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/697/"}]}