ode45 code not producing correct results

3 ビュー (過去 30 日間)
Najeem Afolabi
Najeem Afolabi 2020 年 12 月 19 日
コメント済み: Najeem Afolabi 2020 年 12 月 19 日
clear all; close all
clc
%SEMI-BATCH CODE CONCENTRATION AS A FUNCTION OF TIME
%time span specification
timeStart = 0; timeEnd = 200;%s
timeSpan = [timeStart, timeEnd];
%initial condition specification
initCA = 0.2; initCB = 0.1; initCC = 0; initCD = 0; %mol/m^3
initCon= [initCA, initCB, initCC, initCD];
%ODE solver CSTR
[time, Csemi] = ode45(@diffsemi, timeSpan, initCon,[]);
%plot CSTR
figure (1)
plot(time, Csemi, 'x')
grid on
xlabel('time [s]')
ylabel('concentration [mol/m^3]')
legend('c_A','c_B','c_C','c_D')
function dcdt = diffsemi(t, C)
cA0 = 0.2; %mol/L
cB0 = 0.1; %mol/L
V0 = 0;
Q0A = 1.5*10*-3;
Q0B = 1.5*10*-3;
Q0 = Q0A + Q0B;
V = Q0*t + V0;
k1 = 100; %L/(mol*s)
k2 = 0.15; %L/(mol*s)
%Rate equations
rA = -(k1*C(1)^2*C(2))-(k2*C(1)*C(2));
rB = rA;
rC = (k1*C(1)^2*C(2));
rD = (k2*C(1)*C(2));
% differential equations
dcdt = [ Q0A*(cA0/V) - Q0*(C(1)/V) - (-rA);
Q0B*(cB0/V) - Q0*(C(2)/V) - (-rB);
-Q0*(C(3)/V) + rC;
-Q0*(C(4)/V) + rD];
end
So I have this problem that I'm trying to solve using ode45. There appears to be something with wrong with the function I believe cause the graph that I get looks like this.

採用された回答

Alan Stevens
Alan Stevens 2020 年 12 月 19 日
The initial value for V is zero, so, because you divide by V in dcdt you get NaNs everywhere. You need to revisit how you calculate V.
  1 件のコメント
Najeem Afolabi
Najeem Afolabi 2020 年 12 月 19 日
Ahh I see. Thank you very much.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeOrdinary Differential Equations についてさらに検索

タグ

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by