MATH 156 LAB 5We introduce two new Riemann sums to approximate integrals. The Trapezoid RuleTRAP(NiMlIm5H)=(LHS( NiMlIm5H)+RHS(NiMlIm5H ))/2and the Midpoint Rule, which instead of computing using the values of NiMtJSJmRzYjJSJ4Rw== at the left endpoint NiMtJSN4X0c2IywmJSJpRyIiIkYoISIi and the rightendpoint NiMlJHhfaUc=, it uses the midpoint NiMqJiwmLSUjeF9HNiMsJiUiaUciIiJGKiEiIkYqJSR4X2lHRipGKiIiI0Yr . So we have MID(NiMlIm5H)=NiMtJSRzdW1HNiQtJSJmRzYjKiYsJi0lI3hfRzYjLCYlImlHIiIiRjAhIiJGMCUkeF9pR0YwRjAiIiNGMS9GLztGMCUibkc= .Maple has commands that will plot for us the midpoint rule and compute the midpoint rule.We should introduce the student package. Let us introduce the function NiMvLSUiZkc2IyUieEctJSVzcXJ0R0Ym and consider the integral NiMtJSRpbnRHNiQtJSVzcXJ0RzYjJSJ4Ry9GKTsiIiIiIiU=.f:=x->sqrt(x);with(student):Topic 1: Midpoint RuleThe command for graphing the midpoint rule is middlebox(function (x), x=lowerlimit..upperlimit, number of subintervals);middlebox(f(x), x=1..4, 5);The command to compute numerically the midpoint rule is middlesum(function (x), x=lowerlimit..upperlimit, number of subintervals);middlesum(f(x), x=1..4, 5);As you see, Maple does not evaluate it immediately, so we use the evalf command.evalf(middlesum(f(x), x=1..4, 5));Write commands that show on the graph the midpoint rule with 10, 20, 40 subintervals. Write commands that name these graphs and the graph with 5 subintervals above. Write commands that evaluate the midpoint rule with 10, 20, 40 subintervals.Topic 2: Comparing the midpoint rule with the left-hand sums and right-hand sums.Write commands that name the graphs of the left-hand sums and right-hand sums with 5, 10, 20, 40 subintervals.Write commands that show on the same graph the left-hand sums, the right-hand sums and the midpoint sums with the same number of subintervals. Do not forget to introduce the plots package. What do you notice? Which are larger, the left-hand sums, right-hand sums, or midpoint sums? Can you explain it?Write commands that compute the left-hand sums and right-hand sum and midpoints sums numerically with 5, 10, 20, 40, 80, 160, 320, 640, 1280, 2560 subintervals. You can use a loop. What do you notice?Topic 3: Trapezoid rule.It is easy to calculate the trapezoid rule, as it is the average of the left-hand sum and the right-hand-sum.Write commands that calculate the trapezoid rule, left-hand sums and right-hand sums with 5, 10, 20, 40, 80, 160, 320, 640, 1280, 2560 subintervals. You can use a loop. What do you notice? Which are larger, smaller? Why?Write commands that calculate the trapezoid and midpoint rules with 5, 10, 20, 40, 80, 160, 320, 640, 1280, 2560 subintervals. You can use a loop. What do you notice? Which are larger, smaller? Which are overestimates and which are underestimates of the integral? Why?Maple does not have a command to plot the trapezoid rule automatically, as it was the case for left-hand sum, right-hand sum and midpoint rule. But we can introduce a number of commands to see the graph. The following commands let Maple know of the lower limit, upper limit and the number of subintervals. The length of each subinterval is NiMqJiwmJSJiRyIiIiUiYUchIiJGJiUibkdGKA==. In the following example we choose NiMvJSJuRyIiIw==.a:=1;b:=4;n:=2;Dx:=(b-a)/n;We create a list of numbers in increasing order that represent the points between NiMlImFH and NiMlImJH, where we have split the interval [NiMlImFH,NiMlImJH]. In all we have NiMsJiUibkciIiJGJUYl points.xpoints:=[seq( a+Dx*i, i=0..n)];The next command finds the values of the function NiMtJSJmRzYjJSJ4Rw== at the points we are interested in. valuesoflist:=map(f, xpoints);The next two commands pair together the NiMlInhH and NiMlInlH coordinates to form a list of points we would like to join with a broken line. We call this list datapoints.pair:=(x,y)->[x,y];datapoints:=zip(pair, xpoints,valuesoflist);The next command plots a broken line joining the points in the list datapoints.plot(datapoints, style=line, color=blue);As usual it is nice to name this plot:trap2:=plot(datapoints, style=line, color=blue):We now display the graph of NiMtJSJmRzYjJSJ4Rw== with the broken line we just saw.display(plot(f(x), x=1..4), trap2);If we want to shade the area represented by the trapezoid rule, we use the following commands that shade the area under each part of the broken blue line and give a name to the corresponding graph: trapezoid[i]. We use a loop. for i from 1 to n do trapezoid[i]:=inequal({y<f(xpoints[i])+(f(xpoints[i+1])-f(xpoints[i]))/Dx *(x-xpoints[i])}, x=xpoints[i]..xpoints[i+1], y=0..2, optionsexcluded=(color=white)): od;display(plot(f(x), x=1..4),trapezoid[1], trapezoid[2]);We clearly see that the trapezoid rule in an underestimate.Topic 4: The midpoint rule as a midpoint-tangent-trapezoid rule.We need to graph the tangent line at the midpoints.midpoints:=[seq(a+Dx*(i-0.5), i=1..n)];derivatmidpoints:=map(D(f), midpoints);for i from 1 to n do MID[i]:=inequal({y<f(midpoints[i])+derivatmidpoints[i]*(x-midpoints[i])}, x=xpoints[i]..xpoints[i+1], y=0..2, optionsexcluded=(color=white)): od;display(plot(f(x), x=1..4), MID[1],MID[2], middlebox(f(x), x=1..4, 2));We see that the trapezoids with slanted side the tangent line at the midpoint cover exactly the same area as the midpoint sums. We also see that, because NiMtSSJmRzYiNiNJInhHRiU= is concave downwards, the tangent lines lie above the graph of NiMtJSJmRzYjJSJ4Rw==, so the midpoint rule is an overestimate.Write a command that shows the graph and the comparison of the trapezoid sum and the midpoint sum with NiMiIiM= subintervals.Work all the commands introduced today for the integral NiMtJSRpbnRHNiQqJiIiIkYnJSJ4RyEiIi9GKDtGJyIiIw== with n=1, 2, 4, 8, 16, 32, 64 subintervals. Order in increasing order the left-hand sums, right-hand sums, midpoint suns and trapezoid sums. Explain you answer. Graph your sums for NiMvJSJuRyIiIg==, NiMvJSJuRyIiIw== to explain you answers.