Advertisement
ruhan008

Trapezoidal

Aug 22nd, 2024
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.33 KB | None | 0 0
  1. function IT = trapezoidal(a, b, n)
  2.    
  3.     f = @(x) sqrt(1 - 0.162 * (sin(x) ^ 2));
  4.     h = (b - a) / n;
  5.    
  6.     sum = 0;
  7.  
  8.     for i = 0 : n
  9.  
  10.         if i == 0 || i == n
  11.             sum = sum + f(a + i * h);
  12.         else
  13.             sum = sum + 2 * f(a + i * h);
  14.         end
  15.  
  16.     end
  17.  
  18.     IT = (sum * h) / 2;
  19. end
  20.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement