need help with mass transfer modelling

18 views (last 30 days)
Hi guys,
It would be great if someone can help me with this. I am quite new to modelling, I am trying to model this mass transfer equation
dx/dt=K(C*-x)
x is dissolved CO2 in molten carbonate
C* is solubility of CO2 in molten in the equilibrium
So I am trying to get a plot of CL with following conditions
C*= 150 : 250
t= 0 to 1200
k =0.02
thanks
my function code is
function f= ODEfun(x,t)
for C=(150:250)
k=0.05;
dxdt=k*(C-x);
f=[dxdt];
end
end
% I did the below code in separate file where I called the function
tspan= [0 1200];
x=0; %initial condition
[v y]= ode45(@ODEfun,tspan, x);
plot(v,y);
  1 Comment
Sam Chak
Sam Chak on 7 Jul 2022
C has many values.
Why not writing out the first few equations in math notations?
It helps to understand how to translate that into MATLAB code.

Sign in to comment.

Answers (1)

Alan Stevens
Alan Stevens on 7 Jul 2022
Here's one way of doing it:
% You need to do the time integration for each C separately
C = 150:50:250; % Choose your own values of C
tspan = 0:10:1200;
x0 = 0;
lgnd = [];
% Loop through C values
for i = 1:numel(C)
[t, X] = ode45(@(t,x)ODEfn(t,x,C(i)), tspan, x0, C(i));
plot(t,X)
hold on
end
grid
xlabel('time'), ylabel('x')
function dxdt = ODEfn(~ ,x, C)
k = 0.05;
dxdt(:,1) = k*(C-x);
end

Categories

Find more on Particle & Nuclear Physics 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!