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

(MATLAB) The following questions need to be programmed using MATLAB. I need help

ID: 3108765 • Letter: #

Question

(MATLAB) The following questions need to be programmed using MATLAB.

I need help in questions 1 and 2(a, b). I am aware that there is a solution for these questions founded in the textbook solutions on Chegg, but please do not use their codes! I would like to see different methods used to answer these questions. I will report for plagiarism if it's the same! Thank you.

1. Write real function Trapezoid Uniform f, a, b, n) the composite trapezoid rule with n equal subintervals. 2. (Continuation) Test the code written in the preceding computer problem on the following functions. In each case, compare with the correct answer. sinx dx ab. l et dx c. arctan x dx J 0 J 0

Explanation / Answer

syms x
a=input('Enter Lower limit: ');
b=input('Enter Upper Limit: ');
n=input('Enter Interval Length: ');
t=linspace(a,b,n+1);
f=input('Enter Function (x as dependent variable): ');
fval=subs(f,x,t);
h=(b-a)/n;
s=0;
for i=1:n+1
    if i==1
        s=s+fval(i);
    elseif i==n+1
        s=s+fval(i);
    else
        s=s+(2*fval(i));
    end
end
s=h*s/2;
fprintf('Integral value from trepezoidal method is %d',s);
disp(' ');
fprintf('Exact Integral value is');
I=int(f,x,a,b)

Note:

i) u can use arctan function as atan(x),

ii) you can use any function with any intervals.