SHARE
TWEET

Untitled

a guest Oct 21st, 2019 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function[y] = f(x)
  2.     y = cos(x) / x;
  3. end
  4.  
  5. function[wynik] = simpson(a, b, n)
  6.     x = [a];
  7.     y = [];
  8.     i = 0;
  9.     h = (b - a) / n;
  10.     for i = 2:n+1
  11.       x(i) = x(1) + (i - 1) * h;
  12.     end  
  13.    
  14.     for i = 1:n+1
  15.       y(i) = f(x(i));
  16.     end
  17.    
  18.     wynik = 0;
  19.    
  20.     for i = 1:n+1
  21.       if i == 1 || i == n + 1
  22.         wynik = wynik + y(i);
  23.       else
  24.         if mod(i, 2) == 0
  25.           wynik = wynik + 4 * y(i);
  26.         else
  27.           wynik = wynik + 2 * y(i);
  28.         end
  29.       end
  30.     end;
  31.          
  32.     wynik = wynik * (h / 3);    
  33. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top