Documentos de Académico
Documentos de Profesional
Documentos de Cultura
numrica
Integracin
CAPITULO V
INTEGRACION NUMERICA
---------------------------------------------------------------------------------------------------------Objetivos: Desarrollar ejercicios de soluciones bsicas y aplicadas a la ingeniera de
Alimentos.
---------------------------------------------------------------------------------------------------------5.1 INTEGRACION NUMERICA
b
f ( x)dx
a
La integral definida
es un nmero y el proceso de calcularlo, con base en
valores de la funcin f; se conoce como integracin numrica o cuadratura. (Esta ltima
palabra se reere a encontrar un cuadrado cuya rea sea igual al rea bajo una curva.)
b
f ( x)dx
a
es una
A . f (x ) R
i 1
Las formas de escoger los xj y los Aj; generan los distintos tipos de cuadratura.
Tal como dijimos al principio de estas notas, frecuentemente lo que se requiere para
clculos numricos son aproximaciones numricas en lugar de soluciones analticas. En
este caso, podemos decir que utilizar integracin numrica es tan importante cuando no
se conoce antiderivada para la funcin como cuando se conoce.
Para presentar la integracin numrica, seguimos a Stewart (1996) y Kincaid y Cheney
(1994). Nos dedicamos nicamente a integrales unidimensionales denidas en
intervalos cerrados. No consideramos otros dominios de integracin ni funciones con
singularidades. Para tratamiento avanzado del tema, sugerimos Isaacson y Keller (1994)
y el libro especializado Davis y Rabinowitz (1984)
-------------------------------------------------------------------------------------------------------------------------------------------------------Alberto L.Huaman Huaman
173
Integracin
f xi xi
f ( x )dx lim
i 1
La cual se llama Integral (Suma) de Riemann, que significa el rea bajo la curva y = f
(x) en un intervalo [a,b].
Si quisiramos obtener una Integral definida para una funcin de dos variables; primero
deberamos suponer que ahora la regin de integracin sera de la forma [a,b][c,d ], es
decir un rectngulo de R2 , la cual la denotamos como R.
Integracin
La ij sima particin tendr forma rectangular. Ahora cabe referirse al rea de esta
particin, que estara dada por:
Aij xi yi
Podemos definir una funcin de dos variables z = f ( x, y) en la regin R, que para la ij
sima particin sera:
f xi, yi xi yi
Bien, veamos ahora su significado geomtrico. Observe la grfica siguiente:
Vij f xi, yi xi yi
-------------------------------------------------------------------------------------------------------------------------------------------------------Alberto L.Huaman Huaman
175
Integracin
Por tanto, si deseamos el volumen bajo la superficie, tendramos que hacer una suma de
volmenes de una cantidad infinita de paralelepdedos, es decir:
m
V lim f xi, yi xi yi
n
m
j 1 i 1
lim f xi, yi x y
n
m
j 1 i 1
Al
denota de la siguiente manera:
d
f ( x, y )dxdy
Integracin
Prctica 5-1
REGLA TRAPEZOIDAL
5.1 REGLA TRAPECIAL
Si la interpolacin se limita al primer orden, y la integral solo se calcula entre los dos
primeros valores de x, es decir entre a y b x1 (n=1), aplicando, se obtiene:
x1
x1
12
f(x)dx
n
y
y
0
0
x
y 0 y1 y0
f(x)dx
x0
h
y 0 y1
2
y como
Integracin
f(x)dx
x n -1
Integracin
h
y n-1 yn
2
f(x)dx
x n -1
h
y 0 yn 2 y1 y2 y3 ... yn1
2
5.1.1
x n x0
n
Formulario
Programa
function varargout = pushbutton1_Callback(h, eventdata, handles, varargin)
-------------------------------------------------------------------------------------------------------------------------------------------------------Alberto L.Huaman Huaman
179
Integracin
f=inline(get(handles.edit1,'string'));
a=str2double(get(handles.edit2,'string'));
b=str2double(get(handles.edit3,'string'));
n=str2double(get(handles.edit4,'string'));
h=(b-a)/n;
s=f(a)+f(b);
for i=2:n
x(i)=a+(i-1)*h;
s=s+2*(f(x(i)));
end
AREA=s*(h/2);
set(handles.edit5,'string',AREA);
function varargout = pushbutton2_Callback(h, eventdata, handles, varargin)
f=inline(get(handles.edit1,'string'));
a=str2double(get(handles.edit2,'string'));
b=str2double(get(handles.edit3,'string'));
n=str2double(get(handles.edit4,'string'));
h=(b-a)/n;
for i=1:n+1
x(i)=a+(i-1)*h;
y(i)=f(x(i));
end
x =[x,b,a,a];
y =[y,0,0,f(a)];
fill(x,y, [0.2 0.6 0.4]);
for i=1:n+1
x(i)=a+(i-1)*h;
y(i)=f(x(i));
end
hold on
ezplot (f,[min(x):0.1:max(x)]);
plot(x,y, '*b')
plot(x,y, 'r')
xlabel('Coordenadas X');
ylabel('Coordenadas Y');
title('METODO DE TRAPECIO');
legend('AREA');
function varargout = pushbutton3_Callback(h, eventdata, handles, varargin)
set(handles.edit1,'string','');
set(handles.edit2,'string','');
set(handles.edit3,'string','');
set(handles.edit4,'string','');
set(handles.edit5,'string','');
function varargout = pushbutton4_Callback(h, eventdata, handles, varargin)
close
-------------------------------------------------------------------------------------------------------------------------------------------------------Alberto L.Huaman Huaman
180
Resultado
Integrar la funcin :
Integracin
- 3 * x dx
Integracin
Prctica 5-2
Figura 5.2 Aproximacin al rea bajo la curva con la frmula de Simpson de 1/3
Si la interpolacin es limitada de segundo orden y la integral solo se calcula entre los
tres primeros valores de x (n=2) y se obtiene:
3
23 2 2 2
2 4 23 2 2 3
22
f(x)dx
h
2y
...
y0 ...
0
0
0
0
6 4
24 6 4
2
x0
x2
Integracin
f(x)dx
x0
1
h
h 2y 0 2 y1 y0 y2 2 y1 y0 .. y0 4 y1 y2
3
3
En forma general:
f(x)dx
x 0- 2
h
yn2 4 yn1 yn
3
f(x)dx
x 0-2
Integracin
h
y0 yn 2 y2 y4 y6 ... yn2 4 y1 y3 y5 ... yn1
3
5.2.1
Formulario
Programa
function varargout = pushbutton1_Callback(h, eventdata, handles, varargin)
f=inline(get(handles.edit1,'string'));
a=str2double(get(handles.edit2,'string'));
b=str2double(get(handles.edit3,'string'));
n=str2double(get(handles.edit4,'string'));
h=(b-a)/n;
for i=1:n+1
x(i)=a+(i-1)*h;
end
if rem(n,2)==0
s=0;
for i=3:2:n+1
s=s+f(x(i-2))+4*f(x(i-1))+f(x(i));
end
I=h*s/3;
-------------------------------------------------------------------------------------------------------------------------------------------------------Alberto L.Huaman Huaman
184
Integracin
set(handles.edit5,'string',I)
else
end
% GRAFICANDO
S=f(a)+f(b);
for i=1:n+1
x(i)=a+(i-1)*h;
y(i)=f(x(i));
end
x =[x,b,a,a];
y =[y,0,0,f(a)];
fill(x,y, [0.8 0.4 0.9]);
for i=1:n+1
x(i)=a+(i-1)*h;
y(i)=f(x(i));
line([x(i),x(i)], [0,f(x(i))]);
end
hold on
ezplot (f,[min(x):0.1:max(x)]);grid on
plot(x,y, '*b')
plot(x,y, 'r')
xlabel('Coordenadas X');
ylabel('Coordenadas Y');
title('METODO DE SIMPSON UN TERCIO');
legend('AREA');
function varargout = pushbutton2_Callback(h, eventdata, handles, varargin)cc c
set(handles.edit1,'string','');
set(handles.edit2,'string','');
set(handles.edit3,'string','');
set(handles.edit4,'string','');
set(handles.edit5,'string','');
function varargout = pushbutton4_Callback(h, eventdata, handles, varargin)cc c
close
Resultado
1
Ingresamos la funcin:
- 3 * x dx
Integracin
Prctica 5-3
33 32 2
34 33 32 3
32
f(x)dx
h
3y
...
0
0
0
0
6 4
24 6 4
2
x0
x3
x3
f(x)dx
x0
x3
f(x)dx
x0
9
9
3
h 2y 0 y1 y0 y2 2 y1 y0 y3 3 y2 3 y1 y0
2
4
8
3
h y0 3 y1 3 y2 y3
8
Integracin
en forma general:
xn
f(x)dx
x 0 -3
3
h yn3 3 yn2 3 yn1 yn
8
f(x)dx
x0
3
h y0 yn 2 y3 y6 y9 ... yn3 3 y1 y2 y4 y5 y7 y8 ... yn2 yn1
8
Figura 5.5 Aproximacin al rea bajo la curva con la frmula de Simpson de 3/8
Integracin
Formulario
Programa
-------------------------------------------------------------------------------------------------------------------------------------------------------Alberto L.Huaman Huaman
188
Integracin
Integracin
Resultado
1
- 3 * x dx
Prctica 5-6
EJERCICIOS RESUELTOS
5.4 EJERCICIOS RESUELTOS
1. Aplicacin en conservacin de alimentos. A partir de los datos experimentales de
humedad de equilibrio para las diferentes humedades relativas, caractersticas del
producto, caractersticas del empaque y condiciones de almacenamiento dado,
-------------------------------------------------------------------------------------------------------------------------------------------------------Alberto L.Huaman Huaman
190
Integracin
0,5
0,754
0,653
9,87
0
7
X (g agua/100 g
2
3,3
4,5
7,4 9,7
ms)
Solucin
Despus de aplicar el programa de regresin, la funcin es:
13,1
18,8
dx
Awe f ( Awi )
Integracin
0 V t L
t
t t
Lt
(1)
Aplicndose los teoremas de valor medio del clculo diferencial e integral se tiene:
t t t V z t t t V
t z
(2)
En donde z es un punto dentro del intervalo t + t.
Dividiendo entre t cuando el lmite t -0 y para cualquier t:
Integracin
V z V
t z
(3)
Por otro lado el balance para el componente A es el siguiente:
t t
0 Vyd t L
x t t
Lx t
(4)
Vyd Lx
t
Lx
t
L( x) x L
L
yd
t
t
(5)
se tiene:
(6)
yd x L Lx
L
x
L
yd
L
L0 L
xL
x
xL0 yd x
(7)
(8)
(9)
x
L
Ln
L0 xL 0 yd x
(10)
-------------------------------------------------------------------------------------------------------------------------------------------------------Alberto L.Huaman Huaman
193
Integracin
Programa DS.m
%DESTILACION SIMPLE AGUA ETANOL
%Programa para obtener la grafica T xy
% para agua y etanol ideal y utilizando
% la correccion de Margules
%% ALBERTO HUAMANI HUAMANI
% Inicio
function DS
clc; clear all;
global A B C T Pt AM i j
% indice para las figuras
fig=1;
-------------------------------------------------------------------------------------------------------------------------------------------------------Alberto L.Huaman Huaman
194
Integracin
%% Datos Experimentales
L0 = 200; % mL (volumen inicial)
L = 172; % mL (volumen residuo)
x0 = 0.47; % frmol (concentracion inicial)
xf = 0.0015; % frmol (concentracion residuo)
Texp = [83 84 85 86 87 88 89 89]; % [oC]
xdest = [0.2150 0.1725 0.1745 0.1603 0.1268 0.0962 0.0844 0.0573];
xres = [0.0088 0.0076 0.0076 0.0039 0.0027 0.0015 0.0000 0.0000];
%% Datos
% nombre de los componentes
componente1=['etanol'];
componente2=['agua'];
% Constantes de Antoine para componente1 y componente2
% ln(Ps(i)) = A(i) - B(i) / (C(i)+T)
A = [8.1122 8.0713];
B = [1592.864 1730.630];
C = [226.184 233.426];
% Coeficientes de Margules
AM=[1.6022 0.7947]; % [A12 A21]
% Calculo de la presion real
Tebexp = Texp(1);
Preal = 10^(A(1)-B(1)/(C(1)+Tebexp));
% Pt = presion de trabajo
Pt = [760 550 Preal]; % mmHg (presion de trabajo [atm ... ref])
for j = 1:length(Pt),
for i = 1:length(A),
Teb(i,j) = B(i)/(A(i)-log10(Pt(j)))-C(i);
end
Trange = linspace(Teb(1,j),Teb(2,j));
T(:,j) = Trange';
for i = 1:length(T)
Ps1(i,j) = 10^(A(1)-B(1)/(C(1)+T(i,j)));
Ps2(i,j) = 10^(A(2)-B(2)/(C(2)+T(i,j)));
K1(i,j) = Ps1(i,j)/Pt(j);
K2(i,j) = Ps2(i,j)/Pt(j);
x1(i,j) = (1-K2(i,j))/(K1(i,j)-K2(i,j));
x2(i,j) = (1-K1(i,j))/(K2(i,j)-K1(i,j));
y1(i,j) = K1(i,j)*(K2(i,j)-1)/(K2(i,j)-K1(i,j));
y2(i,j) = K2(i,j)*(K1(i,j)-1)/(K1(i,j)-K2(i,j));
xini = [x1(i,j) x2(i,j) y1(i,j) y2(i,j)];
[fun val flag] = fsolve(@margules,xini);
xM1(i,j) = fun(1);
xM2(i,j) = fun(2);
yM1(i,j) = fun(3);
yM2(i,j) = fun(4);
funx(i,j) = 1/(yM1(i,j)-xM1(i,j));
Tc(i,j) = T(i,j); % eventual conversion K --> C
-------------------------------------------------------------------------------------------------------------------------------------------------------Alberto L.Huaman Huaman
195
Integracin
end
% para los limites de la inegral
[val0(j) pos0(j)] = min(abs(xM1(:,j)-x0));
[valf(j) posf(j)] = min(abs(xM1(:,j)-xf));
% para la concentracion promedio
[val00(j) pos00(j)] = min(abs(T(:,j)-Texp(1)));
[valff(j) posff(j)] = min(abs(T(:,j)-Texp(end)));
pos = ceil(length(yM1(:,j))/2);
while yM1(pos,j)-xM1(pos,j)>0.025,
pos=pos-1;
end
az=Tc(pos,j);
figure(fig)
plot(x1(:,j),Tc(:,j),':',xM1(:,j),Tc(:,j),xres,Texp,'-.')
hold on
plot([0 1],[Tc(pos,j) Tc(pos,j)],'k--','LineWidth',1.5)
hold on
plot(y1(:,j),Tc(:,j),':',yM1(:,j),Tc(:,j),xdest,Texp,'-.')
title(['Diagrama Txy para ' componente1 '-' componente2...
' @' num2str(Pt(j)) 'mmHg'],...
'FontSize',12,'FontWeight','Bold')
xlabel(['fraccion mol ' componente1])
ylabel('Temperatura [^oC]')
axis([0 1 floor(Tc(1,j)) ceil(Tc(end,j))])
legend('Ideal','Margules',...
'Experimental',['Azeotropo @' num2str(Tc(pos,j)) '^oC'],0)
grid
hold off
fig=fig+1;
end
%% Ultimos Plots
% Comparacion
figure(fig)
title(['Diagrama Txy para ' componente1 '-' componente2],...
'FontSize',12,'FontWeight','Bold')
line(x1(:,1),Tc(:,1),'Color','r','LineStyle','--');
line(xM1(:,1),Tc(:,1),'Color','r');
line(y1(:,1),Tc(:,1),'Color','r','LineStyle','--');
line(yM1(:,1),Tc(:,1),'Color','r');
legend('Ideal','Margules',0)
axis([0 1 floor(min([Tc(1,1) Tc(1,end)]))...
ceil(max([Tc(end,1) Tc(end,end)]))]);
ax1 = gca;
set(ax1,'XColor','k','YColor','r');
ylabel(['Temperatura [^oC] @' num2str(Pt(1)) 'mmHg'])
ax2 = axes('Position',get(ax1,'Position'),...
'XAxisLocation','bottom',...
'YAxisLocation','right',...
-------------------------------------------------------------------------------------------------------------------------------------------------------Alberto L.Huaman Huaman
196
Integracin
'Color','none',...
'XColor','k','YColor','b');
ylabel(['Temperatura [^oC] @' num2str(Pt(end)) 'mmHg'])
line(x1(:,end),Tc(:,end),'Color','b','Parent',ax2,'LineStyle','-.');
line(xM1(:,end),Tc(:,end),'Color','b','Parent',ax2);
line(y1(:,end),Tc(:,end),'Color','b','Parent',ax2','LineStyle','-.');
line(yM1(:,end),Tc(:,end),'Color','b','Parent',ax2);
legend('Ideal','Margules',0)
axis([0 1 floor(min([Tc(1,1) Tc(1,end)]))...
ceil(max([Tc(end,1) Tc(end,end)]))]);
xlabel(['fraccion mol ' componente1])
grid
fig=fig+1;
%% Clculos
% integrales
for i=1:length(Pt),
funxrec = funx(pos0(i):posf(i),i);
int_teo(i) = trapz(xM1(pos0(i):posf(i),i),funxrec);
figure(fig)
plot(xM1(pos0(i):posf(i),i),funxrec)
xlabel('x')
ylabel('1/(y-x)')
axis([0 1 0 ceil(funxrec(end))+10-mod(ceil(funxrec(end)),10)])
grid
fig=fig+1;
end
int_teo=int_teo % a diferentes presiones
der = log(L/L0)
funx_exp=1./(xdest-xres);
int_exp = trapz(xres,funx_exp)
% Grafica 1/(y-x) vs. x
figure(fig)
plot(xres,1./(xdest-xres))
xlabel('x')
ylabel('1/(y-x)')
axis([0 1 0 ceil(funx_exp(end))+10-mod(ceil(funx_exp(end)),10)])
grid
fig=fig+1;
% concentracion
for i=1:length(Pt),
conc(i) = (yM1(pos00(i),i)-yM1(posff(i),i))/2;
end
conc=conc
err=((conc-0.0707)/0.0707)*100
Programa margules.m
%% Function
-------------------------------------------------------------------------------------------------------------------------------------------------------Alberto L.Huaman Huaman
197
Integracin
function f= margules(x)
global A B C T Pt AM i j
x1=x(1);
x2=x(2);
y1=x(3);
y2=x(4);
Ps1(i,j) = 10^(A(1)-B(1)/(C(1)+T(i,j)));
Ps2(i,j) = 10^(A(2)-B(2)/(C(2)+T(i,j)));
gamma1(i,j) = exp(x2^2*(AM(1)+2*(AM(2)-AM(1))*x1));
gamma2(i,j) = exp(x1^2*(AM(2)+2*(AM(1)-AM(2))*x2));
KM1(i,j) = gamma1(i,j)*Ps1(i,j)/Pt(j);
KM2(i,j) = gamma2(i,j)*Ps2(i,j)/Pt(j);
f(1)=(1-KM2(i,j))/(KM1(i,j)-KM2(i,j))-x1;
f(2)=(1-KM1(i,j))/(KM2(i,j)-KM1(i,j))-x2;
f(3)=KM1(i,j)*(1-KM2(i,j))/(KM1(i,j)-KM2(i,j))-y1;
f(4)=KM2(i,j)*(1-KM1(i,j))/(KM2(i,j)-KM1(i,j))-y2;
Resultados
int_teo =
-1.8657 -1.9130 -2.0374
der =
-0.1508
int_exp =
-0.0661
conc =
0.0862 0.1090 0.2475
err =
21.9347 54.1060 250.0400
100
Ideal
Margules
Experimental
98
96
Azeotropo @78.5174oC
94
Temperatura [oC]
Integracin
92
90
88
86
84
82
80
78
0.1
0.2
0.3
0.4
0.5
0.6
fraccion mol etanol
0.8
0.9
92
Ideal
Margules
Experimental
90
88
Azeotropo @70.5481oC
86
Temperatura [oC]
0.7
84
82
80
78
76
74
72
70
0.1
0.2
0.3
0.4
0.5
0.6
fraccion mol etanol
0.7
0.8
0.9
Integracin
Ideal
Margules
Experimental
Azeotropo @83.2241oC
Temperatura [oC]
100
95
90
85
0.1
0.2
0.3
0.4
0.5
0.6
fraccion mol etanol
0.7
0.8
0.9
105
100
100
95
95
90
90
85
85
80
80
0.1
0.2
0.3
0.4
0.5
0.6
fraccion mol etanol
0.7
0.8
0.9
105
Integracin
70
60
1/(y-x)
50
40
30
20
10
0
0.1
0.2
0.3
0.4
0.5
x
0.6
0.7
0.8
0.9
0.1
0.2
0.3
0.4
0.5
x
0.6
0.7
0.8
0.9
70
60
1/(y-x)
50
40
30
20
10
0
Integracin
70
60
1/(y-x)
50
40
30
20
10
0
0.1
0.2
0.3
0.4
0.5
x
0.6
0.7
0.8
0.9
20
18
16
14
1/(y-x)
12
10
8
6
4
2
0
0.1
0.2
0.3
0.4
0.5
x
0.6
0.7
0.8
0.9