Diferencia entre revisiones de «Reacciones complejas - Grupo 1 A»
De MateWiki
(→Trapecio) |
(→Runge Kutta) |
||
| Línea 119: | Línea 119: | ||
{{matlab|codigo= | {{matlab|codigo= | ||
| + | %PVI por Runge Kutta orden 4 con una h = 0.1 | ||
| + | clear all | ||
| + | %condiciones dadas | ||
| + | y0 = 0; | ||
| + | t0 = 0; | ||
| + | tN = 2; | ||
| + | h = 0.1; | ||
| + | k = 1; | ||
| + | a = 3; | ||
| + | b = 1; | ||
| + | %calculamos N | ||
| + | N = (tN - t0)/h; | ||
| + | %definimos la variable t | ||
| + | t = linspace(t0,tN,N+1); | ||
| + | %funcion y | ||
| + | y = zeros(1,N+1); | ||
| + | |||
| + | y(1)= y0; | ||
| + | |||
| + | %solucion obtenida | ||
| + | for i=1:N | ||
| + | K1 = k*(a - y(i))*(b - y(i)); | ||
| + | K2 = k*(a-(y(i)+K1*h/2))*(b - (y(i)+K1*h/2)); | ||
| + | K3 = k*(a-(y(i)+K2*h/2))*(b - (y(i)+K2*h/2)); | ||
| + | K4 = k*(a-(y(i)+(K3*h)))*(b - (y(i)+K3*h)); | ||
| + | y(i+1)= y(i) + h/6*(K1+(2*K2)+(2*K3)+K4); | ||
| + | end | ||
| + | |||
| + | %Concentracion de los reactivos | ||
| + | ya = zeros(1,N+1); | ||
| + | yb = zeros(1,N+1); | ||
| + | |||
| + | ya = 3.- y; | ||
| + | yb = 1.- y; | ||
| + | |||
| + | |||
| + | %solucion grafica | ||
| + | hold on | ||
| + | plot(t,y,'linewidth',2) | ||
| + | plot(t,ya,'g','linewidth',2) | ||
| + | plot(t,yb,'r','linewidth',2) | ||
| + | legend('Concentracion de C','Concentracion de A','Concentracion de B','Location','best'); | ||
| + | hold off | ||
}} | }} | ||
Revisión del 13:32 26 feb 2015
| Trabajo realizado por estudiantes | |
|---|---|
| Título | Reacciones complejas. Grupo 1A |
| Asignatura | Ecuaciones Diferenciales |
| Curso | Curso 2014-15 |
| Autores | María Ramírez
Ignacio Posada Antonio López-Mateos Pablo Bueno |
| Este artículo ha sido escrito por estudiantes como parte de su evaluación en la asignatura | |
Contenido
1 Introducción
2 Apartado 1
3 ¿Qué sucedería si el proceso fuese reversible?
4 Apartado 3
%PVI por Euler con una h = 0.1
clear all
%condiciones dadas
y0 = 0;
t0 = 0;
tN = 2;
h = 0.1;
k = 1;
%calculamos N
N = (tN - t0)/h;
%definimos la variable t
t = linspace(t0,tN,N+1);
%funcion y
y = zeros(1,N+1);
y(1)= y0;
%solucion obtenida
for i=1:N
y(i+1)=y(i)+ h*(k*(3 - y(i))*(1 - y(i)));
end
%Concentracion de los reactivos
ya = zeros(1,N+1);
yb = zeros(1,N+1);
ya = 3.- y;
yb = 1.- y;
%solucion grafica
hold on
plot(t,y,'linewidth',2)
plot(t,ya,'g','linewidth',2)
plot(t,yb,'r','linewidth',2)
legend('Concentracion de C','Concentracion de A','Concentracion de B','Location','best');
hold off
4.1 Resolución numérica
5 Apartado 4
6 Resolucion por trapecio y runge kutta
6.1 Trapecio
%PVI por Trapecio con una h = 0.1
clear all
%condiciones dadas
y0 = 0;
t0 = 0;
tN = 2;
h = 0.1;
k = 1;
a = 3;
b = 1;
%calculamos N
N = (tN - t0)/h;
%definimos la variable t
t = linspace(t0,tN,N+1);
%funcion y
y = zeros(1,N+1);
y(1)= y0;
%solucion obtenida
for i=1:N
%Definimos tres variables para reducir la ecuación
Q = 1 + (h*k*(a+b))/2;
W = -(h*k)/2;
E = -y(i)- h*k*(1/2)*((a - y(i))*(b - y(i)) + a*b);
y(i+1)=(-Q + sqrt(Q^2- (4*W*E)))/(2*W);
end
%Concentracion de los reactivos
ya = zeros(1,N+1);
yb = zeros(1,N+1);
ya = 3.- y;
yb = 1.- y;
%solucion grafica
hold on
plot(t,y,'linewidth',2)
plot(t,ya,'g','linewidth',2)
plot(t,yb,'r','linewidth',2)
legend('Concentracion de C','Concentracion de A','Concentracion de B','Location','best');
hold off
6.2 Runge Kutta
%PVI por Runge Kutta orden 4 con una h = 0.1
clear all
%condiciones dadas
y0 = 0;
t0 = 0;
tN = 2;
h = 0.1;
k = 1;
a = 3;
b = 1;
%calculamos N
N = (tN - t0)/h;
%definimos la variable t
t = linspace(t0,tN,N+1);
%funcion y
y = zeros(1,N+1);
y(1)= y0;
%solucion obtenida
for i=1:N
K1 = k*(a - y(i))*(b - y(i));
K2 = k*(a-(y(i)+K1*h/2))*(b - (y(i)+K1*h/2));
K3 = k*(a-(y(i)+K2*h/2))*(b - (y(i)+K2*h/2));
K4 = k*(a-(y(i)+(K3*h)))*(b - (y(i)+K3*h));
y(i+1)= y(i) + h/6*(K1+(2*K2)+(2*K3)+K4);
end
%Concentracion de los reactivos
ya = zeros(1,N+1);
yb = zeros(1,N+1);
ya = 3.- y;
yb = 1.- y;
%solucion grafica
hold on
plot(t,y,'linewidth',2)
plot(t,ya,'g','linewidth',2)
plot(t,yb,'r','linewidth',2)
legend('Concentracion de C','Concentracion de A','Concentracion de B','Location','best');
hold off


