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

(In Matlab) Write a script file (i.e. a non-function) “trapezoid.m” that compute

ID: 3676849 • Letter: #

Question

(In Matlab) Write a script file (i.e. a non-function) “trapezoid.m” that computes the integral

of this “f(x)=24sin(10x)+2x^2+4” using the “Multiple-Application” Trapezoid Rule with n = 5, 50, and 500:

Your script file should include:

a) Request from user to input the following values: n, a ( = 0), and b ( = 5).

b) Clear (and nicely formatted) output display of the computed integral “I” and comparison with the actual exact integral value.

c) Clear statement indicating which method was used to compute the integral “I.”

n- Xi) + f(Xn I= (b-a) 200

Explanation / Answer

% trapezoid.m

n=input('Enter the value of n: ');
fx0 = 24*sin(10*0)+2*0^2+4;
fxn = 24*sin(10*n)+2*n^2+4;

a=input('Enter the value of a: ');
b = input('Enter the value of b: ');

sum=0;
for i=1:(n-1)
    sum = sum + 24*sin(10*i) + 2*(i^2) +4;
    disp(sum);
end
sum = 2*sum;
sum = sum+fx0+fxn;
sum = sum*(b-a)/(2*n);
disp('Integral using multiple application rule: ');
disp(sum);
fun = @(x) 24*sin(10*x) +2*x.*x+4;
q= integral(fun, a, b);
disp('Actual Integral: ');
disp(q);

c) integral method in matlab was used to find integral I.