CSTR reactor dynamic model with matlab

14 次查看(过去 30 天)
I try to analys to cstr reactor. There is an sample
question:
formulas:
Output sample and data inputs:
I write these code:
clc; clear all; close all;
% variables
T = 350; % K
Ti = 300; % K
Tcc = 300; % K
q = 100; % L/dk
Cai = 1; % Mol/L
V = 100; % L
p = 1000; % g/L
c = 0.239; % J/gK
ER = 8750; % K
k0 = 7.2*10^10; % dk^-1
UA = 5*10^4; % J/dkK
DHR = 5*10^4; % J/Mol
Ca = 0.5; % mol/L
Tc=305;
Q=UA*(Tc-T)
k = k0*(exp(-ER/T))
% function
f = @(t, Tc) ((c*(Ti-T)+(DHR)*V*k*Ca+UA*(Tc-T))/(p*V*c));
% time and step
tspan = [0 10];
dt = 0.1;
% solution
[t, Tc] = ode15s(f, tspan(1):dt:tspan(2), Ti);
% plot
plot(t, Tc)
xlabel('Time (min)')
ylabel('Tc (K)')
title('Temperature Profile of the Reactor')
But i cant take same results like sample output. Whats wrong and how can i fix it?
Thank u for your time.
  1 个评论
Sam Chak
Sam Chak 2023-5-11
Have you checked the equation clearly and show that they are exactly the same?
% solution
[t, Tc] = ode15s(f, tspan(1):dt:tspan(2), Ti);
% plot
plot(t, Tc)
xlabel('Time (min)')
ylabel('Tc (K)')
title('Temperature Profile of the Reactor')

请先登录,再进行评论。

回答(1 个)

Vanesa
Vanesa 2024-5-24
% Parámetros del reactor y del proceso
V_max = 0.4; % Volumen máximo del reactor en litros (0.4 L = 400 ml)
F_in = 0.01; % Flujo inicial de entrada en L/s
C_oil_in = 0.5; % Concentración del aceite en la entrada en mol/L (suponiendo)
C_NaOH_in = 0.5; % Concentración de NaOH en la entrada en mol/L (suponiendo)
k = 0.1; % Constante de velocidad de reacción en 1/s (suponiendo)
T_in = 321; % Temperatura de entrada en K (48°C)
T_ref = 321; % Temperatura de referencia en K (48°C)
rho = 1000; % Densidad del líquido en kg/m^3
% Parámetros de control
Kp_T = 2.0; % Ganancia proporcional del controlador de temperatura
Ki_T = 1.0; % Ganancia integral del controlador de temperatura
Kp_F = 1.0; % Ganancia proporcional del controlador de flujo
Ki_F = 0.5; % Ganancia integral del controlador de flujo
Kp_L = 3.0; % Ganancia proporcional del controlador de nivel
Ki_L = 1.5; % Ganancia integral del controlador de nivel
% Inicialización de variables
C_oil = 0.25; % Concentración inicial de aceite en el reactor en mol/L (suponiendo)
C_NaOH = 0.25; % Concentración inicial de NaOH en el reactor en mol/L (suponiendo)
T = 321; % Temperatura inicial del reactor en K
T_setpoint = 321; % Setpoint de temperatura en K (48°C)
F_setpoint = 0.01; % Setpoint de flujo en L/s
L_setpoint = 0.3; % Setpoint de nivel en L (300 ml)
V = 0.3; % Volumen inicial del reactor en L (300 ml)
% Variables para la integración numérica
dt = 0.01; % Paso de tiempo en s
t_final = 2000; % Tiempo de simulación en s
t = 0:dt:t_final; % Vector de tiempo
n = length(t);
% Inicialización de vectores para almacenar resultados
C_oil_vec = zeros(1, n);
C_NaOH_vec = zeros(1, n);
T_vec = zeros(1, n);
F_in_vec = zeros(1, n);
V_vec = zeros(1, n);
% Variables de error integradas para el control integral
error_T_int = 0;
error_F_int = 0;
error_L_int = 0;
for i = 1:n
% Cálculo de la reacción
r_oil = k * C_oil * C_NaOH; % Tasa de reacción en mol/(L·s)
% Ecuaciones de balance de masa y energía
dC_oil_dt = (F_in * (C_oil_in - C_oil) - r_oil * V) / V;
dC_NaOH_dt = (F_in * (C_NaOH_in - C_NaOH) - r_oil * V) / V;
dT_dt = (F_in * (T_in - T) + r_oil * V * (T_ref - T)) / V;
% Ecuación de balance de volumen
dV_dt = F_in - F_setpoint;
% Actualización de las variables de estado
C_oil = C_oil + dC_oil_dt * dt;
C_NaOH = C_NaOH + dC_NaOH_dt * dt;
T = T + dT_dt * dt;
V = V + dV_dt * dt;
% Controlador de temperatura
error_T = T_setpoint - T;
error_T_int = error_T_int + error_T * dt;
F_in_T = Kp_T * error_T + Ki_T * error_T_int;
% Controlador de flujo
error_F = F_setpoint - F_in;
error_F_int = error_F_int + error_F * dt;
F_in_F = Kp_F * error_F + Ki_F * error_F_int;
% Controlador de nivel
error_L = L_setpoint - V;
error_L_int = error_L_int + error_L * dt;
F_in_L = Kp_L * error_L + Ki_L * error_L_int;
% Ajuste del flujo de entrada basado en controladores
F_in = F_in + F_in_T + F_in_F + F_in_L;
% Asegurarse de que el volumen no exceda el máximo
if V > V_max
V = V_max;
F_in = 0;
end
% Asegurarse de que el flujo de entrada sea positivo
if F_in < 0
F_in = 0;
end
% Almacenamiento de resultados
C_oil_vec(i) = C_oil;
C_NaOH_vec(i) = C_NaOH;
T_vec(i) = T;
F_in_vec(i) = F_in;
V_vec(i) = V;
end
% Gráficas de resultados
figure;
subplot(5,1,1);
plot(t, C_oil_vec);
xlabel('Tiempo (s)');
ylabel('Concentración de Aceite (mol/L)');
title('Concentración de Aceite en el Reactor');
subplot(5,1,2);
plot(t, C_NaOH_vec);
xlabel('Tiempo (s)');
ylabel('Concentración de NaOH (mol/L)');
title('Concentración de NaOH en el Reactor');
subplot(5,1,3);
plot(t, T_vec);
xlabel('Tiempo (s)');
ylabel('Temperatura (K)');
title('Temperatura del Reactor');
subplot(5,1,4);
plot(t, F_in_vec);
xlabel('Tiempo (s)');
ylabel('Flujo de Entrada (L/s)');
title('Flujo de Entrada al Reactor');
subplot(5,1,5);
plot(t, V_vec);
xlabel('Tiempo (s)');
ylabel('Volumen (L)');
title('Nivel de Líquido en el Reactor');

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

产品


版本

R2018a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by