plot a mccabe thiele diagram in matlab

To plot a McCabe-Thiele diagram in MATLAB, we need to first define the equilibrium curve and the operating line for a given distillation system. This can be done using the following steps:

  1. Define the feed composition and the reflux ratio:
main.m
xf = 0.5; % Feed composition (in mole fraction)
R = 2; % Reflux ratio
70 chars
3 lines
  1. Generate the equilibrium curve using the given vapor-liquid equilibrium data:
main.m
% Vapor-liquid equilibrium data
x = [0 0.2 0.4 0.5 0.6 0.8 1]; % Liquid composition (in mole fraction)
y = [0 0.3 0.5 0.6 0.7 0.9 1]; % Vapor composition (in mole fraction)

% Calculate the slope and intercept of the equilibrium curve
dx = diff(x)./diff(y);
b = x(1:end-1)-dx.*y(1:end-1);

% Define the range of liquid mole fractions for plotting
x_range = linspace(0,1,100);

% Evaluate the equilibrium curve for the given range of liquid mole fractions
y_eq = (x_range-b)./dx;

% Plot the equilibrium curve
plot(x_range,y_eq,'LineWidth',2);
hold on;
552 chars
18 lines
  1. Generate the operating line for the given reflux ratio:
main.m
% Calculate the minimum reflux ratio
q_min = (y(end)-xf)/(xf-x(1));

% Define the range of liquid mole fractions for plotting
x_range = linspace(0,1,100);

% Calculate the slope and intercept of the operating line
m = (R/q_min)-1;
c = R/(q_min*(1+R));

% Evaluate the operating line for the given range of liquid mole fractions
y_op = m*x_range + c;

% Plot the operating line
plot(x_range,y_op,'LineWidth',2);
411 chars
16 lines
  1. Generate the McCabe-Thiele diagram by finding the intersection points between the equilibrium curve and the operating line:
main.m
% Find the intersection points between the equilibrium curve and the operating line
x_intercept = (b-R./(1+R))./(1-dx.*(1./(1+R)));
y_intercept = m.*x_intercept + c;

% Plot the intersection points
plot(x_intercept,y_intercept,'ro','MarkerSize',8,'LineWidth',2);

% Add labels and legend
xlabel('Liquid mole fraction');
ylabel('Vapor mole fraction');
title('McCabe-Thiele Diagram');
legend('Equilibrium curve','Operating line','Intersection points');
451 chars
13 lines

The final MATLAB code for plotting a McCabe-Thiele diagram would look something like this:

main.m
% Define the feed composition and the reflux ratio
xf = 0.5; % Feed composition
R = 2; % Reflux ratio

% Vapor-liquid equilibrium data
x = [0 0.2 0.4 0.5 0.6 0.8 1]; % Liquid composition
y = [0 0.3 0.5 0.6 0.7 0.9 1]; % Vapor composition

% Calculate the slope and intercept of the equilibrium curve
dx = diff(x)./diff(y);
b = x(1:end-1)-dx.*y(1:end-1);

% Define the range of liquid mole fractions for plotting
x_range = linspace(0,1,100);

% Evaluate the equilibrium curve for the given range of liquid mole fractions
y_eq = (x_range-b)./dx;

% Plot the equilibrium curve
plot(x_range,y_eq,'LineWidth',2);
hold on;

% Calculate the minimum reflux ratio
q_min = (y(end)-xf)/(xf-x(1));

% Define the range of liquid mole fractions for plotting
x_range = linspace(0,1,100);

% Calculate the slope and intercept of the operating line
m = (R/q_min)-1;
c = R/(q_min*(1+R));

% Evaluate the operating line for the given range of liquid mole fractions
y_op = m*x_range + c;

% Plot the operating line
plot(x_range,y_op,'LineWidth',2);

% Find the intersection points between the equilibrium curve and the operating line
x_intercept = (b-R./(1+R))./(1-dx.*(1./(1+R)));
y_intercept = m.*x_intercept + c;

% Plot the intersection points
plot(x_intercept,y_intercept,'ro','MarkerSize',8,'LineWidth',2);

% Add labels and legend
xlabel('Liquid mole fraction');
ylabel('Vapor mole fraction');
title('McCabe-Thiele Diagram');
legend('Equilibrium curve','Operating line','Intersection points');
1481 chars
51 lines

gistlibby LogSnag