clc
clear all

syms x

prompt = 'Function: ';
f = input(prompt);
prompt = 'a: ';
a = input(prompt);
prompt = 'b: ';
b = input(prompt);
prompt = 'Number of intervals: ';
n = input(prompt);

h = (b-a)/n;

z = a:h:b;
fx = 1:n+1;

sum1=0;

for i =1:1:n+1
    fx(i) = subs(f,x,vpa(z(i)));
    if i >= 2 && i <= n
        sum1 = sum1+2*fx(i);
    end
end

sum = (h/2)*(fx(1)+sum1+fx(n+1));
int = int(f,a,b);
disp(vpa(sum))
X = sprintf('Error:');
disp(X)
disp(vpa(abs(int-sum)))
