How can I integrate a set of ODEs given that my initial conditions also change (linearly) within the concerned time span?

2 views (last 30 days)

Accepted Answer

Torsten
Torsten on 6 Apr 2016
Edited: Torsten on 6 Apr 2016
function driver
tstart = 0.0;
tend = 1.0;
flag = 1;
[T1 Y1] =ode45(@(t,y)myfun(t,y,flag),[tstart tend],[0.01;600]);
tstart = 1.0;
tend = 2.0;
flag = 2 ;
[T2 Y2] = ode45(@(t,y)myfun(t,y,flag),[tstart tend],[Y1(end,1);Y1(end,2)]);
tstart = 2.0;
tend = 10.0;
flag = 3 ;
[T3 Y3] = ode45(@(t,y)myfun(t,y,flag),[tstart tend],[Y2(end,1);Y2(end,2)]);
function myfun(t,y,flag)
if flag==1
yin = 0.01;
Tin = 600;
elseif flag==2
yin = 0.01+(t-1)*0.02;
Tin = 600+(t-1)*100;
elseif flag==3
yin = 0.03;
Tin = 700;
end
...
Best wishes
Torsten.
  1 Comment
Maneet Goyal
Maneet Goyal on 6 Apr 2016
Edited: Maneet Goyal on 6 Apr 2016
Thanks a lot Torsten. Function Driver:
tstart = 0;
tend = 1.0;
flag = 1;
[T1, Y1] =ode15s(@(t,y) trancstr(t,y,flag),[tstart tend],[0.01;600]);
tstart = 1.0;
tend = 2.0;
flag = 2 ;
[T2, Y2] = ode15s(@(t,y) trancstr(t,y,flag),[tstart tend],[Y1(end,1);Y1(end,2)]);
tstart = 2.0;
tend = 3.0;
flag = 3 ;
[T3, Y3] = ode15s(@(t,y) trancstr(t,y,flag),[tstart tend],[Y2(end,1);Y2(end,2)]);
t = [T1;T2;T3];
yo = [Y1;Y2;Y3];
plot(t,yo)
grid on
The function used is:
function out = trancstr(t,x,flag)
if flag == 1
yin = 0.01;
Tin = 600;
elseif flag == 2
yin = 0.01+(t-1)*0.02;
Tin = 600+(t-1)*100;
elseif flag == 3
yin = 0.03;
Tin = 700;
end
y = x(1);
T = x(2);
% Constants
Cpg = 1070; % J/kgK
Cps = 1000; % J/kgK
epsi = 0.68;
Q = 0.06555; % m3/s
Ctot = 0.0203; % kmol/m3
alpha = 26900; % m2/m3
V = 6*1e-4; % m3
Mcap = 30; % kg/kmol
enthalpy = 2.84*1e8; % J/kmol
rhog = Ctot*Mcap; % kg/m3
rhos = 2500; % kg/m3
% Other Parameters
k1 = 6.70*1e10*exp(-12556/T);
K1 = 65.5*exp(961/T);
r = (0.05*k1*y)/(T*(1+(K1*y))^2);
% Output
out(1,1) = ((Q*Ctot*(yin-y)) - (alpha*V*r))/(epsi*V*Ctot);
out(2,1) = ((Q*Ctot*Mcap*Cpg*(Tin-T)) + (alpha*V*enthalpy*r))/(V*((epsi*rhog*Cpg)+((1-epsi)*rhos*Cps)));
end
The solver was taking too much time, so I moved to ode15s. The system is, in fact, stiff (Very fast dynamics coupled with very slow dynamics). As the reaction proceeds, the concentration keeps on changing before reaching a steady state and subsequently, heat is generated (it's an exothermic reaction). But this heat is low and is not able to bring a big change to the temperature of the mixture. Hence,the rate of change is concentration is very fast compared to the rate of change in temperature due to the large heat capacity of the reaction mixture.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!