Guest User

Untitled

a guest
Aug 21st, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scilab 0.27 KB | None | 0 0
  1. function [z] = trap(f,a,b,n)
  2.     s = f(a);
  3.     c = a;
  4.     dx = (b-a)/n
  5.     for i=1:1:n-1
  6.         d = a+i*dx
  7.         s = s + 2*f(d)
  8.     end
  9.     s = s + f(b)
  10.     z = s/2;
  11. endfunction
  12.  
  13.  
  14. function y = fun(x)
  15.     y = x^2
  16. endfunction
  17.  
  18. a = trap(fun, 0, -5 , 5)
  19. disp(a)
Add Comment
Please, Sign In to add comment