Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- clc;
- close;
- clear;
- tic;
- f=@(x)sin(x);
- a=-pi;
- b=pi;
- w=a:0.01:b;
- plot(w, f(w));
- hold on
- line([a,b],[0,0],'color','k')
- quad(f,a,b);
- x=rand;
- h=1;
- s=0;
- n=floor((b-a)/h);
- for i=0:n-1
- s=s+f(a+h+i*h);
- line([a+i*h,a+i*h],[0,f(a+i*h)])
- line([a+i*h,a+(i+1)*h],[f(a+i*h),f(a+(i+1)*h)])
- line([a+(i+1)*h,a+(i+1)*h],[0,f(a+(i+1)*h)])
- end
- s=(s+(f(a+h)+f(a))/2)*n;
- disp(s);
- toc;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement