[Go to previous section: 1.2| Go
to next section: 1.4]
[ Go to CENG301 Homepage
| CENG301 Notes Table of Contents]
Part 1
The matlab directory of ~ceng301 stores current versions of the
flow sheet and auxiliary functions used in Ceng 301. A brief
description of each function used for mass balances in simple
idealized units is given in this section of the notes. The functions
that you will use the most are:
Program |
Called from |
Used for |
|
---|---|---|---|
1 |
Matlab |
Specifies compounds, creates a data file and creates variables for other window programs |
|
2 |
Unix xterm |
Displays names and formulae of compounds in the data
base |
|
3 |
Matlab |
Displays the flow rates of the compounds in the streams
in and out of a unit. |
|
4 |
Matlab |
The separator mass balance module. |
|
5 |
Matlab |
The splitter mass balance module. |
|
6 |
Matlab |
The mixer mass balance module. |
|
7 |
Matlab |
The reactor mass balance module |
|
8 |
Matlab |
Lists the set of chemical equations associated with a
stoichiometric array. |
When start301 is executed in a Matlab window, all previous data is
deleted from the workspace. Start301 should be executed at the
beginning of your session. If you do need to execute start301 in the
middle of a session, remember to save the workspace if necessary to
retain any necessary data. All the variables read by the Matlab
program are made global. This means that any function that involves
the same variables will use the same data if the program also
designates the variables as global. There are five variables always
set for a Matlab session by the use of the start301 programs.
Variable |
Stores |
---|---|
Names of the compounds |
|
form |
Chemical Formulae for all compounds |
mw |
Molecular weight of compounds |
nc |
Number of compounds |
nst |
Number of streams |
The start301 program was written in Matlab and must be executed in a Matlab window. Here is a session used to set the names of two compounds with no reactions.
>> start301 Copyright 1998 Rice University All rights reserved Welcome to CENG301's start301!! You have three choices, Please read them carefully Then click on the appropriate choice in the menu bar 1: Click (1) to start a new session 2: Click (2) to enter the name of a datafile from a previous session, in the current directory 3: Click (3) to use compound names not in the CENG 301 database WARNING...if you hit (3) no compound data will be available The following menu will appear in the upper left corner of the screen Click on the appropriate button to make your selection.<-- The choice selected here is (1) Now choose from the above menu The following menu will appear again in the upper left corner of the screen.
<-- For this example 'Mass Balances only' is chosen. There are two existing databases, depending upon the choice selected here, one is loaded. We will learn more about the data available in chapter 3.
Input the name of your new file: test The output file name is: test <-- The name of our data file is echoed. Input the number of compounds: 2 The number of compounds is: 2 <-- The number of compounds is also echoed Enter the name of compound # 1: CO2 <-- We can either give a formula or a name for each compound. Enter the name of compound # 2: sulfuric acid Enter the number of reactions: 0 <-- There are not many reactions among just two compounds. Here are your compounds' formulae and names: No. Formula Name ---------------------------------------- 1 CO2 carbon dioxide 2 H2SO4 sulfuric acid <-- Display of your compound and reactions. Here are your reactions: ---------------------------------------- No reactions given Enter the number of streams: 2 The variables for your compounds have now been created, you may continue, or come back later and reload the same data.
<-- We have the ability to create our own database, which we will see later, here select CENG 301's
If you are running start301 via a telnet session, the Menu bars won't pop up and the display will look slightly different. Click Telnet Version of Start301, to view the above example in a telnet session
The file called test is created by this execution, as well as all the variables to continue in other ceng301 modules. We can now run the modules, or exit Matlab and reload the same data later.
If we list the variables that have been set, we
find:
>> who Your variables are: cnms mw ns form nc nst We can see the values put into our arrays by:
>> cnms <-- The compound names cnms = carbon dioxide sulfuric acid >> form <-- Our compound's formula form = CO2 H2SO4 >> mw <-- Our compound's molecular weights mw = 44.0100 98.0730 >> nc <-- There are two compounds nc = 2 >> ns ns = <-- Our array to store flows for each compound in 0 0 each of two streams. At present there are no flows. 0 0 >> nst <-- There are two streams nst = 2
If you are dialing in to Rice from off campus or even using a telnet version of MATLAB, the menu bars will not pop up as in the previously shown example. If you are having trouble using a telnet session, and are using X-Win32 or similar program, make sure that the UNIX box that you are trying to telnet to is listed as a host in X-Util32 list of XHosts. The same example would be operated as follows in a telnet session:
>> start301 Copyright 1998 Rice University All rights reserved Welcome to CENG301's start301!! You have three choices, Please read them carefully Then click on the appropriate choice in the menu bar 1: Click (1) to start a new session 2: Click (2) to enter the name of a datafile from a previous session, in the current directory 3: Click (3) to use compound names not in the CENG 301 database WARNING...if you hit (3) no compound data will be available ----- Choose one of the following: ----- 1) (1) New Session 2) (2) Continue Existing Session 3) (3) Other Select a menu number: 1 Now choose from the above menu ----- Choose one of the following: ----- 1) Mass Balances only 2) Energy & Mass Balances Select a menu number: 1 ----- Select a Database ----- 1) CENG 301`s 2) Your Own Select a menu number: 1 Please wait while loading database... Input the name of your new file: test The output file name is: test Input the number of compounds: 2 The number of compounds is: 2 Enter the name of compound # 1: CO2 Enter the name of compound # 2: sulfuric acid Enter the number of reactions: 0 Here are your compounds' formulae and names: No. Formula Name ---------------------------------------- 1 CO2 carbon dioxide 2 H2SO4 sulfuric acid Here are your reactions: ---------------------------------------- No reactions given Enter the number of streams: 2 The variables for your compounds have now been created, you may continue, or come back later and reload the same data.
To continue a session that you have already entered the data for, such as the test file above, simply execute the start301 program in a Matlab window.
>> start301 1: Click (1) to start a new session 2: Click (2) to enter the name of a datafile from a previous session, in the current directory 3: Click (3) to use compound names not in the CENG 301 database WARNING...if you hit (3) no compound data will be available<-- Select (2) to continue an existing session Enter the name of the existing file: test Here are your compounds' formulae and names: No. Formula Name ---------------------------------------- 1 CO2 carbon dioxide 2 H2SO4 sulfuric acid <-- Echoes the contents of the data file Here are your reactions: ---------------------------------------- No reactions given The number of streams is: 2 <-- All variables are still created for use >> who Your variables are: cnms mw ns form nc nst >> cnms <-- Contents of each variable are identical to before cnms = carbon dioxide sulfuric acid
Remember that upon executing the start301 program, all previous data in the Matlab workspace will be erased. To store the data before using start301, use the save command. This stores all the variables in the current MATLAB workspace into the file which you specify. This is especially helpful if it is necessary to clear the workspace of all variables. It is useful for saving data which will be needed in future MATLAB sessions as well. The variables can be listed with the who command. For example, if the workspace currently contains:
>> who Your variables are: X oil candy >> save datafile <-- This is the name of the file storing the variables >> clear all <-- A clear all occurs at the beginning of start301 >> who Your variables are: <-- There are none.
To get the data back, just use the built-in command load .
>> load datafile >> who Your variables are: X oil candy <-- All data is saved, and returned
Before running any of the flow sheet programs, a matrix of flow
rates must be set up. The matrix used in the molar balance modules is
called ns. Its shape is S rows by C columns where S is the
number of streams in the problem and C is the number of components.
Thus the element ns(j,k) gives the flow rate of component
k in stream j. An abbreviated Table of molar flow rates
like the one shown in the last section of the notes is reproduced
below with the flows ns(j,k) marked.
Problem with 5 streams and 4 components
Comp. Number |
1 |
2 |
3 |
4 |
Total |
|
---|---|---|---|---|---|---|
Stream No. |
||||||
1 |
ns(1,1) |
ns(1,2) |
ns(1,3) |
ns(1,4) |
sum(ns(1,:)) |
|
2 |
ns(2,1) |
ns(2,2) |
ns(2,3) |
ns(2,4) |
sum(ns(2,:)) |
|
3 |
ns(3,1) |
ns(3,2) |
ns(3,3) |
ns(3,4) |
sum(ns(3,:)) |
|
4 |
ns(4,1) |
ns(4,2) |
ns(4,3) |
ns(4,4) |
sum(ns(4,:)) |
|
5 |
ns(5,1) |
ns(5,2) |
ns(5,3) |
ns(5,4) |
sum(ns(5,:)) |
The names and formulae used for compounds can be quite arbitrary.
Although a lot of effort has been made to standardize both, many
texts and computer applications do not follow the same standards. We
have adopted a procedure that is frequently used in chemical
engineering, but it may not be the same one you use. This is not
critical in the mass balance applications, since the names are not
used except as labels and to find the molecular weights for compounds
with known formulae. It will be crucial in accessing the data needed
for energy balances and phase behavior. You can see the names and
formulae we use by executing shownoh (for show name or heading). Here
is one session with it to find all formulae that start with "N" and
to list all such compound's names and formulae. Many of the compounds
in the data bank have only the formula and name stored for them. Most
have also a data file. We will limit our list to those compounds that
have data files with them. Later you will learn how to create your
own data files. If you do so, you can use this same program to list
the compounds in it. The current version of the program was written
in FORTRAN and is executed from a Unix xterm window.
station% shownoh If you want to show, reply: Compound names n Names of headings h Neither, STOP listing s n <-- To search for compound formula Give a letter to get names starting with that <-- There are more than letter or nothing to see all the names. 200 compounds in the list. N <-- We want formulae starting with N. If you want compound names reply: y, formulae, reply: <-- We want formulae. If you want to skip compounds that do not have a data file, reply: y y <-- This limits the number seen. If you want to show both name and formula, reply: y y <-- We want both. N2 nitrogen N2O nitrous oxide NH3 ammonia NH4 ammonium ion NO nitric oxide NO2 nitrogen dioxide Na2CO3 sodium carbonate Ne neon
You may sometimes want to set a list of names in
your variable cnms without using the data for each compound.
Another possibility is if the compounds you want to use are not in
either database. For example, i-pentane is not in either
database, and therefore would prompt you to re-enter the compound
name since it is not recognized. In this case you would choose (3)
from the menu bar "Use your own compound names":
<-- Select (3) Other You have chosen to not use any compound data If you wish to enter data for a compound, exit (control-C) then execute "create", then run a "new session", choice (1) <-- We will learn more about this option in chapter 3 Enter the number of compounds: 4 Compound names must be less than 25 characters long! Give the name of compound # 1: propane Compound names must be less than 25 characters long! Give the name of compound # 2: i-butane Compound names must be less than 25 characters long! Give the name of compound # 3: n-butane Compound names must be less than 25 characters long! Give the name of compound # 4: i-pentane Enter the number of streams: 0 >> who Your variables are: <-- Choice (3) only creates the variables 'cnms' and 'nc' cnms nc >> cnms cnms = propane i-butane n-butane i-pentane