Question: % Your task for this lab assignment is to correctly implement % the functions called by integration 1 : % leftriemannsum, rightriemannsum, and midpointriemannsum %

%Your task for this lab assignment is to correctly implement
%the functions called by integration1:
% leftriemannsum, rightriemannsum, and midpointriemannsum
%based on their comments, provided code, and examples.
%The function integration1 assumes arg1 is a floating point number a.
%The function integration1 assumes arg2 is a floating point number b.
%The function integration1 assumes arg3 is an integer for n.
%This function assumes a <= b and n >0.
%The function integration1 is already implemented for you to have
%consistent I/O with our examples. After you finish implementing
%the functions aforementioned, you should not change the source
%code in integration1.
function []= integration1(arg1, arg2, arg3)
a = str2num(arg1);
b = str2num(arg2);
n = ceil(str2num(arg3));
fprintf("Let f(x)=3*e^(-x^2).
");
fprintf("Approximating the integral of f(x) over the interval
");
fprintf("[%.8f,%.8f] for n =%i.
", a, b, n);
approx = leftriemannsum(a, b, n);
absError = absoluteerror(approx, a, b);
fprintf("Left hand Riemann sum =%15.8f, absolute error =%15.8f
", approx, absError);
approx = rightriemannsum(a, b, n);
absError = absoluteerror(approx, a, b);
fprintf("Right hand Riemann sum =%15.8f, absolute error =%15.8f
", approx, absError);
approx = midpointriemannsum(a, b, n);
absError = absoluteerror(approx, a, b);
fprintf("Midpoint Riemann sum =%15.8f, absolute error =%15.8f
", approx, absError);
end
%Return sum, the left hand Riemann sum
%of f(x) from a to b using n rectangles.
%You should call f(x) to implement this function.
%Do not use any built-in Matlab functions
%to implement this function.
function [sum]= leftriemannsum(a, b, n)
end
%Return sum, the right hand Riemann sum
%of f(x) from a to b using n rectangles.
%You should call f(x) to implement this function.
%Do not use any built-in Matlab functions
%to implement this function.
function [sum]= rightriemannsum(a, b, n)
end
%Return sum, the midpoint Riemann sum
%of f(x) from a to b using n rectangles.
%You should call f(x) to implement this function.
%Do not use any built-in Matlab functions
%to implement this function.
function [sum]= midpointriemannsum(a, b, n)
end
%Return y, f evaluated at x.
%Call this function to implement
%the other functions above.
%You should not change this function.
function [y]= f(x)
y =3*exp(-x^2);
end
%Return absError, the absolute error between v and
%the area under the curve for f(x) over [a, b].
%You should not change this function.
function [absError]= absoluteerror(v, a, b)
area =-(3*pi^(1/2)*(erf(a)- erf(b)))/2;
absError = abs(v - area);
end

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Accounting Questions!