Guest User

Untitled

a guest
Jun 23rd, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. function [I] = simpson13(x,f)
  2. [nrx,ncx]=size(x)
  3. [nrf,ncf]=size(f)
  4. if((nrx<>1)|(nrf<>1))then
  5. error('x or f,or both,not colum vector');
  6. abort;
  7. end;
  8. if((ncx<>ncf))then
  9. error('x and f are not of the same lebgth');
  10. abort;
  11. end;
  12. //check the size of the vector x and f is odd
  13. if(modulo(ncx,2)==0)then
  14. disp(ncx,"list size =")
  15. error('list size must be an odd number');
  16. abort;
  17. end;
  18. n = ncx;
  19. xdiff = mtlb_diff(x);
  20. h = xdiff(1,1);
  21. I = f(1,1) + f(1,n);
  22. for j 2:n-1
  23. if(modulo(j,2)==0) then
  24. I = I + 4*f(1,j);
  25. else
  26. I = I + 2*f(1,j);
  27. end;
  28. end;
  29. I = (h/3.0)*I
  30. // end of function simpson 1/3
Add Comment
Please, Sign In to add comment