Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- отрезке [0,1]).
- function [J] = method_of_trapezoids(f, a, b, n)
- h = (b - a) / n;
- f = matlabFunction(f);
- h_n = @(i) a + i * h;
- J=0.5*sum(h*(f(h_n(0:n-1))+f(h_n(1:n))));
- fprintf('integral trapezoid method is=%d \n',J);
- syms x
- df=inline(diff(f,x,2),'x');
- x_max=(fminbnd(df, a, b));
- M_2=abs(df(x_max));
- R=(b-a)*M_2*h^2/12;
- I=quad(f,a,b);
- R_r=double(abs(J-I));
- fprintf('error is=%d \n',R);
- fprintf('real bug is =%d \n',R_r);
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement