Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function plot_trapez()
- f = @sin;
- a = 0;
- b = pi;
- fehler = [];
- n_values = 1e3:100:1e4;
- for n=n_values
- fehler(end+1) = abs(2-trapez(f,a,b,n));
- end
- plot(n_values, fehler)
- end
- function I = trapez(f,a,b,n)
- h = (b-a)/n;
- x0 = a/2;
- xn = (a+n*h)/2;
- I = h*(f(x0) + f(xn));
- for j=1:n-1
- xj = a + j*h;
- I = I + f(xj);
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement