This statement is not inside any function. (It follows the END that terminates the definition of the function "mixing_tank".)
84 views (last 30 days)
Show older comments
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');
0 Comments
Answers (1)
Stephen23
on 26 Jan 2023
Edited: Stephen23
on 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
0 Comments
See Also
Categories
Find more on Ordinary Differential Equations 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!