This statement is not inside any function. (It follows the END that terminates the definition of the function "mixing_tank".)

85 ビュー (過去 30 日間)
Elijah
Elijah 2023 年 1 月 26 日
編集済み: Stephen23 2023 年 1 月 27 日
function dy = mixing_tank(t,y,FA0,CA0,FB0,CB0,V)
% Define the model equations
dy = zeros(2,1);
dy(1) = (FA0 * CA0 - (FA0 + FB0) * y(1)) / V;
dy(2) = (FB0 * CB0 - (FA0 + FB0) * y(2)) / V;
end
% Define the initial conditions and parameters
CA0 = 0.1; % mol/L
CB0 = 0.2; % mol/L
FA0 = 100; % L/min
FB0 = 50; % L/min
V = 100; % L
y0 = [CA0, CB0]; % t=0
% Define the time interval
tspan = [0, 30*60]; % 30 hours
% Solve the ODEs
[t,y] = ode45(@(t,y) mixing_tank(t, y, FA0, CA0, FB0, CB0, V), tspan, y0);
% Plot the results
figure
plot(t, y(:,1), '-', t, y(:,2), '--');
xlabel('Time (min)');
ylabel('Concentration (mol/L)');
legend('C_A', 'C_B');

回答 (1 件)

Stephen23
Stephen23 2023 年 1 月 26 日
編集済み: Stephen23 2023 年 1 月 27 日
The function definition needs to come after all of the other code. See:
% Define the initial conditions and parameters
CA0 = 0.1; % mol/L
CB0 = 0.2; % mol/L
FA0 = 100; % L/min
FB0 = 50; % L/min
V = 100; % L
y0 = [CA0, CB0]; % t=0
% Define the time interval
tspan = [0, 30*60]; % 30 hours
% Solve the ODEs
[t,y] = ode45(@(t,y) mixing_tank(t, y, FA0, CA0, FB0, CB0, V), tspan, y0);
% Plot the results
figure
plot(t, y(:,1), '-', t, y(:,2), '--');
xlabel('Time (min)');
ylabel('Concentration (mol/L)');
legend('C_A', 'C_B');
function dy = mixing_tank(t,y,FA0,CA0,FB0,CB0,V)
% Define the model equations
dy = zeros(2,1);
dy(1) = (FA0 * CA0 - (FA0 + FB0) * y(1)) / V;
dy(2) = (FB0 * CB0 - (FA0 + FB0) * y(2)) / V;
end

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by