0% found this document useful (0 votes)
17 views3 pages

Chemical Engineering Computing Kyambogo University Lecture 7

The document outlines a lecture on solving engineering problems using MATLAB, specifically focusing on the 'specvol' function to calculate specific volume for n-Pentane. It emphasizes the importance of correct syntax in MATLAB programming and provides a step-by-step procedure for creating and testing a script. An assignment is included, requiring students to calculate specific volumes for a mixture of hydrocarbons and determine optimal distillation conditions.

Uploaded by

4wpc24w2gh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views3 pages

Chemical Engineering Computing Kyambogo University Lecture 7

The document outlines a lecture on solving engineering problems using MATLAB, specifically focusing on the 'specvol' function to calculate specific volume for n-Pentane. It emphasizes the importance of correct syntax in MATLAB programming and provides a step-by-step procedure for creating and testing a script. An assignment is included, requiring students to calculate specific volumes for a mixture of hydrocarbons and determine optimal distillation conditions.

Uploaded by

4wpc24w2gh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

KYAMBOGO UNIVERSITY

FACULTY OF ENGINEERING
DEPARTMENT OF MINING, CHEMICAL & PETROLEUM ENGINEERING
BACHELOR OF SCIENCE IN CHEMICAL ENGINEERING
Course Code and Name: SCE 2202 COMPUTING FOR CHEMICAL ENGINEERING II
Course Level: YR II, SEM II (2023/2024)
Course Credit: 3 CU
Lecturer: Dr. Dan Egesa
Assisting Lecturer: Joshua Ocoun (Eng.)

SCE 2202 Lecture 07 (12th March 2024)


SOLVING ENGINEERING PROBLEMS IN MATLAB
‘Specvol’ function:
This function is used to describe a problem, and lay out the known parameters. With this function,
several equations can be fed in / described. Later on, by the use of ‘feval’ & ‘specvol’ the solution
to the problem is found, depending on the variable you want to find.

NOTE: when this symbol ‘%’ is used, in a Matlab, it indicates a statement describing the problem.
It can also indicate units of the described parameters. Whenever it’s used the words turn to green.

Matlab is a programming language, and therefore it’s very sensitive. Any mis-spelling of a
function name, will cause it not to work.
When you start a script, write;
 ‘function’.
Note that the ‘f’ should be in lower case. If it’s in the Upper case, Matlab will not understand that
you have written a script. If there is any error in the word, ‘function’ e.g ‘fuction’, ‘Function’,
‘fnction’… etc. Matlab will understand nothing of what you have written. It’s imperative that you
pay close attention to what you have written, even in other Matlab operators.

Example:
Find the Specific volume of n-Pentane at 600K and 16atm in a side draw stream of a distillation
column.
Soln:
We can use Equations of state to solve for this. In this case we can Redlich-Kwong equation of
State.

Dr. Dan Egesa (all assignments should to be submitted in time)


Joshua Ocoun (Eng.) 2023/2024Adc Yr.
So, in MatLab; Procedure:
1. Start Matlab and Create a new Script. Save it as ’specvol.m’ (an m-file)
2. Write the script; (Note that if typed correctly, the word ‘function’ will change to color
blue.)
function y=specvol (v)
% in K atm l/gmol
% parameters for n-Pentane
Tc = 425.2
Pc = 37.5
T = 500
P = 18
R = 0.08206
Tr = T/Tc^0.5
alpha = 1/Tr
a = 0.42748*R^2*Tc^2/Pc
b = 0.08664*R*Tc/Pc
y = (R*T/(v-b)) – (a/v*(v+b)) - P
end
3. If the script has been saved, properly as an m-file we can now go to the command window
and test the function. We can write;
>> feval (‘specvol’, 2) (Then press Enter)
Matlab will provide you an answer of the function y = specvol (v) at v=2. (Note this step
is used only to test the function, but later on we can use ‘fzero’ function to equate the
equation to zero so that we obtain the specific volume v.)
4. Matlab Tabulates and displays the results for the process as shown below;
Tc = 425.2
Pc = 37.5
T = 500
P = 18
R = 0.08206
Tr=24.24786
alpha=0.041241
a = 13.8782
b = 0.0806
y = ans (This value depends on the value of v you have fed in)
5. You can now issue the command; ‘fzero’

Dr. Dan Egesa (all assignments should to be submitted in time)


Joshua Ocoun (Eng.) 2023/2024Adc Yr.
>>v=fzero(‘specvol’,2)
v= 2.0377

Matlab provides all the calculations upto the final value of v and therefore it can take a
lot of pages for the case of printing out. To prevent this, always put a semi-colon ‘;’ at the
end of each line, to suppress the other calculations, and only provide the final solution.
In our case we did not do that.

Go back to editor and include the semi-colon. Then rewrite the command.
Summary:
 ‘specvol’ defines the problem whose unknown quantity you want to find.
 ‘feval’ evaluates the defined problem
 ‘fzero’ operates when the expression in the problem sums to zero
Assignment 10:
A kingfisher-2009 Petroleum assay contains, Propane, n-butane, n-pentane and benzene
as shown in the table below.
Compound %wt
Propane 0.1168
n-butane 0.4064
n-pentane 0.1485
Benzene 0.0175

Using either, RK-Soave or Peng Robinson, tabulate the specific volume of each of the
given components in the mixture stream for a temperature range of 200K to 500K and a
corresponding pressure range of 2bars to 10bars, using MATLAB
From your tabulation, suggest the optimum/best conditions (T and P) at which the mixture
can be separated by distillation.

Dr. Dan Egesa (all assignments should to be submitted in time)


Joshua Ocoun (Eng.) 2023/2024Adc Yr.

You might also like