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

87 Ansichten (letzte 30 Tage)
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');

Antworten (1)

Stephen23
Stephen23 am 26 Jan. 2023
Bearbeitet: Stephen23 am 27 Jan. 2023
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

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by