Professional Documents
Culture Documents
Mtodos de integracin
PROGRAMA
function Simpson
f1=input('ingrese funcion: ','s');
a=input('ingrese valor de a: ');
b=input('ingrese valor de b: ');
n=input('ingrese valor de n: ');
h=(b-a)/n;
X=zeros(1,(n+1));
f=inline(f1);
X(1,1)=a;
syms x
z1=int(sym(f1),a,b);
z=double(z1);
for i=1:1:n
X(i+1)=X(i)+h;
end
I=0;
for i=1:1:n
I=I+(h/6)*((f(X(i))+4*f((X(i)+X(i+1))/2))+f(X(i+1)));
end
ezplot(f1,[a,b]),grid,title('SIMPSON [1/3]'),xlabel('eje X'),ylabel('eje
Y'),text(0,0,'Origen')
hold on
for i=1:1:n
plot([X(i),X(i)],[0,f(X(i))])
plot([X(i),(X(i)+X(i+1))/2],[f(X(i)),f((X(i)+X(i+1))/2)])
plot([(X(i)+X(i+1))/2,X(i+1)],[f((X(i)+X(i+1))/2),f(X(i+1))])
plot([X(i+1),X(i+1)],[f(X(i+1)),0])
end
fprintf('LA RESPUESTA ES: %5.4f\n ',I)
ER=(abs(z-I)/abs(z))*100;
disp('EL ERROR RELATIVO ES:')
disp(ER)
3
a) I =
1
( 1+lnx x ) dx n=2
SIMPSON [1/3]
COMPILACION:
1
ingrese funcion:
(1+log(x))/x
0.95
ingrese a: 1
0.9
ingrese b: 3
eje Y
0.85
ingrese n: 2
0.0574
0.7
b) I = ( x 2 x 3+ 1 ) dx n=2
0
SIMPSON [1/3]
COMPILACION:
60
ingrese valor de n: 2
0.1288 0 Origen
c) I = ( x 2 Sen x ) dx n=2
0
SIMPSON [1/3]
COMPILACION: 4
ingrese valor de a: 0 3
2.5
ingrese valor de b: 2
2
eje Y
ingrese valor de n: 2
1.5
LA RESPUESTA ES: 2.4628
1
EL ERROR RELATIVO ES:
0.5
0.2692
0 Origen
d) I = ( x e2 x +1 ) dx n=2
1
SIMPSON [1/3]
COMPILACION: 300
ingrese funcion:
250
x*exp(2*x+1)
ingrese valor de b: 2
eje Y
150
ingrese valor de n: 2
100
LA RESPUESTA ES: 106.3670
0.0738
0
1 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2
eje X
1
e) I = ( x 3 x 2+ 1 ) dx n=2
0
COMPILACION:
SIMPSON [1/3]
ingrese funcion: 1.5
x^3*(x^2+1)^(1/2)
ingrese valor de a: 0
ingrese valor de b: 1 1
LA RESPUESTA ES:
0.3223
0.5
EL ERROR RELATIVO
ES:
0.1237
0 Origen
PROGRAMA
function Simpsontresoctavos
f1=input('ingrese funcion: ','s');
a=input('ingrese valor de a: ');
b=input('ingrese valor de b: ');
n=input('ingrese valor de n: ');
h=(b-a)/n;
X=zeros(1,(n+1));
f=inline(f1);
X(1,1)=a;
syms x
z1=int(sym(f1),a,b);
z=double(z1);
R=zeros(1,n);
T=zeros(1,n);
for i=1:1:n
X(i+1)=X(i)+h;
end
for i=1:1:n
R(i)=X(i)+h/3;
T(i)=X(i+1)-h/3;
end
I=0;
for i=1:1:n
I=I+(h/8)*(f(X(i))+3*f(R(i))+3*f(T(i))+f(X(i+1)));
end
ezplot(f1,[a,b]),grid
title('SIMPSON (3/8)')
xlabel('eje X')
ylabel('eje Y')
text(0,0,'Origen')
hold on
for i=1:1:n
plot([X(i),X(i)],[0,f(X(i))])
plot([X(i),R(i)],[f(X(i)),f(R(i))])
plot([R(i),T(i)],[f(R(i)),f(T(i))])
plot([T(i),X(i+1)],[f(T(i)),f(X(i+1))])
plot([X(i+1),X(i+1)],[f(X(i+1)),0])
end
fprintf('LA RESPUESTA ES:%5.4f\n ',I)
ER=(abs(z-I)/abs(z))*100;
fprintf('EL ERROR RELATIVO ES:%5.4f\n ',ER)
?
3
a) I =
1
( 1+lnx x ) dx n=2
SIMPSON (3/8)
COMPILACION: 1
ingrese valor de a: 1
0.9
ingrese valor de b: 3
eje Y
0.85
ingrese valor de n: 2
0.8
LA RESPUESTA ES: 1.7016
0.75
EL ERROR RELATIVO ES:
0.0272
0.7
b) I = ( x 2 x 3+ 1 ) dx n=2
0
SIMPSON (3/8)
COMPILACION:
120
ingrese funcion:
x^2*(x^3+1)^(1/2) 100
ingrese valor de a: 0 80
eje Y
ingrese valor de b: 4 60
ingrese valor de n: 2 40
116.3008
20
c) I = ( x 2 Sen x ) dx n=2
0
SIMPSON (3/8)
4
COMPILACION:
3.5
ingrese funcion: x^2*sin(x)
3
ingrese valor de a: 0
2.5
ingrese valor de b: 2 2
eje Y
ingrese valor de n: 2 1.5
0.1187
0 Origen
d) I ( x e2 x+1 ) dx n=2
1
COMPILACION:
ingrese valor de n: 2
250
LA RESPUESTA ES: 106.3235
200
EL ERROR RELATIVO ES:
0.0330
eje Y
150
100
50
0
1 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2
eje X
1
e) I = ( x 3 x 2+ 1 ) dx n=2
0
COMPILACION:
ingrese valor de a: 0
SIMPSON (3/8)
ingrese valor de b: 1
1.5
ingrese valor de n: 2
0.5
0 Origen