La Regla Del Trapecio en Matlab
La Regla Del Trapecio en Matlab
La Regla Del Trapecio en Matlab
CODIGO:
clc
clear
close
syms x
grid on
ezplot(f,(-2:-1))
if n==1
x=b;
fb=eval(f);
x=a;
fa=eval(f);
Ireal= (b-a)*(fa+fb)/2;
I=int(f);
x=a;
fa=eval(I);
x=b;
fb=eval(I);
Iaprox=(fb-fa);
Ereal = abs(Ireal-Iaprox);
else if n>1
x=b;
fb=eval(f);
x=a;
fa=eval(f);
Ireal= (b-a)*(fa+fb)/2;
f=inline(f);
h=(b-a)/n;
Iaprox=fa+fb;
for i=1:n-1
x=a+i*h;
Iaprox=Iaprox+2*f(x);
end
Iaprox=(h/2)*Iaprox; a=0;
Ereal=abs(Ireal-Iaprox);
end
end