// Numbas version: exam_results_page_options {"name": "Compute Riemann sums of a linear function, ", "extensions": ["jsxgraph"], "custom_part_types": [], "resources": [], "navigation": {"allowregen": true, "showfrontpage": false, "preventleave": false, "typeendtoleave": false}, "question_groups": [{"pickingStrategy": "all-ordered", "questions": [{"variable_groups": [], "variables": {"uppersum": {"templateType": "anything", "group": "Ungrouped variables", "definition": "((d-c)*(a*(c+d+sign(a))+2*b))/2", "description": "", "name": "uppersum"}, "d": {"templateType": "anything", "group": "Ungrouped variables", "definition": "if(c <0,-c+random(4..10),c+random(6..10))", "description": "", "name": "d"}, "lowersum2": {"templateType": "anything", "group": "Ungrouped variables", "definition": "(a*(2*c-sign(a)+2*d)+4*b)*(d-c)/4", "description": "", "name": "lowersum2"}, "c": {"templateType": "anything", "group": "Ungrouped variables", "definition": "random(-5..5 except 0)", "description": "", "name": "c"}, "uppersum2": {"templateType": "anything", "group": "Ungrouped variables", "definition": "(a*(2*c+sign(a)+2*d)+4*b)*(d-c)/4", "description": "", "name": "uppersum2"}, "theint": {"templateType": "anything", "group": "Ungrouped variables", "definition": "a/2*(d^2-c^2)+b*(d-c)", "description": "", "name": "theint"}, "lowersum": {"templateType": "anything", "group": "Ungrouped variables", "definition": "(d-c)*(a*(c+d-sign(a))+2*b)/2", "description": "", "name": "lowersum"}, "a": {"templateType": "anything", "group": "Ungrouped variables", "definition": "random(-5..5 except 0)", "description": "", "name": "a"}, "side": {"templateType": "anything", "group": "Ungrouped variables", "definition": "if(a>0,1,0)", "description": "", "name": "side"}, "n": {"templateType": "anything", "group": "Ungrouped variables", "definition": "d-c", "description": "", "name": "n"}, "type": {"templateType": "anything", "group": "Ungrouped variables", "definition": "if(a>0,'increasing','decreasing')", "description": "", "name": "type"}, "b": {"templateType": "anything", "group": "Ungrouped variables", "definition": "random(1..9)", "description": "", "name": "b"}, "monotonic": {"templateType": "anything", "group": "Ungrouped variables", "definition": "if(a<0,\"a decreasing \", \"an increasing \")", "description": "", "name": "monotonic"}}, "ungrouped_variables": ["a", "c", "b", "uppersum2", "d", "theint", "monotonic", "n", "lowersum", "lowersum2", "type", "uppersum", "side"], "question_groups": [{"pickingStrategy": "all-ordered", "questions": [], "name": "", "pickQuestions": 0}], "name": "Compute Riemann sums of a linear function, ", "functions": {"riemann": {"type": "html", "language": "javascript", "definition": "\n//the next four variables are used to scope out the bounding box.\nvar m1=a<0? c*a+b: a>0? d*a+b:0;\nvar m2=a<0? d*a+b: a>0?c*a+b:0;\nvar v1=Math.max(3,m1+2);\nvar v2=Math.min(-3,m2-2);\nvar m=d-c;\nvar div = Numbas.extensions.jsxgraph.makeBoard('400px','400px', {axis:false,showNavigation:false, boundingbox:[2*c-d-7,v1,d+2,v2-5]});\nvar brd=div.board;\nvar xaxis=brd.create('segment',[[2*c-d-7,0],[d+2,0]],{strokeColor:'black',fixed:true});\n//This slider varies the number of partitions. Start off with m\nvar s = brd.create('slider',[[c-5,(v1+v2)/2],[c-1,(v1+v2)/2],[0,m,40]],{name:'n',snapWidth:1});\nn=s.Value();\n//The function for which we are estimating the integral. \n//This displays to the right\nvar f = function(x){ return a*x+b; };\n//Same function but displaced to the left for the lower sum\nvar f1=function(x){return a*(x+d-c+5)+b;};\nvar plot = brd.create('functiongraph',[f,c,d+1]);\nvar plot1=brd.create('functiongraph',[f1,2*c-d-5,c-5]);\n//Two diagrams created using built in function.\nvar os = brd.create('riemannsum',[f,function(){return s.Value();},'upper',c, d ], \n{fillColor:'#ffff00', fillOpacity:0.3});\nvar os1 = brd.create('riemannsum',[f1,function(){return s.Value();},'lower',2*c-d-5, c-5 ], \n{fillColor:'#ffff00', fillOpacity:0.3});\n//Unfortunately the uppersum and lowersum calculations in jsxgraph sometimes does not agree with mine!\n//So have written functions usm and lsm which gives the same result as the question.\n//Have checked this and is OK - still could be checked.\n//lsm and usm are functions which add up arithmetic sequences. The term abs(a)*m/n varies in\n//sign depending on whether or not a<0, decreasing function, or a > 0, increasing.\nvar lsm=function(a,b,c,d,n){\nvar s=m*(a*(c+d)-Math.abs(a)*m/n+2*b)/2;\ns=Numbas.math.precround(Numbas.math.niceNumber(s),3);\nreturn s;}\nvar usm=function(a,b,c,d,n){\nvar s=m*(a*(c+d)+Math.abs(a)*m/n+2*b)/2;\ns=Numbas.math.precround(Numbas.math.niceNumber(s),3);\nreturn s;}\nbrd.create('text',\n[2*c-d-5,v2,function(){ return 'Lower Sum='+lsm(a,b,c,d,s.Value()); }]);\nbrd.create('text',[2*c-d-5-0.2,-0.5,c]);\nbrd.create('text',[c-5+0.2,-0.5,d]);\nbrd.create('text',\n[c,v2,function(){ return 'Upper Sum='+usm(a,b,c,d,s.Value()); }]);\nbrd.create('text',[c-0.2,-0.5,c]);\nbrd.create('text',[d+0.2,-0.5,d]);\n\nreturn div;\n", "parameters": [["a", "number"], ["b", "number"], ["c", "number"], ["d", "number"]]}, "plotf": {"type": "html", "language": "javascript", "definition": "\nvar f = function(x){ return a*x+b; }\nvar m1=a<0? c*a+b: a>0? d*a+b:0;\nvar m2=a<0? d*a+b: a>0?c*a+b:0;\nvar div = Numbas.extensions.jsxgraph.makeBoard('400px','400px', {axis:true,showNavigation:false, boundingbox:[c-5,Math.max(3,m1+2),d+5,Math.min(-3,m2-2)]});\n\nvar brd=div.board;\n\nvar plot = brd.create('functiongraph',[f,Math.min(-3,c-2),Math.max(3,d+2)]);\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\n//brd.create('text',[c,-2,c]);\n//brd.create('text',[d,-2,d]);\nvar i1 = brd.create('integral', [[c,d], plot]);\n\nreturn div;\n", "parameters": [["a", "number"], ["b", "number"], ["c", "number"], ["d", "number"]]}}, "showQuestionGroupNames": false, "parts": [{"scripts": {}, "gaps": [{"showCorrectAnswer": true, "allowFractions": false, "scripts": {}, "type": "numberentry", "maxValue": "uppersum", "minValue": "uppersum", "correctAnswerFraction": false, "marks": 2, "showPrecisionHint": false}, {"showCorrectAnswer": true, "allowFractions": false, "scripts": {}, "type": "numberentry", "maxValue": "lowersum", "minValue": "lowersum", "correctAnswerFraction": false, "marks": 2, "showPrecisionHint": false}], "type": "gapfill", "prompt": "

Compute the upper and lower sums of $f$ for the partition of the interval $[\\var{c},\\var{d}]$ into subintervals each of length 1:

\n

\\[\\Delta = \\{\\var{c},\\var{c+1},\\;\\ldots,\\var{d}\\}.\\]

\n

Note that $f$ is {monotonic} function over this interval.

\n

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

\n

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

", "showCorrectAnswer": true, "marks": 0}, {"scripts": {}, "gaps": [{"showCorrectAnswer": true, "allowFractions": false, "scripts": {}, "type": "numberentry", "maxValue": "uppersum2", "minValue": "uppersum2", "correctAnswerFraction": false, "marks": 2, "showPrecisionHint": false}, {"showCorrectAnswer": true, "allowFractions": false, "scripts": {}, "type": "numberentry", "maxValue": "lowersum2", "minValue": "lowersum2", "correctAnswerFraction": false, "marks": 2, "showPrecisionHint": false}], "type": "gapfill", "prompt": "

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

\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).

", "showCorrectAnswer": true, "marks": 0}], "statement": "\n

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

\n

\n

\n

\n", "tags": ["approximating integrals", "checked2015", "interactive", "jsxgraph", "JSXgraph", "Jsxgraph", "linear function", "lower sum", "MAS1601", "MAS2224", "numerics", "Riemann sums", "upper sum"], "rulesets": {}, "preamble": {"css": "", "js": ""}, "type": "question", "metadata": {"notes": "\n\t\t

09/12/2013:

\n\t\t

First version started.

\n\t\t", "licence": "Creative Commons Attribution 4.0 International", "description": "

Approximating integral of a linear function 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

{plotf(a,b,c,d)}

\n

$f(x)$ is a linear function which is {monotonic} function. It follows that:

\n

1. The lower sum is given by taking the area over each interval $[x_j,x_{j+1}]$ to be $f(x_{\\simplify{j+{1-side}}})\\times(x_{j+1}-x_j)$ as $f(x_{\\simplify{j+{1-side}}})\\lt f(x_{\\simplify{j+{side}}})$

\n

2. The upper sum is given by taking the area over each interval $[x_j,x_{j+1}]$ to be  $f(x_{\\simplify{j+{side}}})\\times(x_{j+1}-x_j)$  as $f(x_{\\simplify{j+{side}}})\\gt f(x_{\\simplify{j+{1-side}}})$

\n

\n

a) In this case, $x_j=j,\\;\\;j=\\var{c},\\var{c+1},\\dots,\\var{d}$ and so the interval length  $x_{j+1}-x_{j}=1$ and so we have the for the lower sum:

\n

Lower sum.

\n


\\[\\begin{eqnarray}\\mbox{LS}=\\sum_{j=\\var{c}}^{\\var{d-1}}f(x_{\\simplify{j+{1-side}}})=\\sum_{j=\\var{c}}^{\\var{d-1}}\\left(\\simplify[all,!collectNumbers,!noLeadingMinus]{{a}*(j+{1-side})+{b}}\\right)&=&{\\var{a}}\\times\\sum_{j=\\var{c}}^{\\var{d-1}}(\\simplify[all,!collectNumbers,!noLeadingMinus]{(j+{1-side}) })+\\var{n*b}\\\\&=&\\var{lowersum}\\end{eqnarray}\\]

\n

We are using the arithmetic series sum: $\\displaystyle \\sum_{j=a}^b j=\\frac{1}{2}(a+b)(b-a+1)$ so that $\\sum_{j=\\var{c}}^{\\var{d-1}}(\\simplify[all,!collectNumbers,!noLeadingMinus]{(j+{side}) })=\\var{(c+d-1+2*side)*(d-c)/2}$.

\n

Upper sum.

\n


\\[\\begin{eqnarray}\\mbox{US}=\\sum_{j=\\var{c}}^{\\var{d-1}}f(x_{\\simplify{j+{side}}})=\\sum_{j=\\var{c}}^{\\var{d-1}}\\left(\\simplify[all,!collectNumbers,!noLeadingMinus]{{a}*(j+{side})+{b}}\\right)&=&{\\var{a}}\\times\\sum_{j=\\var{c}}^{\\var{d-1}}(\\simplify[all,!collectNumbers,!noLeadingMinus]{(j+{side}) })+\\var{n*b}\\\\&=&\\var{uppersum}\\end{eqnarray}\\]

\n

We are using the arithmetic series sum: $\\displaystyle \\sum_{j=a}^b j=\\frac{1}{2}(a+b)(b-a+1)$ so that $\\sum_{j=\\var{c}}^{\\var{d-1}}(\\simplify[all,!collectNumbers,!noLeadingMinus]{(j+{side}) })=\\var{(c+d-1+2*side)*(d-c)/2}$.

\n

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

\n

You can use the slider above to see the effect of changing the number, $n$ of partitions between $\\var{c}$ and $\\var{d}$.

\n

b)

\n

If we double the number of  partitions them we have $x_j=\\frac{j}{2},\\;\\;j=\\var{2*c},\\var{2*c+1},\\ldots,\\var{2*d}$.

\n

Also we have to remember to multiply by the interval length $x_{j+1}-x_j=1/2$.

\n

We have:

\n

Lower sum.

\n


\\[\\begin{eqnarray}\\mbox{LS}=\\sum_{j=\\var{2*c}}^{\\var{2*d-1}}f(x_{\\simplify{j+{1-side}}})\\times \\frac{1}{2}=\\sum_{j=\\var{2*c}}^{\\var{2*d-1}}\\left(\\simplify[all,!collectNumbers,!noLeadingMinus]{{a}*((j+{1-side})/2)+{b}}\\right)\\times \\frac{1}{2}&=&\\frac{\\var{a}}{4}\\times\\sum_{j=\\var{2*c}}^{\\var{2*d-1}}\\left(\\simplify[all,!collectNumbers,!noLeadingMinus]{(j+{(1-side)}) }\\right)+\\var{n*b}\\\\&=&\\var{lowersum2}\\end{eqnarray}\\]

\n

Upper sum.

\n

\\[\\begin{eqnarray}\\mbox{US}=\\sum_{j=\\var{2*c}}^{\\var{2*d-1}}f(x_{\\simplify{j+{side}}})\\times \\frac{1}{2}=\\sum_{j=\\var{2*c}}^{\\var{2*d-1}}\\left(\\simplify[all,!collectNumbers,!noLeadingMinus]{{a}*((j+{side})/2)+{b}}\\right)\\times \\frac{1}{2}&=&\\frac{\\var{a}}{4}\\times\\sum_{j=\\var{2*c}}^{\\var{2*d-1}}\\left(\\simplify[all,!collectNumbers,!noLeadingMinus]{(j+{side}) }\\right)+\\var{n*b}\\\\&=&\\var{uppersum2}\\end{eqnarray}\\]

\n

True value of the integral is:

\n


\\[\\int_{\\var{c}}^{\\var{d}}\\simplify{{a}*x+{b}}\\;dx=\\left[\\simplify{{a}/2*x^2+{b}*x}\\right]_{\\var{c}}^{\\var{d}}=\\var{theint}\\]

\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/"}]}