Kinetics - Matlab System of ODEs Plot Resulting Number of Moles Over Time

3 views (last 30 days)
Hello all,
I'm fairly new to modeling Kinetics in MATLAB so bare with me! Here goes:
I was given a set of 7 differential equations that represent equilibrium expressions. They depend on each other and I want to solve the solutions to the differential equations and plot them on the same graph. This will allow me to visualize the kinetics of the reaction over time by plotting the yield in moles. I cannot figure out how to actually use a solve or ode function in order to solve the complex set of equations in order to plot them all on one plot. Also, the Volume, denoted by dv_dt is used in solving the system, but it won't ultimately be plotted on the graph. I've attached my code below so far. Any help would be greatly appreciated!
Thanks,
Steve
% Biodiesel Kinetics - Group M1 % Stephen Smith
% Constants for Kinetics
% Densities
p_TG = 894; % g/L p_DG = 894; % g/L p_MG = 894; % g/L p_GL = 1240; % g/L p_FAME = 850; % g/L p_M= 755; % g/L
% Molecular Weights
MW_TG = 873.84; % g/mol MW_MG = 353.36; % g/mol MW_FAME = 292.29; % g/mol MW_DG = 613.60; % g/mol MW_GL = 93.12; % g/mol MW_M = 32.04; % g/mol
% Kinetic Reaction Constants
k_1 = 0.079; % L/mol min k_2 = 0.150; % L/mol min k_3 = 0.417; % L/mol min k_4 = 1.600; % L/mol min k_5 = 0.228; % L/mol min k_6 = 0.004; % L/mol min
% Symbols
syms n_TG n_DG n_MG n_M n_FAME n_GL V t
% TG
dTG_dt = [-k_1*(n_TG/V)*(n_M/V)+k_2*(n_DG/V)*(n_FAME/V)]*V
% DG
dDG_dt = [k_1*(n_TG/V)*(n_M/V)-k_2*(n_DG/V)*(n_FAME/V)-k_3*(n_DG/V)*(n_M/V)+k_4*(n_MG/V)*(n_FAME/V)]*V
% MG
dMG_dt = [k_3*(n_DG/V)*(n_M/V)-k_4*(n_MG/V)*(n_FAME/V)-k_5*(n_MG/V)*(n_M/V)+k_6*(n_GL/V)*(n_FAME/V)]*V
% GL
dGL_dt = [k_5*(n_MG/V)*(n_M/V)-k_6*(n_GL/V)*(n_FAME/V)]*V
% FAME
dFAME_dt = [k_1*(n_TG/V)*(n_M/V)-k_2*(n_DG/V)*(n_FAME/V)+k_3*(n_DG/V)*(n_M/V)-k_4*(n_MG/V)*(n_FAME/V)+k_5*(n_MG/V)*(n_M/V)-k_6*(n_GL/V)*(n_FAME/V)]*V
% M
dM_dt = [-k_1*(n_TG/V)*(n_M/V)+k_2*(n_DG/V)*(n_FAME/V)-k_3*(n_DG/V)*(n_M/V)+k_4*(n_MG/V)*(n_FAME/V)-k_5*(n_MG/V)*(n_M/V)+k_6*(n_GL/V)*(n_FAME/V)]*V
% Volume
dV_dt = [(dTG_dt)*(MW_TG)/p_TG +(dDG_dt)*(MW_DG)/p_DG +(dMG_dt)*(MW_MG)/p_MG +(dGL_dt)*(MW_GL)/p_GL +(dFAME_dt)*(MW_FAME)/p_FAME +(dM_dt)*(MW_M)/p_M]
% System of Equation Solver
f = @(t, n_TG, n_DG, n_MG, n_M, n_FAME, n_GL, V) [dTG_dt; dDG_dt; dMG_dt; dGL_dt; dFAME_dt; dM_dt; dV_dt]
% Initial Conditions
init = [35;0;0;0;0;200;100];
% Solve
% Plot

Answers (1)

Torsten
Torsten on 17 Nov 2014
Take a look at the examples provided under
Best wishes
Torsten.

Community Treasure Hunt

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

Start Hunting!