Páginas

metodo del trapecio

clc
clear all
y=inline('1/x')
a=1;
b=2;
n=4;
x0=a;
h=(b-a)/4;
i=1;
s=0;
disp('-------x-------y---------integral')
while i<=n
x1=x0+h;
y0=y(x0);
y1=y(x1);
s=s+h*(y0+y1)/2;
fprintf('\n%10.5f %10.5f %10.5f \n ',x1,y1,s)
x0=x1;
i=i+1;
end