Here are the main steps but I'm stuck, please show all the work and process. Thanks! Main steps: 1. Create a file containing the function (f.m) or use parameterized function 2. Use fzero functions 3. Use bubble point equation, specify vectors containing your composition (types of species in your system) and z values and then use GetKValues.m to develp an expression from which you can use fzero to solve for the bubble point. Here is the GetKValues function: function K_value_array = GetKValues(p,T, component_numbers, x_compositions, y_compositions) %GETKVALUES Obtain K values for the specified components % p : Pressure in Pa % T: Temperature in K % component_numbers: a row vector containing the database index numbers % of the components to be analyzed % x_compositions: The liquid-phase compositions of the components, in the % same order as the component_numbers vector % y_compositions: The vapor-phase compositions of the components, in the % same order as the component_numbers vector % all input vectors should be row vectors %First, get the K values from the database if they're not already loaded if ~exist('thermo_database','var') global thermo_database; ParseDatabase('./thermo_database.txt'); end %Now, determine if we need to enter interactive mode if nargin < 3 disp('Entering interactive mode'); interactive_on = true; elseif nargin == 4 disp('Assuming equimolar composition in vapor phase'); mole_fraction = 1/length(component_numbers); y_compositions = (mole_fraction * ones(length(component_numbers),1))'; interacive_on = false; elseif nargin == 3 disp('Assuming equimolar composition in vapor and liquid phase'); mole_fraction = 1/length(component_numbers); y_compositions = (mole_fraction * ones(length(component_numbers),1))'; x_compositions = y_compositions; interactive_on = false; else interactive_on = false; end if interactive_on == true p = input('Enter pressure in Pa: '); T = input('Enter temperature in K: '); number_of_components = input('How many components? '); component_numbers = zeros(number_of_components,1); x_compositions = component_numbers; y_compositions = component_numbers; index = 1; while index <= number_of_components string = sprintf('Enter component number %d ',index); identifier = input(string,'s'); if ~isempty(str2num(identifier)) search_database = find(cell2mat(thermo_database(:,1)) == str2num(identifier)); if isempty(search_database) disp('Component not found'); else component_numbers(index) = str2num(identifier); x_compositions(index) = input('What is the mole fraction of this component in the liquid phase? '); y_compositions(index) = input('What is the mole fraction of this component in the vapor phase? '); index = index + 1; end else found = false; for inner_index = 1:length(thermo_database(:,2)) if strcmp(identifier,char(thermo_database{inner_index,2})); found = true; identifier = thermo_database{inner_index,1}; end end if found == true component_numbers(index) = identifier; x_compositions(index) = input('What is the mole fraction of this component in the liquid phase? '); y_compositions(index) = input('What is the mole fraction of this component in the vapor phase? '); index = index + 1; else disp('Component not found'); end end end component_numbers = component_numbers'; x_compositions = x_compositions'; y_compositions = y_compositions'; end %Search through the database and find the selected components. Load these %into the variables that will be passed to the K value calculation %function. database_length = size(thermo_database,1); number_of_components = size(component_numbers,2); variable_increment = 1; for component_number_index = 1:number_of_components for database_index = 1:database_length if cell2mat(thermo_database(database_index,1)) == component_numbers(component_number_index) pc(variable_increment) = cell2mat(thermo_database(database_index, 3)); Tc(variable_increment) = cell2mat(thermo_database(database_index, 4)); w(variable_increment) = cell2mat(thermo_database(database_index, 5)); cp = cell2mat(thermo_database(database_index, 6)); cpig(variable_increment, :) = cp; DHf(variable_increment) = cell2mat(thermo_database(database_index, 7)); variable_increment = variable_increment + 1; end end end k = zeros(number_of_components,number_of_components); %We need to invert the arrays for use in the K_value calculation, except %for the cpig array, which is already in the correct orientation K_value_array = K_value(x_compositions',y_compositions',p,T,pc',Tc',w',k,cpig,DHf'); end
Here are the main steps but I'm stuck, please show all the work and process. Thanks! Main steps: 1. Create a file containing the function (f.m) or use parameterized function 2. Use fzero functions 3. Use bubble point equation, specify vectors containing your composition (types of species in your system) and z values and then use GetKValues.m to develp an expression from which you can use fzero to solve for the bubble point. Here is the GetKValues function: function K_value_array = GetKValues(p,T, component_numbers, x_compositions, y_compositions) %GETKVALUES Obtain K values for the specified components % p : Pressure in Pa % T: Temperature in K % component_numbers: a row vector containing the database index numbers % of the components to be analyzed % x_compositions: The liquid-phase compositions of the components, in the % same order as the component_numbers vector % y_compositions: The vapor-phase compositions of the components, in the % same order as the component_numbers vector % all input vectors should be row vectors %First, get the K values from the database if they're not already loaded if ~exist('thermo_database','var') global thermo_database; ParseDatabase('./thermo_database.txt'); end %Now, determine if we need to enter interactive mode if nargin < 3 disp('Entering interactive mode'); interactive_on = true; elseif nargin == 4 disp('Assuming equimolar composition in vapor phase'); mole_fraction = 1/length(component_numbers); y_compositions = (mole_fraction * ones(length(component_numbers),1))'; interacive_on = false; elseif nargin == 3 disp('Assuming equimolar composition in vapor and liquid phase'); mole_fraction = 1/length(component_numbers); y_compositions = (mole_fraction * ones(length(component_numbers),1))'; x_compositions = y_compositions; interactive_on = false; else interactive_on = false; end if interactive_on == true p = input('Enter pressure in Pa: '); T = input('Enter temperature in K: '); number_of_components = input('How many components? '); component_numbers = zeros(number_of_components,1); x_compositions = component_numbers; y_compositions = component_numbers; index = 1; while index <= number_of_components string = sprintf('Enter component number %d ',index); identifier = input(string,'s'); if ~isempty(str2num(identifier)) search_database = find(cell2mat(thermo_database(:,1)) == str2num(identifier)); if isempty(search_database) disp('Component not found'); else component_numbers(index) = str2num(identifier); x_compositions(index) = input('What is the mole fraction of this component in the liquid phase? '); y_compositions(index) = input('What is the mole fraction of this component in the vapor phase? '); index = index + 1; end else found = false; for inner_index = 1:length(thermo_database(:,2)) if strcmp(identifier,char(thermo_database{inner_index,2})); found = true; identifier = thermo_database{inner_index,1}; end end if found == true component_numbers(index) = identifier; x_compositions(index) = input('What is the mole fraction of this component in the liquid phase? '); y_compositions(index) = input('What is the mole fraction of this component in the vapor phase? '); index = index + 1; else disp('Component not found'); end end end component_numbers = component_numbers'; x_compositions = x_compositions'; y_compositions = y_compositions'; end %Search through the database and find the selected components. Load these %into the variables that will be passed to the K value calculation %function. database_length = size(thermo_database,1); number_of_components = size(component_numbers,2); variable_increment = 1; for component_number_index = 1:number_of_components for database_index = 1:database_length if cell2mat(thermo_database(database_index,1)) == component_numbers(component_number_index) pc(variable_increment) = cell2mat(thermo_database(database_index, 3)); Tc(variable_increment) = cell2mat(thermo_database(database_index, 4)); w(variable_increment) = cell2mat(thermo_database(database_index, 5)); cp = cell2mat(thermo_database(database_index, 6)); cpig(variable_increment, :) = cp; DHf(variable_increment) = cell2mat(thermo_database(database_index, 7)); variable_increment = variable_increment + 1; end end end k = zeros(number_of_components,number_of_components); %We need to invert the arrays for use in the K_value calculation, except %for the cpig array, which is already in the correct orientation K_value_array = K_value(x_compositions',y_compositions',p,T,pc',Tc',w',k,cpig,DHf'); end
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
Related questions
Question
Here are the main steps but I'm stuck, please show all the work and process. Thanks!
Main steps:
1. Create a file containing the function (f.m) or use parameterized function
2. Use fzero functions
3. Use bubble point equation, specify vectors containing your composition (types of species in your system) and z values and then use GetKValues.m to develp an expression from which you can use fzero to solve for the bubble point.
Here is the GetKValues function:
function K_value_array = GetKValues(p,T, component_numbers, x_compositions, y_compositions)
%GETKVALUES Obtain K values for the specified components
% p : Pressure in Pa
% T: Temperature in K
% component_numbers: a row vector containing the database index numbers
% of the components to be analyzed
% x_compositions: The liquid-phase compositions of the components, in the
% same order as the component_numbers vector
% y_compositions: The vapor-phase compositions of the components, in the
% same order as the component_numbers vector
% all input vectors should be row vectors
%First, get the K values from the database if they're not already loaded
if ~exist('thermo_database','var')
global thermo_database;
ParseDatabase('./thermo_database.txt');
end
%Now, determine if we need to enter interactive mode
if nargin < 3
disp('Entering interactive mode');
interactive_on = true;
elseif nargin == 4
disp('Assuming equimolar composition in vapor phase');
mole_fraction = 1/length(component_numbers);
y_compositions = (mole_fraction * ones(length(component_numbers),1))';
interacive_on = false;
elseif nargin == 3
disp('Assuming equimolar composition in vapor and liquid phase');
mole_fraction = 1/length(component_numbers);
y_compositions = (mole_fraction * ones(length(component_numbers),1))';
x_compositions = y_compositions;
interactive_on = false;
else
interactive_on = false;
end
if interactive_on == true
p = input('Enter pressure in Pa: ');
T = input('Enter temperature in K: ');
number_of_components = input('How many components? ');
component_numbers = zeros(number_of_components,1);
x_compositions = component_numbers;
y_compositions = component_numbers;
index = 1;
while index <= number_of_components
string = sprintf('Enter component number %d ',index);
identifier = input(string,'s');
if ~isempty(str2num(identifier))
search_database = find(cell2mat(thermo_database(:,1)) == str2num(identifier));
if isempty(search_database)
disp('Component not found');
else
component_numbers(index) = str2num(identifier);
x_compositions(index) = input('What is the mole fraction of this component in the liquid phase? ');
y_compositions(index) = input('What is the mole fraction of this component in the vapor phase? ');
index = index + 1;
end
else
found = false;
for inner_index = 1:length(thermo_database(:,2))
if strcmp(identifier,char(thermo_database{inner_index,2}));
found = true;
identifier = thermo_database{inner_index,1};
end
end
if found == true
component_numbers(index) = identifier;
x_compositions(index) = input('What is the mole fraction of this component in the liquid phase? ');
y_compositions(index) = input('What is the mole fraction of this component in the vapor phase? ');
index = index + 1;
else
disp('Component not found');
end
end
end
component_numbers = component_numbers';
x_compositions = x_compositions';
y_compositions = y_compositions';
end
%Search through the database and find the selected components. Load these
%into the variables that will be passed to the K value calculation
%function.
database_length = size(thermo_database,1);
number_of_components = size(component_numbers,2);
variable_increment = 1;
for component_number_index = 1:number_of_components
for database_index = 1:database_length
if cell2mat(thermo_database(database_index,1)) == component_numbers(component_number_index)
pc(variable_increment) = cell2mat(thermo_database(database_index, 3));
Tc(variable_increment) = cell2mat(thermo_database(database_index, 4));
w(variable_increment) = cell2mat(thermo_database(database_index, 5));
cp = cell2mat(thermo_database(database_index, 6));
cpig(variable_increment, :) = cp;
DHf(variable_increment) = cell2mat(thermo_database(database_index, 7));
variable_increment = variable_increment + 1;
end
end
end
k = zeros(number_of_components,number_of_components);
%We need to invert the arrays for use in the K_value calculation, except
%for the cpig array, which is already in the correct orientation
K_value_array = K_value(x_compositions',y_compositions',p,T,pc',Tc',w',k,cpig,DHf');
end
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 2 steps
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY