Advertisement
ruhan008

Weddles

Aug 22nd, 2024
294
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.53 KB | None | 0 0
  1. function IW = weddles(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.         md = mod(i, 6);
  10.         func_val = f(a + i * h);
  11.  
  12.         if md == 1 || md == 5
  13.             sum = sum + 5 * func_val;
  14.         elseif md == 2 || md == 4
  15.             sum = sum + func_val;
  16.         elseif md == 3
  17.             sum = sum + 6 * func_val;
  18.         else
  19.             sum = sum + 2 * func_val;
  20.         end
  21.  
  22.     end
  23.  
  24.     IW = (3 * sum * h) / 10;
  25. end
  26.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement