Problem #1: Modified from #5 in the textbook Chapter 01.03 Problem Set The integ
ID: 3111886 • Letter: P
Question
Problem #1: Modified from #5 in the textbook Chapter 01.03 Problem Set The integral2 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 90 60 30 0 15 3 45 6 759105 1 , Figure 1 plot of y xshowing the approximate area under the curve from x = 3 to x = 9 using four rectangles. Write a MATLAB function to calculate the truncation error caused by the left sum method for x2 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: 1) 2) 3) 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. Page 1 of 3 . 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 sumO function. Demonstrate this portion of your code in your reportExplanation / Answer
function [approx, exact , err]=NumericalInt(f,h,x)
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=vpa(abs(approx-exact));
end
clc;
clera all;
f=@(x) x^2;
h=1.5;
x=3:h:9;
[approx, exact , err]=leftintr(f,h,x)
NOTE: bot the files should save in same folder
Answer
approx =
303.7500
exact =
234
err =
69.750000000000000000000000000000
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.