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

3. Construct an algorithm called simpsons7 that takes three inputs; the integran

ID: 3167626 • Letter: 3

Question

3. Construct an algorithm called simpsons7 that takes three inputs; the integrand, the lower bound of the integration and the upper bound of the integration. The function should compute and output three different approximations using seven segments to the integral for the given conditions. You may call simpson13 and simpson38 as sub-functions. Compute the integral below using 1-x+8x3 - 0.25xdr (a) A single application of the trapezoidal rule (b) A composite application of the trap with n-7 (c) A single application of the simpson's 1/3 rule (d) A single application of the simpson's 3/8 method, and (e) Three approximations using the composite simpson's n-7 algorithms you created (f) Compare each numerical estimate to the analytical solution (calculate by hand) using true percent relative error. Display results in table with column header.

Explanation / Answer

%%% Matlab code is

syms x
f=1-x+8*x^3-0.25*x^5;
a=-2;
b=3;
m=(a+b)/2;
k=linspace(a,b,7);

%%% a) a single application of trapezoidal rule
y(1)=(b-a)*(subs(f,b)+subs(f,a))/2;

%%% b) a composite application with trap n= 7
gh=0;
for n=2:6;
gh=gh+2*subs(f,k(n));
end
y(2)=(b-a)/7*(subs(f,a)+subs(f,b)+gh)/2;

%%% c ) single application of simpson 1/3rd
y(3)=(b-a)/6*(subs(f,a)+4*subs(f,m)+subs(f,b));

%%% d) single application of simpson 3/8th rule
y(4)=(b-a)/8*(subs(f,a)+3*subs(f,(2*a+b)/3)+3*subs(f,(a+2*b)/3)+subs(f,b));

% % e) composite application of simpson 1/3 rd rule
gh=0;

for n=2:6
if ( mod(n,2)==0)
gh=gh+4*subs(f,k(n));
else
gh=gh+2*subs(f,k(n));
end
end
y(5)=(b-a)/n*(subs(f,a)+subs(f,b)+gh)/3;

% % e) composite application of simpson 3/8 rd rule
gh=0;

for n=2:6
if ( mod(n-1,3)~=0)
gh=gh+3*subs(f,k(n));
else
gh=gh+2*subs(f,k(n));
end
end
y(6)=3*(b-a)/n/8*(subs(f,a)+subs(f,b)+gh);

%%% Actual value
y_act= subs(int(f,-2,3));
%%% Calculating relative error

rel_err=abs((y-y_act)/y_act);

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