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

2. Write a MATLAB function to implement the composite trapezoidal rule and do th

ID: 3728116 • Letter: 2

Question

2. Write a MATLAB function to implement the composite trapezoidal rule and do the following problems. The input is the function handle f, the integration limits a, b and the number of subintervals m. The output is the approximated integral. 2n for m = 2, 22, 23, , 2s and empirically calculate the order of accuracy. Put m, the error and the order (b) Use your code to calculate o esinz dr for m = 2.22 , 2s. Output the approxim!ated values in format 3. Write a MATLAB function to implement the composite Simpson's rule and do the following problems. The as columns in a matrix and display your results. long. Based on your outputs, please write down the digits that you believe match the exact solution. input is the function handle f, the integration limits a, b and the number of subintervals m. The output is the approximated integral. Redo problem 2 (a) and (b).

Explanation / Answer

Solution for 3 :

for question 2 (a) and interval 2^8

%m = input('enter number of intervals')
%a = input('enter the lower limit a')
%b = input('enter upper limit b')
% above if u want to take inputs
function f(x)= (x)*(exp(-x))*cos(2*x);
m=(2^8);
b=(2*pi);
a=0;
h = (b-a)/m;
integration = f(a);
for i=1:m-1
if (mod(i,2)==1)
integration = integration + (4*f(a+(i*h)));
else if (mod(i,2)==0)
integration = integration + (2*f(a+(i*h)));
end
end
integration = integration + f(b);
integration = integration * (h/3);
disp(integration)

for 2(b) and interval 2^8

%m = input('enter number of intervals')
%a = input('enter the lower limit a')
%b = input('enter upper limit b')
% above if u want to take inputs
function f(x)= exp(sin(x));
m=(2^8);
b=1;
a=0;
h = (b-a)/m;
integration = f(a);
for i=1:m-1
if (mod(i,2)==1)
integration = integration + (4*f(a+(i*h)));
else if (mod(i,2)==0)
integration = integration + (2*f(a+(i*h)));
end
end
integration = integration + f(b);
integration = integration * (h/3);
disp(integration)

Note : this is the solution for composite simpson's rule in the third question.

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