func=@(x) 1/x; a=1; b=3; n=7; sum=0; delx=(b-a)/n; for i=0:n; temp=a+(i*delx); temp1=func(temp); if i==0 || i==n sum=sum+temp; else if i/2!=0 sum=sum+2*temp1; else sum=sum+4*temp1; endif endif endfor sum=sum*delx; sum=sum/3; disp(sum);