Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The integral integral^9_3 x^2 dx can be calculated approximately by the left sum

ID: 3111858 • Letter: T

Question

The integral integral^9_3 x^2 dx can be calculated approximately by the left sum method (finding the area of multiple rectangles whose top left corners lie on the curve). Figure 1 shows such an approximation with 4 rectangles. Write a MATLAB function to calculate the truncation error caused by the left sum method for integral^9_3 x^2 dx. Your function should meet the following requirements: It should be named NumericalInt It should have the number of rectangles as the sole input argument. It should have one output variable-a row vector with three elements: the first element is the exact value of the integral: the second element is the approximate value: and the third element is the truncation error. All rectangles should be of equal width. Demonstrate this portion of your code in your report. Use a for-end loop to calculate the total area of the rectangles. Do NOT use the built-in sum function. Demonstrate this portion of your code in your report.

Explanation / Answer

clc;
clear all;
f=@(x) x^2;
format short
h=1.5;
x=3:h:9;
s=0;
for i=1:length(x)
s=s+f(x(i))*h;
end
approx=s
syms y
exact=int(y^2,3,9)
err=abs(approx-exact)

[exact approx (err)]

approx =

303.7500


exact =

234



err =

279/4



ans =

[ 234, 1215/4, 279/4]

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote