Advertisement
Guest User

dla pana Marcina

a guest
Dec 12th, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.42 KB | None | 0 0
  1. clc;
  2. close;
  3. clear;
  4. tic;
  5. f=@(x)sin(x);
  6. a=-pi;
  7. b=pi;
  8. w=a:0.01:b;
  9. plot(w, f(w));
  10. hold on
  11. line([a,b],[0,0],'color','k')
  12. quad(f,a,b);
  13. x=rand;
  14. h=1;
  15. s=0;
  16. n=floor((b-a)/h);
  17. for i=0:n-1
  18. s=s+f(a+h+i*h);
  19. line([a+i*h,a+i*h],[0,f(a+i*h)])
  20. line([a+i*h,a+(i+1)*h],[f(a+i*h),f(a+(i+1)*h)])
  21. line([a+(i+1)*h,a+(i+1)*h],[0,f(a+(i+1)*h)])
  22. end
  23. s=(s+(f(a+h)+f(a))/2)*n;
  24. disp(s);
  25. toc;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement