Advertisement
STANAANDREY

trapcomp

Apr 3rd, 2023
1,164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.21 KB | None | 0 0
  1. function int = trapcomp(f, m, a, b)
  2.     h=(b-a)/m;
  3.     y=zeros(1,m);
  4.     for i=1:m
  5.        y(i)=f(a + i*h);
  6.     end
  7.     int = (h/2)*(f(a) + f(b) + 2*sum(y(1:m-1)));
  8. end
  9. %trapcomp(f,32,0,4)-integral(f,0,4)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement