Advertisement
ruhan008

Simpson Three Eight

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