How to interpret mass conservation in MatLab
Show older comments
Hey there, I am using MatLab to get a time dependent change of 24 species with 24 differential equations. As they all are chemical reactions, I need to conserve the initial mass. For example, A=x(1) B=x(2) C=x(3), all of these has their own differential equations like dxdt(1), dxdt(2), dxdt(3). Initial concentration of these are given as, lets say [1 0 0] and imagine that these are interconvertable, A is converted to B and C is converted to C as time passes. What I want is to keep the total concentration of these three species at exactly 1, neirther the sum of them nor the one of them should exceed 1. By simple logic, when I try to enter A+B+C=1, MatLab give me an error. I know somebody else already asked such a question about mass conservation but he/she has not get a proper answer. So I wanted to ask this again. Thank you so much for your help P.S. I am using ode45 as this is the only one that I know
Answers (2)
Walter Roberson
on 11 Aug 2015
Only pass two values into your ode and calculate the third:
A = x(1);
B = x(2);
C = 1 - (A+B);
You do not need the third differential equation because if it does not exactly mirror the gains or losses of the first two then the equations would not be preserving mass.
Torsten
on 12 Aug 2015
0 votes
If your concentrations are in [kg/m^3], check whether
dxdt(1)+dxdt(2)+dxdt(3)=0.
Then mass conservation should automatically be satisfied (without any additional constraint).
Best wishes
Torsten.
Categories
Find more on Chemistry in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!