viernes, 28 de octubre de 2011

Un programa con MATLAB.

Un programa con MATLAB.

Categoría: 1. Programación y electrónica.


El programa calcula y grafica las concentraciones de tres especies químicas que intervienen en una reacción química de la siguiente forma: A <--k1--k2--> B <--k3--k4--> C. El programa emplea el comando ode45 para la solución del sistema de ecuaciones diferenciales, leyendo en primer lugar las ecuaciones escritas en el archivo dy11.m.

Las ecuaciones se plantean de la siguiente manera
rAadelante=-k1CA                                                                rAatrás=k2CB
rBadelante=-k3CB                                                                rBatrás=k4CC
rCadelante=0                                                                        rCatrás=k4CC

Así, el sistema de ecuaciones queda:
dA/dt=-k1CA+k2CB
dB/dt=-k3CB+k4CC
dC/dt=k4CC

A continuación está escrito el código de MATLAB que resuelve este sistema de ecuaciones.

%Solucion de un sistema de ecuaciones diferenciales que representa un
%sistema de reaccion quimica A <--k1--k2--> B <--k3--k4--> C
%Para resolver el sistema de ecuaciones diferenciales, se crea primero el
%archivo dy11.m en el que definimos las ecuaciones diferenciales con la
%funcion cpunto de la siguiente manera:
%
%function Cpunto=dc(t,c)
%global k
%Cpunto(1)=-K(1)*C(1)+K(2)*C(2);
%Cpunto(2)=K(1)*C(1)-K(2)*C(2)-K(3)*C(2)+K(4)*C(3);
%Cpunto(3)=K(3)*C(2)-K(4)*C(3);
%Cpunto=Cpunto';
%
%Para a continuacion resolver el sistema y graficar los perfiles de
%concentracion creamos el siguiente codigo
%
%Datos de entrada
%fprintf('\dame las concentraciones cineticas\')
%K(1)=input('A -> B, K1= ');
%K(2)=input('B -> A, K2= ');
%K(3)=input('B -> C, K3= ');
%K(4)=input('C -> B, k4= ');
%
%fprintf('\Dame las concentraciones iniciales \')
%C0(1)=input('Concentracion inicial de A= ');
%C0(2)=input('Concentracion inicial de B= ');
%C0(3)=input('Concentracion inicial de C= ');
%tmax=input('\Dame el tiempo maximo \tmax= ');
global K
tmax=5;
K=[1 0 2 3];
C0=[1 0 0];
t=0:0.01:tmax;
[t,C]=ode45('dy11',[0,tmax],C0);
plot(t,C)
xlabel('tiempo(seg)')
ylabel('Concentraciones')
legend('CA','CB','CC')



%help global
% GLOBAL Define global variable.
%    GLOBAL X Y Z defines X, Y, and Z as global in scope.
%
%    Ordinarily, each MATLAB function, defined by an M-file, has its
%    own local variables, which are separate from those of other functions,
%    and from those of the base workspace.  However, if several functions,
%    and possibly the base workspace, all declare a particular name as
%    GLOBAL, then they all share a single copy of that variable.  Any
%    assignment to that variable, in any function, is available to all the
%    other functions declaring it GLOBAL.
%
%    If the global variable doesn't exist the first time you issue
%    the GLOBAL statement, it will be initialized to the empty matrix.
%
%    If a variable with the same name as the global variable already exists
%    in the current workspace, MATLAB issues a warning and changes the
%    value of that variable to match the global.
%
%    Stylistically, global variables often have long names with all
%    capital letters, but this is not required.
%
%    See also isglobal, clear, clearvars, who, persistent.


Se puede consultar los siguientes libros:
H. Scott Fogler. 1999. Elementos de ingeniería de las reacciones químicas. Tercera edición. Prentice Hall. México. p.30

David Báez López. 2006. MATLAB con aplicaciones a la ingeniería, física y finanzas. Ed. Alfaomega

Por el momento es todo.
Saludos




No hay comentarios:

Publicar un comentario