0% found this document useful (0 votes)
301 views

AA Introduction To MATLAB Applications in Chemical Engineering, PDF

This document provides an introduction to using MATLAB for applications in chemical engineering. It covers key MATLAB topics like matrix manipulation, plotting, solving equations, optimization, and more. The document is divided into multiple chapters focusing on areas like nonlinear algebraic equations, linear algebraic equations, ordinary differential equations, regression/curve fitting, and symbolic mathematics. It aims to equip chemical engineering students and professionals with the ability to use MATLAB as a tool to solve chemical engineering problems.

Uploaded by

Mohammed Ghanem
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)
301 views

AA Introduction To MATLAB Applications in Chemical Engineering, PDF

This document provides an introduction to using MATLAB for applications in chemical engineering. It covers key MATLAB topics like matrix manipulation, plotting, solving equations, optimization, and more. The document is divided into multiple chapters focusing on areas like nonlinear algebraic equations, linear algebraic equations, ordinary differential equations, regression/curve fitting, and symbolic mathematics. It aims to equip chemical engineering students and professionals with the ability to use MATLAB as a tool to solve chemical engineering problems.

Uploaded by

Mohammed Ghanem
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/ 277

Introduction to

MATLAB Applications in
Chemical Engineering

Professor Kamil M. Wagialla


‫بروفيسور اكمل محمد احلسن وقيع هللا‬

University of Khartoum
Faculty of Engineering
Chemical Engineering Department

First Edition

August, 2017

i
To my parents, who gave their children love, encouragement
and the passionate desire to seek knowledge.

ii
No part of this publication may be reproduced or transmitted in any form or by any
means, electronic or mechanical, including photocopying, recording, or any
information storage and retrieval system, without permission in writing from the
author.

iii
Table of Contents

Preface 1
Chapter 1 Introduction to MATLAB 3
1.1 MATLAB Structure 3
1.1.1 Important Basic Functions 3
1.1.2 Script M-files and function M-files 4
1.1.3 Using Command window only 4
1.1.4 Using Command window and function M-file 4
1.1.5 Using a script file only 4
1.1.6 Using script M-files and function M-files 4
1.2 Reading and Writing Data from and to Files 5
1.3 Sources of Errors 5
1.3.1 Human Errors 5
1.3.2 Truncation Errors 6
1.3.3 Round-off Errors 6
1.3.4 Accumulative Errors 6
1.4 Manipulating MATLAB Matrices 6
1.5 Matrix Multiplication Operations 9
1.5.1 Matrix Algebra Calculations 9
1.5.2 Element by element multiplication (dot multiplication) 9
1.6 Functions with multiple inputs and outputs 9
1.7 Formated Output 10
1.7.1 The fprint function: 10
1.8 Logical Statements 12
1.8.1 if statement 12
1.8.2 Nested if commands 12
1.8.3 for LOOPS 12
1.8.4 while LOOPS 13
1.8.5 Using while loop to check for error in user input 13
1.8.6 switch-case logical procedure: 14
1.9 Plotting 14
1.9.1 Line, Colour & Mark Style 15
1.9.2 Laying plots one on top of another 18
1.9.3 Sub Plots 20
1.9.4 The fplot function 21

iv
1.10 Three-Dimensional Plotting 22
1.11 Surface Plots 23
Exercises 26

Chapter 2 Non-Linear Algebraic Equations 29


2.1 Single Non-linear Algebraic Equations 29
2.1.1 Newton’s Method 29
2.1.2 The Secant Method 32
2.1.3 MATLAB roots Function 34
2.1.4 MATLAB built_in function (using symbolic mathematics) 35
2.2 Multiple Nonlinear Algebraic Equations 36
2.3 The Phase Rule 54
2.4 Single-Component Systems 55
2.5 Multi-Component, Multiphase Systems 56
2.6 The Equilibrium Coefficient (K) and Raoult’s Law 56
2.7 Determination of Temperature and Concentrations in Two
phase Systems 57
2.8 Dew Point and Bubble Point Temperature 59
2.8.1 Determination of the Dew Point Temperature 60
2.8.2 Determination of the Bubble Point Temperature 60
2.9 Equilibrium Flash Vaporization 62
2.10 Isothermal Flash Calculation 63
2.11 Ammonia Plant: Case Study 1 ((Material and Energy Balances) 74
2.12 Ammonia Plant: Case Study 2 (Sensitivity Analysis) 78
2.13 Synthesis Gas Plant: Case Study 3 80
Exercises 88

Chapter 3 Linear Algebraic Equations 97


3.1 Cramer’s Rule 97
3.1.1 Cramer’s Rule using MATLAB Command Window 97
3.1.2 MATLAB using UofK Application (University of
Khartoum Application) 97
3.2 Direct Methods for Solving Linear Systems 99
3.2.1 Gauss Elimination Methods 100
3.2.2 Gauss elimination method using partial pivoting 102
3.2.3 Gauss Elimination Method Using Total Pivoting 102
3.3 Built_in MATLAB Function 103
3.4 Iterative Methods in Matrix Algebra 104
3.4.1 Jacobi Iterative Method 104
3.4.2 The Jacobi Iterative Method in Matrix Form 105
Exercises 110

v
Chapter 4 Initial Value Ordinary Differential Equations 113
4.1 Classification of Differential Equations 113
4.1.1 Definitions 113
4.2 Initial-Value ODE Problems: 113
4.3 Boundary-Value ODE Problems: 114
4.4 Numerical Methods for Solving IVP 114
4.4.1 Fourth-Order Runge-Kutta Method 113
4.5 MATLAB User_Defined Function 115
4.6 MATLAB ODE Solvers 116
4.7 ODE45 MATLAB Function 118
4.8 Higher-Order Differential Equations 126
Exercises 128

Chapter 5 Boundary-Value Ordinary Differential Equations 135


5.1 Types of Boundary value Problems 135
5.2 Boundary-value ODEs Applications in Chemical Engineering 135
5.2.1 Porous Catalyst Pellet 136
5.2.2 The Plug Flow Axial Dispersion Model 136
5.2.2.1 Formulation of the Axial Dispersion Model 137
5.3 Solution Methods 139
5.3.1 The Shooting Methods 139
Exercises 143

Chapter 6 Regression and Correlation of Data (Curve Fitting) 145


6.1 Prelude 135
6.2 Linear Regression 135
6.3 Polyfit Function 136
6.4 Polynomial (Non_linear Regression) 137
6.5 The Polyval Function 138
Exercises 143

Chapter 7 Optimization 155


7.1 Examples of Optimization Applications 155
7.2 Single-variable bounded nonlinear function 155
7.3 Multidimensional Unconstrained Nonlinear Minimization 157
7.4 Linear Programming 158
7.4.1 MATLAB Function linprog 158
7.5 Heat Integration 163
7.5.1 An Introductory Overview 164
7.5.2 HEN Synthesis Problem Statement 164
7.5.2.1 Temperature Interval Diagram (TID) 165

vi
7.5.2.2 Table of Exchangeable Heat Loads (TEHL) 165
7.6 Targeting for Minimum Heating and Cooling Utilities 166
7.7 Integer and Mixed Integer Programming 169
7.8 Stream Matching and HEN Synthesis 171
7.8.1 Stream Matching Using MATLAB Code 175
7.8.2 Stream Matching Using LINGO Software 177
7.9 The Assignment Problem 180
183
7.10 The Transportation Problem 186
7.10.1 The Transportation formulation using LINGO software 187
Exercises
195
Chapter 8 Symbolic Mathematics in MATLAB 195
8.1 Symbolic Variables 195
8.2 Declaration of symbolic variables 195
8.3 Symbolic Commands 197
8.4 Symbolic Equation Solving 198
8.4.1 Symbolic Differentiation 199
8.4.2 Symbolic Integration 199
8.4.2.1 Indefinite integrals 200
8.4.2.2 Definite integrals 200
8.5 Symbolic Ordinary Differential Equations 201
8.6 Plotting symbolic expressions 203
Exercises
205
Chapter 9 SIMULINK 205
9.1 Introduction 205
9.2 Introductory Example 205
9.3 Problem-Solving Procedure 206
9.4 Ordinary Differential Equations in Simulink 213
9.5 Modelling Common Problems of Control Systems in Simulink 213
9.5.1 Step response of a control system from the transfer function 216
Exercises
219
Chapter 10 Process Dynamics and Control 219
10.1 Single-Loop Control Systems 220
10.1.1 Proportional Control 221
10.1.2 Proportional-Integral Control 221
10.1.3 Proportional-Derivative Control 221
10.1.4 Proportional-Integral-Derivative Control 221
10.2 Transfer function representation 222
10.2.1 Transform Function Poles, and Zeroes 222

vii
10.3 State space representation 224
10.4 Object-Oriented Transfer Functions 225
10.5 Time-response Simulation 225
10.5.1 Step- and Impulse-Response Simulations 227
10.5.2 Sinusoidal Response 229
10.6 Feedback Simulation Functions 231
10.6.1 Steps to develop a closed-loop transfer function 233
10.7 Control System Stability 234
10.7.1 Root-locus Analysis 236
10.8 Root-Locus Functions 237
10.9 SISO System Design Graphics Interface 240
10.10 Frequency-Response Functions 240
10.10.1 Nyquist and Nichols Plots 243
10.10.2 Bode frequency response of dynamic systems 243
10.10.3 Bode Plots 246
Exercises
247
Appendix A Degree of Freedom Analysis 247
A.1 Checking Independence of Algebraic Equations: 247
A.2 Checking by Inspection 247
A.3 Checking Using MATLAB Function rref 248
A.4 Consistency of Equations and Existence of Solutions 248
A.5 Defintions: 248
A.5.1 Order of a matrix 248
A.5.2 What is a vector 248
A.5.3 Determinant of a matrix 249
A.5.4 Rank 249
A.5.5 Existence of Solutions 249
A.5.6 Degree of freedom 254
A.5.7 Solution to problem 2.6 in chapter two (𝑆𝑂3 plant) 259
Appendix B Chemo-Physical Property Data 259
B.1 Heat of Formation and Other Thermodynamic Data 263
B.2 Heat Capacity Data
265
References

viii
ix
Preface
The main objective of this text is to teach the fundamentals of MATLAB as a
computational and software tool to chemical engineering students. MATLAB has now
gained wide acceptance in academia and industry as an indispensable tool in academic
and research fields. Modern engineering practice is becoming increasingly more
quantitative and this has prompted engineers to become computationally literate and
appreciate the possibilities that exist for applying computer capabilities to solving their
engineering tasks.
MATLAB (matrix laboratory) is a multi-paradigm numerical computing environment
and fourth-generation programming language. A proprietary programming language
developed by MathWorks, MATLAB allows matrix manipulations, plotting of
functions and data, implementation of algorithms, creation of user interfaces, and
interfacing with programs written in other languages, including C, C++, C#, Java,
Fortran and Python.
Although MATLAB is intended primarily for numerical computing, an optional
toolbox uses the MuPAD symbolic engine, allowing access to symbolic computing
abilities. An additional package, simulink, adds graphical multi-domain simulation
and model-based design for dynamic and control systems. Simulink is an icon-driven
interface that runs within MATLAB.
The solved examples rely heavily on the use of MATLAB, but when a different
software is believed to be particularly suited for certain types of problems, then this
circumstance is pointed out. The elegance of MATLAB is that it does not have a
sharp learning curve. Students can quickly grasp the fundamentals and experiment on
their own to explore the available possibilities.
At the start of introducing the MATLAB fundamentals to students, the instructor will
notice that some of the students would need some time and effort to grasp and
familiarize themselves with the special nature of this programming language in
comparison to traditional programming languages such as FORTRAN, C++, and
BASIC for example. However, overtime, most students will appreciate the concise
nature and ease with which MATLAB can handle relatively complex mathematical
problems. The main advantage of MATLAB in this context is that MATLAB is a
matrix-based application. In order to invert a matrix (A), for example, the MATLAB
user needs only to invoke the MATLAB function inv (A), whereas in other
programming languages a substantial computer code needs to be written. The other
bonus in using MATLAB is the self-contained environment of MATLAB. Any of the
MATLAB function plot variants can be invoked from within the MATLAB
environment. This feature is lacking in several programming languages where separate
graphing software is often needed to execute graphs.
The teaching material in this document is arranged around the different numerical
computational techniques and not chemical engineering topics. Thus the chapter
entitled “non linear algebra’ for example starts with introducing the numerical

1
methods for solving non linear algebraic problems. MATLAB programs are next
constructed to solve such problems. Thereupon several chemical engineering solved
examples which can be handled using MATLAB functions specially designed for this
particular numerical technique are presented. This presentation approach is in
contrast to the alternative book arrangement on the basis of chemical engineering
topics such as thermodynamics, fluid mechanics, heat transfer, mass transfer, and
reactor engineering.
The book is intended to be introductory in nature in presenting the basic MATLAB
tools for problem solving. However it is hoped that the scope of material presented in
this book will cover some of the fundamental applications of chemical engineering
and it is felt that the reader will find the many solved examples of assistance in
launching MATLAB for solving his own particular academic and research problems.
The book is intended as a one-term course for graduate level or a two-term program
for upper-class undergraduate level. It requires a working knowledge of calculus and
linear algebra. It is meant to be used in a setting where students are actively using
MATLAB. In addition to its use as a textbook, it is hoped that the book will also
serve as a guide for individual study, industrial short courses, and other continuing
education programs.
Writing a book is a lengthy endeavour, and one for which I have enjoyed much
assistance from many quarters. I wish to acknowledge the helpful suggestions of
several colleagues in developing this book. This preface cannot be concluded without
extending my gratitude for the help and comments I received from the chemical
engineering students (under graduate as well as post graduate) in the department of
chemical engineering department at the University of Khartoum (Sudan). In particular
I would like to extend my sincere appreciation to engineers Reem Abdul Moniem
Farag, Isra Awad Omer Alsamani, Amina Hussein Ahmed, and Heba Abdalla Karam
Alla for their assisatance and proofreading of the manuscript. The teaching assistants
and graduate students were a great source of feedback and help.

Kamil Mohamed-Elhassan Wagialla,


Department of Chemical Engineering,
University of Khartoum,
August, 2017

2
CHAPTER

1
1.1 MATLAB Structure
Introduction to MATLAB

The MATLAB environment includes the following windows (the first four are open
in the default view):
•Command window
•Command history window
•Workspace window
•Current folder window
•Document window
•Graphics window
•Edit window
1.1.1 Important Basic Functions
General functions
cd Change subdirectory
demo (intro) Launch the demo (introduction)
dir List of files in current directory (or only M-files)
help, helpwin Help! Help window
load Load workspace
lookfor Keyword search
print Print graph; can use pull down window
quit Quit!
Save Save workspace
who, whos List of variables in workspace
Calculation functions
conv Convolution function to multiply polynomials
size, length Size of an array, length of a vector
Plotting functions
axis Override axis default of plot
grid Add grid to plot
hold Hold a Figure to add more plots (curves)
legend Add legend to plot
plot Make plots

3
text (gtext) Add text (graphical control) to plot
title Add title to plot
xlabel, ylabel Add axis labels to plot
1.1.2 Script M-files and function M-files
Commands can be entered in command window, or stored in a script M-file or a
function M-file. Using the command window for calculations is an easy and powerful
tool. However once you close the MATLAB program, all your calculations are lost.
To avoid loss of programs, the user can create and save code in the so called M-files.
Once saved, these files can be reused by the programmer.
A script M-file can call a function M-file to perform certain calculations and then
return command to the script file.
To illustrate the use of command window, script, and function files let us consider the
trivial problem of the calculation of the area of a circle of radius 10 cm.
1.1.3 Using Command window only:
>> x = 10;
>> area = pi*x^2
1.1.4 Using Command window and function M-file
In the edit window create a function as follows:
function f = circle(x)
f = pi*x^2
end
Notation:
f is the output
circle is the function name
x is input argument (a scalar or vector).
The MATLAB input argument (x) is used to pass data between the function and
command window or a script file or another function.
The user must save the function in a folder with an identical name to the function
name. Therefore save the function under the name circle.m.
Then in the command window type:
>> x = 10;
>> circle(x)
1.1.5 Using a script file only:
Go to the edit window, create and save a script file with the name test1.m
x = 10;
area = pi*x^2;
In the command window type:
>> test1
1.1.6 Using script file and function M-files
With the function circle.m already in the current folder, go to the edit window and
create a new script file:

4
x = 10;
circle(x)
Save file under the name run_circle.m. In the command window enter this script file
name (without the extension .m):
>> run_circle
1.2 Reading and Writing Data from and to Files
The following are some of the data types supported by MATLAB:
.mat MATLAB workspace
.dat ASCII data
.txt ASCII data
.xls, xlxx Excel spreadsheet
.jpeg or jpg joint photographic expert group
If you select a data file from the current folder and double-click on the file name, the
Import Wizard launches. The Import Wizard can be used for simple ASCII files and
for Excel spreadsheet files. To read an Excel (.xls), we’d use xlsread:
xlsread(‘filename.xls’)
For writing an Excel file: xlswrite (‘filename.xls’, M)
Where M is the array you want to store in the Excel spreadsheet.
1.3 Sources of Errors
In analyzing the accuracy of numerical results, one should be aware of the possible
sources of errors that can crop up and the extent to which these errors can affect the
results of the computations. There are four main types of errors: human (user) errors,
truncation errors, round-off errors, and accumulative errors.
1.3.1 Human Errors
(a) Idealistic assumptions in formulating the mathematical equations to simplify a
model is a major source of error that can negatively impact the results.
(b) If a MATLAB file is located in a folder other than the current MATLAB folder
or in a folder not in the MATLAB search path, the user is likely to get the following
message from MATLAB upon trying to execute such a file:
Undefined file or variable name
For instance if file test.m is located in the path C:\Users\New\test.m and the
MATLAB program is located in the folder C:\Users\New\Documents\MATLAB,
then MATLAB will not be able to access the file test.m and will give the above
mentioned error message.
To resolve this problem the user can do one of two things:
Either save the file test.m in the MATLAB folder or add the folder in which the file
test.m is currently located to the MATLAB search path.
To add folder C:\Users\New to the MATLAB search path:
Right click on file name (test.m) in the menu bar and then select the option:
Add C:\Users\New to search path

5
(c) The function log in all computer languages means the natural logarithm. Not
knowing the distinction is a common source of error. If you want logarithm to the
base 10, you’ll need to use the log10 function.
(d) Syntax error messages from MATLAB are due to linguistic MATLAB errors.
Typical errors include mismatching of brackets or missing multiplication or other
operators e.g. :
Error: File: run_test_2.m Line: 1 Column: 39
Unbalanced or unexpected parenthesis or bracket.
(e) Invoking a script file with the file extension (.m) will create an error message.
(f) MATLAB is case sensitive and it therefore considers the variables (A) and (a) as
two distinct variables.
1.3.2 Truncation Errors
Truncation errors in numerical analysis usually occur because many numerical
methods are iterative in nature, with the approximations becoming more accurate as
we take more iterations. A typical example is the Taylor’s series expansion for a
function f(x) expanded about 𝑥𝑛 :
(𝑥−𝑥 )2
𝑓(𝑥) = 𝑓(𝑥𝑛 ) + (𝑥 − 𝑥𝑛 )𝑓 ′ (𝑥𝑛 ) + 𝑛
𝑓 " (𝑥𝑛 ) + …
2
Or Maclaurin’s series expansion to represent sine 𝑥, so that:
𝑥3 𝑥5 𝑥7
𝑠𝑖𝑛𝑒 𝑥 = 𝑥 − + − +…
3! 5! 7!
π
If we want a number to approximate sin( ), we must terminate the expression in
2
order to obtain:
π π π
π ( )3 ( )5 ( )7
2 2 2
𝑠𝑖𝑛𝑒 𝑥 = 2 − 3 ! + 5 ! − 7 ! + E
Where E is the truncation error introduced in the calculation. As a practical matter,
we must stop the iteration after a finite number of steps, thus introducing a truncation
error.
1.3.3 Round-off Errors
These types of errors are associated with the limited number of digits in the
computer. For instance, by rounding off 1.3246367 to five decimal places we obtain
1.32463.
1.3.4 Accumulative Errors
A computer program that contains repeated computations which include truncation
and round-off errors will result in the accumulation of such errors which may pile up
and lead to erroneous results.
1.4 Manipulating MATLAB Matrices
Matrices are defined as follows:
>>A = [3.5]; The semicolon suppresses output to screen
>>B = [1.5,3.1]; Or B=[1.5 3.1];

6
B is a row vector
>>C = [1;2];
C is a column vector
>>D = [-1, 0, 0; 1, 1, 1; 0, 0, 2];
D is 3x3 matrix
>>S = [3.0, B]
MATLAB returns: S = 3.0 1.5 3.1
>>T = [1, 2, 3; S]
MATLAB returns: T = 1 2 3
3 1.5 3.1
>>H = 1:6
MATLAB returns: H = 1 2 3 4 5 6
>>Time = 0.0:0.5:2.0
MATLAB returns: 0 0.5 1.0 1.5 2.0
Let
>>M = [1 2 3 4 5;
2 3 4 5 6;
3 4 5 6 7]
We can extract column 1 from matrix M with the command >>X = M(:,1) which
returns X = 1
2
3
We read the syntax (:,1) as “all the rows in column 1”. Similarly, we can extract row 2
from matrix M with the command >>y = M(2,:) which returns Y = 2 3 4 5 6.
We read the syntax (2,:) as “all the columns in row 2”
Example 1.1
>>A = [12 17 3 6];
>>B = 5 8 3
1 2 3
2 4 6
>>C = 22
17
4
1. Assign to variable x1 the value in the second column of matrix a.
>>x1 = A(1,2)
x1 = 17
2. Assign to x2 the third column of matrix B
>>x2 = B(:,3)
x2 = 3 3 6
3. Assign to variable x3 the third row in matrix B

7
>>x3 = B(3,:)
x3 = 2 4 6
4. Assign to x4 the values in matrix B along the diagonal
>>x4 = [B(1,1) B(2,2) B(3,3)]
x4 = 5 2 6
Or
>>x4 = diag(B)
5. Assign to variable x5 the first three values in matrix A as the first row and all the
values in matrix B as the second through the fourth row
>>x5 = [ A(1,1) A(1,2) A(1,3) ; B]
x5 = 12 17 3
5 8 3
1 2 3
2 4 6
6. Assign to variable x6 the values in matrix C as the first column, the values in matrix
B as columns 2,3, and 4, and the values in matrix A as the last row.
>>x6 = [C B ; A]
x6 = 22 5 8 3
17 1 2 3
4 2 4 6
12 17 3 6
7. Assign to variable x7 the value of element 8 in matrix B, using the single-index-
number identification scheme
>>x7 = B(8)
x7 = 3
8. Convert matrix b to a column vector named x8
>>x8 = [B(:,1); B(:,2); B(:,3)]
x8 =
5
1
2
8
2
4
3
3
6

1.5 Matrix Multiplication Operations

8
1.5.1 Matrix Algebra Calculations
When you are performing matrix algebra calculations, if:
>>A = [ 1 2
3 4];
>>B = [ 2 3
4 5];
then >>A*B = (1*2 + 2*4) (1*3 + 2*5)
(3*2 + 4*4) (3*3 +4*5)
= 10 13
22 29
1.5.2 Element by element multiplication (dot multiplication)
>>A.*B = 1*2 2*3
3*4 4*5
>>A.*B
ans = 2 6
12 20
Similar syntax applys for exponentiation (.^) and division (./) of individual elements:
a.^b, A./B
When you divide a scalar by an array you still need to use the (./) syntax, because the
(/) operator means taking the matrix inverse to MATLAB.
As a general rule, unless you specifically are doing problems involving linear algebra
(matrix mathematics), you should use the dot operators.
Example 1.2
>>A = [1 2; 3 4];
>>5/A
Error using /
Matrix dimensions must agree.
>>5./A
ans =
5.0000 2.5000
1.6667 1.2500
1.6 Functions with multiple inputs and outputs
function output = g(x,y)
output = x.*y;
end
>>x = 1:5; % x is a row vector: 1 2 3 4 5
>>y = 5:9; % y is a row vector: 5 6 7 8 9
Run the program by invoking file name (g) in the command window without extension
(.m):
>>g(x,y)
9
ans = 5 12 21 32 45
More than one output variable:
function [dist,vel,accel] = motion(t)
dist= t.^3/12;
vel = t.^2/4;
accel = 0.5.*t;
From command window:
>>[dist,vel,accel] = motion(10)
Returns:
dist = 83.33
vel = 25
accel = 5
Example 1.3
Using a vector of time values from 0 to 30:
>>time = 0:10:30;
>>[dist,vel,accel] = motion(time)
Returns:
Dist = 83.33 666.67 2250.0
vel = 25 100.00 225.00
accel = 5 100 15.00
1.7 Formated Output
1.7.1 The fprint function:
The syntax is: fprintf(format_string, variable, …).
format_string is written as: %f. The sign % is called a place holder.
fprintf writes formatted data to text file. fprintf(FID, FORMAT, A, ...) applies the
FORMAT to all elements of array A and any additional array arguments in column
order, and writes the data to a text file. FID is an integer file identifier. Obtain FID
from FOPEN, or set it to 1 (for standard output, the screen) or 2 (standard error).
fprintf uses the encoding scheme specified in the call to FOPEN.
fprintf(FORMAT, A, ...) formats data and displays the results on the screen.
FORMAT is a string that describes the format of the output fields, and can include
combinations of the following:
Escape characters, including:
\b Backspace '' Single quotation mark
\f Form feed %% Percent character
\n New line \\ Backslash
\r Carriage return \xN Hexadecimal number N
\t Horizontal tab \N Octal number N
For most cases, \n is sufficient for a single line break. However, if you are creating a
file for use with Microsoft Notepad, specify a combination of \r\n to move to a new
line.

10
Example 1.4
Create a text file called exp.txt containing a short table of the exponential function.
>>x = 0:.1:1;
>>y = [x; exp(x)];
>>fid = fopen('exp.txt','w');
>>fprintf(fid,'%6.2f %12.8f\n',y);
>>fclose(fid);
Examine the contents of exp.txt:
>>exp.txt
MATLAB returns:
0.00 1.00000000
0.10 1.10517092
...
1.00 2.71828183
sprintf writes formatted data to string.
STR = sprintf (FORMAT, A, ...) applies the FORMAT to all elements of array A and
any additional array arguments in column order, and returns the results to string STR.
[STR, ERRMSG] = sprint (FORMAT, A, ...) returns an error message when the
operation is unsuccessful. Otherwise, ERRMSG is empty. sprintf is the same as
fprintf except that it returns the data in a MATLAB string rather than writing to a file.
Example 1.5
>>cows=5;
>>fprintf(‘There are %f students in the room’,students)
Returns:
There are 5.000000 students in the room.
The following are standard MATLAB formatting noations:
%f Fixed point format
%e Exponential format
%g Whichever is shorter (%f or %e)
%s String of characters
%d Integer
For example:
>>fprintf(‘There are %d students in the room’,students)
Returns:
There are 5 students in the room
1.8 Logical Statements
1.8.1 if statement
The if logical operator conditionally executes statements. The “if statement” structure
is as follows: if ( condition) expression
if condition is true, then expression is executed.
1.8.2 Nested if commands
11
The general form of the if nested structure is as follows:
if expression
statements
elseif expression
statements
else
statements
end
The statements are executed if the real part of the expression has all non-zero
elements. The ELSE and ELSEIF parts are optional. Zero or more ELSEIF parts can
be used as well as nested ifs. The expression is usually of the form expr rop expr (i.e.
expression relative operator expression) where rop is ==, <, >, <=, >=, or ~=.
Example 1.6
if I == J
A(I,J) = 2;
elseif abs(I-J) == 1
A(I,J) = -1;
else
A(I,J) = 0;
end
1.8.3 for LOOPS
for index = [matrix]
commands to be executed
end
Example 1.7
for k = [1,3,7]
k
end
k = 1
k = 3
k = 7
Example 1.8
for k = 1:5
a(k) = k^2
end
a = 1
a = 1 4
a = 1 4 9
a = 1 4 9 16
a = 1 4 9 16 25

12
Example 1.9
Student Scores = 56,87,45,90,87,88,95,98,55
How many students scored 90 or more ?
Solution:
scores = [56,87,45,90,87,88,95,98,55];
count = 0;
for k = 1:length(scores)
% The word length refers to the number ...
of elements in the array.
if scores(k) >= 90
count = count + 1;
end
end
disp (count)
1.8.4 while LOOPS
Solving the previous example:
scores = [56,87,45,90,87,88,95,98,55];
count = 0;
k = 0;
while k <= length(scores)
k = k + 1;
if scores(k) >= 90
count = count + 1;
end
end
disp (count)
1.8.5 Using while loop to check for error in user input
Example 1.10
x = input(‘Enter a positive value of x ’)
while (x <= 0)
disp(‘log(x) is not defined for negative numbers’)
x = input(‘Enter a positive value of x ’)
end
y = log10(x);
fprintf(‘The log base 10 of %4.2f is %5.2f \n’,x,y)
1.8.6 switch-case logical procedure:
switch variable
case option 1
commands to be executed if variable equal to option 1
case option 2

13
commands to be executed if variable equal to option 2
case option 3
commands to be executed if variable equal to option 3
otherwise
commands to be executed if variable in NOT equal to any of the options
end
Example 1.11
Write the following program as a script file:
city = input(‘Enter the name of a city in single ...
quotes :’)
switch city
case ‘Rufaa’
disp(‘SG 45’)
case ‘Madani’
disp(‘SG 150’)
case ‘London’
disp(‘Stay home and study’)
otherwise
disp(‘ Not on file’)
end
1.9 Plotting
Basic Plotting Functions:
plot(x,y) creates an x-y plot
title( ‘my graph’) adds a title to a plot
xlabel(‘ temperature’) adds label to x-axix
ylabel(‘ volume’) adds label to y-axix
grid adds a grid to the graph
grid on, grid off
pause pauses execution of the program
Figure(2) determines Figure(2) will be used for the current plot
hold freezes the current plot, so that an additional plot can be overlaid
Example 1.12
Plot the function y = 𝑒 𝑥 + 10 between x = -2 and x = +2 with increments of 0.1
Solution:
>> x = -2:0.1:2;

14
Figure 1.1: Plot of the function y = 𝑒 𝑥 + 10
>> y = exp(x) + 10;
>> plot (x,y)
1.9.1 Line, Colour & Mark Style:
>> help plot
The above command returns a list of available options.
To put the markers used for points in plot, the user can use any of the following:
Symbol Effect
• Point
O Circle
X Cross
* Star
Example 1.13
x = [1:10];
y = [40,45,60,71,75,82,87,90,95,105];
>>plot(x,y,’:ok’) or
>>plot(x,y’:ok’,x,y*2,’- -xr’,x,y/2,’-b’)

Figure 1.2: Plot for Example 1.13


Example 1.14
>> x = 0:pi/100:2*pi;

15
>> y1 = cos(x)*2;
>> y2 = cos(x)*3;
>> y3 = cos(x)*4;
>> y4 = cos(x)*5;
>> plot(x,y1,x,y2,x,y3,x,y4)
5

-1

-2

-3

-4

-5
0 1 2 3 4 5 6 7

Figure 1.3: Plot for Example 1.14

Example 1.15 (Van der Waals Equation of State)


The ideal gas law is: PV = nRT and the van der Waals modification of the ideal gas
law is:
𝑛2 𝑎
(𝑃 + )(V – nb) = nRT
𝑉2
Plot reduced pressure values of 2, 4, 6, 10, 15, and 20 versus compressibility factor
for ammonia gas [3,4].
a = (27/64)*R^2*Tcrit^2/Pcrit
b = R*Tcrit/(8*Pcrit)
Pcrit = 111.3 atm, Tcrit = 405.5 K, R = 0.08206 atm. Liter/mole,
Number of moles (n) = 1
Solution:
Create the script M-file (waals_solv.m) and
function M-file (waals).
% script M-file: waals_solv.m
% declare the values of the constants
global press a b R T
Pcrit = 111.3; % in atm
Tcrit = 405.5; % in Kelvin
R = 0.08206; % in atm.liter/g-mole.K

16
T = 450; %T in Kelvin
% The different values of pressure are stored ...
in a single vector “Preduced”:
Preduced = [2 4 6 10 15 20];
a = (27/64)*R^2*Tcrit^2/Pcrit;
b = R*Tcrit/(8*Pcrit);
% each pass of the loop varies the pressure ...
and the volume is calculated
for j = 1:6
press = Pcrit*Preduced(j);
% Built_in MATLAB program “fzero” uses Newton’s
% method for solving a %single algebraic equation.
%An initial guess for “vol” is required:
volguess = R*T/press;
% “volguess” is an initial guess for variable “vol”
% call built_in MATLAB function “fzero” (or fsolve)
% to calculate volume:
vol = fzero(@waals, volguess);
z = press*vol/(R*T); % z is compressibility factor
% Store calculation results in matrix “result”:
result(j,1) = Preduced(j);
result(j,2) = vol;
result(j,3) = z;
end
%end of calculations
disp(' Preduced Molar Vol Zfactor ')
disp(result)
plot(result(:,1),result(:,3),'r')
title('Compressibility factor vs Reduced pressure')
xlabel('Reduced pressure')
ylabel('Compressibility factor')
From editor window create function program “waals_solv” to solve for the variable
“vol”:
function y = waals(vol)
%function M-file: waals.m
global press a b R T
y = (press + a/vol^2)*(vol - b)- R*T;
end
To run program; type in command window the script file name: “waals_solv”:

17
>> waals_solv
Preduced Molar Vol Zfactor
2.0000 0.0773 0.4658
4.0000 0.0607 0.7313
6.0000 0.0556 1.0056
10.0000 0.0509 1.5334
15.0000 0.0479 2.1671
20.0000 0.0462 2.7835
Compressibility factor vs Reduced pressur
3

2.5
Compressibility factor

1.5

0.5

0
2 4 6 8 10 12 14 16 18 20
Reduced pressur

Figure 1.4: Van der Waals equation


1.9.2 Laying plots one on top of another
Example 1.16
x = 0:pi/100:2*pi;
y1 = cos(x*4);
plot(x,y1)
y2 = sin(x);
hold
plot(x,y2)

18
1

0.8

0.6

0.4

0.2

-0.2

-0.4

-0.6

-0.8

-1
0 1 2 3 4 5 6 7

Figure 1.5: layer plots for example 1.16

Example 1.17
Create script file ‘example1.m’ in editor:
c0 = 1;
t = [0:0.1:1];
f = c0*exp(-lambda*t);
plot(t,f);
In command window:
>> lambda = 1;
>> example1;
>> hold on;
>> lambda = 2;
>> example1;
>> lambda = 3;
>> example1;
>> legend('lambda = 1','lambda = 2','lambda = 3');

19
1
lambda = 1
0.9 lambda = 2
lambda = 3
0.8

0.7

0.6

0.5

0.4

0.3

0.2

0.1

0
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

Figure 1.6: Plot for Example 1.17


1.9.3 Sub Plots
The syntax subplot (m,n,p) subdivides the command window into a grid of m rows
and n columns. The variable p identifies the portion of the window where the next
plot will be drawn.

P=1 P=2

P=3 P=4

Example 1.18
Create the following MATLAB program:
x = 0:pi/20:2*pi;
subplot(2,1,1)
plot(x,sin(x))
subplot(2,1,2)
plot(x,sin(2*x))

20
1

0.5

-0.5

-1
0 1 2 3 4 5 6 7

0.5

-0.5

-1
0 1 2 3 4 5 6 7

Figure 1.7: Plot for Example 1.18


Example 1.19
Create the following MATLAB program:
x = linspace(0,2*pi);
subplot(2,2,1);
plot(x,cos(x)); title('cos(x)');
subplot(2,2,2);
plot(x,cos(2*x)); title('cos(2x)');
subplot(2,2,3);
plot(x,cos(3*x)); title('cos(3x)');
subplot(2,2,4);
plot(x,cos(4*x)); title('cos(4x)');
See Fig. 1.8
1.9.4 The fplot function
This function allows you to plot a function without defining arrays of corresponding x-
and y- values. For example:
fplot(sin(x)’,[-2*pi,2*pi]) creates a plot of x versus sin(x) form -2 π to 2 π . MATLAB
automatically calculates the spacing of x values to create a smooth curve.

21
cos(x) cos(2x)
1 1

0.5 0.5

0 0

-0.5 -0.5

-1 -1
0 2 4 6 8 0 2 4 6 8

cos(3x) cos(4x)
1 1

0.5 0.5

0 0

-0.5 -0.5

-1 -1
0 2 4 6 8 0 2 4 6 8

Figure 1.8: Plot for Example 1.19

1.10 Three-Dimensional Plotting


The plot3 function is similar to the plot function, except that it accepts data in three
dimensions, x, y, and z.
Function plot3 plots lines and points in 3-D space. plot3(x,y,z), where x, y and z are
three vectors of the same length, plots a line in 3-space through the points whose
coordinates are the elements of x, y and z.
Thus plot3(x,y,z), where x, y and z are three matrices of the same size, plots several
lines obtained from the columns of x, y and z.
Example 1.20
clear all; %clear all variables
clc; %clears the command window
clf; %clears the Figure window
%specify values of t,x to be included in the grid:
[t,x] = meshgrid(0:0.1:5, -0:0.5:5);
%define the output function:
y =(exp(-0.2*t))+(sin(3*x)).^2
plot3(t,x,y) %to create surface plot
xlabel(‘time’); %x axis label as time
ylabel(‘input’); %x axis label as input
zlabel(‘Amplitude’) %z axis label as Amplitude
colormap hsv
color bar

22
Figure 1.9: Plot for Example 1.20
Example 1.21 ( A helix)
t = 0:pi/50:10*pi;
plot3(sin(t),cos(t),t);

Figure 1.10: The Helix for example 1.21

1.11 Surface Plots


Surface plots allow us to represent data as a three-dimensional surface surface . There
are two types of surface plots: mesh plots and surf plots. Surf plots are similar to mesh
plots but surf creates a colored surface instead of a mesh.
The command for a mesh plot is: mesh(x,y,z).

23
Example 1.22 (Creation of a mesh plot)
x=[-2:0.2:2];
y=[-2:0.2:2];
[X,Y] = meshgrid(x,y);
z = X.*exp(-X.^2 - Y.^2);
mesh (X,Y,z)
title(‘Mesh Plot’), xlabel(‘x-axis’),ylabel(‘y-
axis’),zlabel(‘z-axis’)

Mesh Plot

0.5
z-axis

-0.5
2
1 2
0 1
0
-1 -1
y-axis -2 -2
x-axis

Figure 1.11: Mesh Plots for example 1.22

1.11 Surface Plots


Example 1.23 (Mesh grid as an art work!)
[x,y] = meshgrid(-10:0.5:10, -10:0.5:10);
% meshgrid transforms the specified domain where
% -10 < x < 10, and
% -10< y < 10 into a grid of (x,y) values for
%evaluating z
r = sqrt(x.^2 + y.^2) + eps
%we add the machine epsilon eps
z = sin(r)./r; % so 1/r won’t blow up
mesh(z)

24
Figure 1.12 Plot for Example 1.23

25
Exercises
1.1 The height of each of five symmetrical triangles is 20 cm. Calculate the areas of
the triangles if the bases of the triangles are given by the vector:
Base = [2 3 7 9 15] cm

1.2 Calculate the average of the diagonal elements in the following matrix:

1 2 3 4 5
7 8 -1 3 3
1 -2 5 7 6
2 2 2 2 2
-1 4 6 9 10

1.3 Use a for loop to find the average of the elements in the following vector:
X = [14,27,76,41,52,83,91,12]

1.4 Repeat the previous problem using a while loop

1.5 Write a MATLAB loop structure to calculate the sum of odd numbers from 1 to
99.

1.6 Use an if statement structure to find the maximum value of the vector in problem
1.3

1.7 The ideal gas law is expressed as:


𝑃𝑉 = 𝑛𝑅𝑇
The van der Waals equation for real gases is expressed by the following relation:
𝑛2 𝑎
(𝑃 + 2 ) (𝑉 − 𝑎𝑏) = 𝑛𝑅𝑇
𝑉
Plot (on the same Figure) the variation of gas pressure (bar) versus temperature
change from 100 K to 500 K, given the following data:
Moles, n = 2 mol
Volume, V = 1 L
a = 5.536 L2bar/mol2
b = 0.03049 L/mol
R = 0.08314472 Lbar/K mol

1.8 For above problem, plot variation of temperature as pressure is changed from 50
to 400 bar.

1.9 The ideal gas law states that:


PV = nRT

26
Where P is pressure in kPa, V is volume in m3 , n is number of kmoles, R is ideal gas
constant = 8.314 kPa m3 / kmol K, T is temperature in kelvins.
The mass of gas in kg = nxMW, where MW is molecular weight of gas.
Use the following formats to calculate mass of gas:
(a) Script M-file file only
(b) Function M-file only
(c) Script and function M-files.
Input data:
Volume =1000 m3, Temperature = 300 K, Pressure = 100 kPa, Molecular weight = 29
kg/kmol, R = 8.314 in kPa m3 / kmol K.

1.10 The density of water (ρ) is related to its temperature via the following equation:
ρ = 62.122 + 0.0122T – 1.54X10-4T2
ρ is in lbm/ft3, and T is in O F.
Use the following formats to calculate the density of water at 60O F:
Script M-file file only
Function M-file only
Script and function M-files.

1.11 The viscosity of water (μ) is related to its temperature via the following equation:
1057.51
Ln μ = -11.0318 + 𝑇+214.624
μ is in lbm/ft.s, and T is in O F.
Use the following formats to calculate the viscosity of water at 60O F:
(a) Script M-file file only
(b) Function M-file only
(c) Script and function M-files.

1.12 Try the next meshgrid for fun!

[x,y] = meshgrid(-10:0.5:10, -10:0.5:10);


r = sqrt(x.^2 + y.^2);
z = Besseli(0,r)
mesh(z)

1.13 Do the following meshgrid:


clear all;
clc;
[X, Y] = meshgrid(-10:0.25:10, -10:0.25:10);
f = sinh(sqrt((X/pi).^2 + (Y/pi).^2));
meshz(X, Y, f)
xlabel(‘\bfx’);
ylabel(‘\bfy’);
27
zlabel(‘\bfAmplitude’)
colormap hsv
colorbar

28
CHAPTER
Nonlinear Algebraic

2
2.1 Single Non-linear Algebraic Equations
Systems

Numerical techniques for solving single variable nonlinear algebraic equations


include:
1. Newton’s Method (Also known as Newton Raphson Method)
2. Secant Method
3. Bisection Method
4. Wegstein Method
5. False Position Method
6. Fixed-Point Iteration
7. Successive Substitution Method
2.1.1 Newton’s Method
This method is one of the most popular and powerful procedures for finding the
roots of a single nonlinear equation. It requires the evaluation of both the function
𝑓(𝑥) and its derivative 𝑓 ′ (𝑥 ).
The algorithm for this method is derived from Taylor’s series expansion for a
function 𝑓(𝑥) expanded about 𝑥𝑛 .
(𝑥−𝑥𝑛 )2
𝑓(𝑥) = 𝑓(𝑥𝑛 ) + (𝑥 − 𝑥𝑛 )𝑓 ′ (𝑥𝑛 ) + 𝑓 " (𝜂(𝑥))
2

29
where 𝜂(x) lies between 𝑥 and 𝑥𝑛 . Let α be the root and 𝑥𝑛 is the nearest
approximation to the root. Since 𝑓(α) = 0, then with x = α, we have
(α−𝑥 )2
𝑓(α) = 0 = 𝑓(𝑥𝑛 ) + (α − 𝑥𝑛 )𝑓 ′ (𝑥𝑛 ) + 𝑛
𝑓 " (𝜂(𝑥))
2
Neglecting higher order terms we get:
0 ≌ 𝑓(𝑥𝑛 ) + (α − 𝑥𝑛 )𝑓 ′ (𝑥𝑛 )
Solving for α , we get:
𝑓(𝑥𝑛 )
α ≌ 𝑥𝑛 − ′
𝑓 (𝑥𝑛 )
which should be a better approximation to α than 𝑥𝑛 . If we call this approximation
𝑥𝑛+1 , then we get:
𝑓(𝑥𝑛 )
𝑥𝑛+1 = 𝑥𝑛 − ′
𝑓 (𝑥𝑛 )
The above iterative formula is called the Newton’s method. Usually Newton’s method
converges quickly if the initial guess is sufficiently close to the actual root. The most
serious problem with Newton’s method is that some functions are difficult to
differentiate analytically. As will be explained later, this difficulty may be overcomed
by using MATLAB symbolic mathematics.

Figure 2.1: Newton’s Method


Example 2.1
Use Newton’s method to find the root of the following algebraic equation:
𝑥 3 − 2𝑥 − 1 = 0
(a)Manually
(b)Using a User-defined function
(c)Using a Built_in MATLAB function
Take an initial approximation 𝑥0 = 1.5
Solution:
(b)Manual Solution (based on Newton’s Method)
𝑓 ′ (𝑥) = 3𝑥 2 − 2
′ (𝑥)
Evaluate 𝑓(𝑥) and 𝑓 at the given approximation 𝑥0 = 1.5:

30
When 𝑥0 = 1.5, then 𝑓(𝑥0) = −0.625, and 𝑓 ′ (𝑥0) = 4.750
Using Newton’s iterative formula, we get:
𝑓(𝑥0 )
𝑥1 = 𝑥0 − ′
𝑓 (𝑥0 )
−0.625
= 1.5 − = 1.631579
4.750
Now evaluate 𝑓(𝑥) and 𝑓 ′ (𝑥) at the new approximation 𝑥1 , gives:
When 𝑥1 = 1,631579, then𝑓(𝑥1 ) = 0.0801869, and 𝑓 ′ (𝑥1 ) = 5.9861501
Using the Newton’s iterative formula we obtain another approximation. The
successive iterations are shown in the table 2.1 below:

Table 2.1: Newton’s Method Iterations


k 𝑥k f(𝑥 k) 𝑓 ′ (𝑥 k) Error = 𝑥 - 𝑥 k
0 1.500000 -0.625000 4.750000 0.1180339
1 1.631579 0.0801869 5.9861501 -0.0135451
2 1.618184 0.000878 5.855558 -0.0001501
3 1.618034 0.00000007 5.854102 -0.0000001

(b) Using a User-defined function (based on Newton’s Method)


We create two functions:
1.newton.m which contains the algebraic equation to be solve set as 𝑓(𝑥) = 0.0
2.newton_diff.m which contains the derivative of 𝑓(𝑥).

function f = newton( x )
f = x.^3 - 2.*x -1;
end

function f = newton_diff( x )
f = 3.*x^2 - 2.0;
end

Create a script file (newton_solve):


% Newton's method
x0 = 1.5;
while max(abs(feval(@newton,x0))) > 1e-4;
% 1e-4 is required accuracy, i.e. 0.0001
f = feval(@newton,x0);
fdiff = feval(@newton_diff,x0);

31
x0 = x0 - fdiff\f;
% back slash (\) is more efficient than normal
division slash (/)
end
Note that the function feval executes the specified function.
feval(F,x1,...,xn) evaluates the function specified by a function handle or function
name, F, at the given arguments, x1,...,xn. For example, if F = @foo, feval(F,9.64) is
the same as foo(9.64).
In the command window enter:
>> newton_solve
x0 = 1.6180
Alternatively we can place the two functions (newton.m and newton_diff) in a single
M.file as follows:
Create function file newton_1 which contains the equation to be solved (writtent as
f(1)) and its derivative (set as f(2)):

function f = newton_1( x )
f(1) = x.^3 - 2.*x -1; % equation to be solved
f(2) = 3.*x^2 - 2.0; % derivative of the equation
end

Next create a script file (newton1_solve) to run M.file newton_1:


% script file newton1_solve:
% Newton's method with the function and its ...
derivative placed in same file
x0 = 1.5;
f = feval(@newton_1, x0);
while abs(f(1)) > 1e-4;
f = feval(@newton_1, x0);
% note that ‘f’ is an array which contains both the
%function and its derivative.
x0 = x0 - f(2)\f(1);
end
>> newton1_solve
x0 =
1.6180
(c) Using a Built_in MATLAB function (based on Newton’s method)
The MATLAB function to be used is the fzero function.
Create function with name example2_1.m:

function f = example2_1(x)
32
f(1) = x.^3 - 2.*x -1;

Then from the command window invoke the function example2_1 with the initial
guess x0 = 1.5:
>> x = 1.5;
>> fzero (@example2_1, x)
The symbol @example2_1 is called fhandle. The old MATLAB command was:
>> fzero(‘example2_1’, x)
2.1.2 The Secant Method
The main difficulty in using Newton’s method is that it may sometimes be difficult or
impossible to differentiate the function f(x). The calculation of the derivative 𝑓′(𝑥 )
analytically may be avoided by approximating the slope of the tangent at 𝑥 = 𝑥𝑛 by
that of the chord joining the two points (𝑥𝑛−1 ,𝑓(𝑥𝑛−1 )) and (𝑥𝑛 , 𝑓(𝑥𝑛 )). The
slope of the chord (or secant) is:
𝑓(𝑥 ) −𝑓(𝑥𝑛−1 ))
𝑓′(𝑥𝑛 ) ≈ 𝑛
𝑥𝑛 − 𝑥𝑛−1
Then by substituting this approximation of the derivative of the function in the
Newton’s iterative formula, we get:
(𝑥 − 𝑥 )𝑓(𝑥𝑛 )
𝑥𝑛+1 = 𝑥𝑛 − 𝑛 𝑛−1
𝑓(𝑥𝑛 ) − 𝑓(𝑥𝑛−1 )
The drawback of the secant method is that it requires two initial approximations to
start the iterations.

Figure 2.3: Secant Method


Example 2.2
Solve the following equation (on the basis of the secant method):
𝑥 3 − 2𝑥 − 1 = 0
(a)Manually
(b)Using a User-defined function
Solution:
(a) Manual Solution (based on the secant method)

33
Two initial guesses 𝑥0 =1.5 and 𝑥1 =2 will be used.
When 𝑥0 =1.5, then f(𝑥0 ) = - 0.625 and when 𝑥1 = 2, then f(𝑥1 ) = 3
We use the secant method iterative formula:
(𝑥𝑛 − 𝑥𝑛−1 )𝑓(𝑥𝑛 )
𝑥𝑛+1 = 𝑥𝑛 − 𝑓(𝑥
𝑛 ) − 𝑓(𝑥 )
𝑛−1
To illustrate the iterations we will do two iterations in the command window:
>>𝑥0 = 1.5; 𝑥1 = 2;
(𝑥1 −𝑥0 )𝑓(𝑥1 )
>>𝑥2 = 𝑥1 − 𝑓(𝑥
1 ) − 𝑓(𝑥 )
0
𝑥2 = 1.586207
>>𝑥0 = 𝑥1 ; 𝑥1 = 𝑥2 ;
(𝑥2 −𝑥1 )𝑓(𝑥2 )
>>𝑥3 = 𝑥2 − 𝑓(𝑥 ) − 𝑓(𝑥 )
2 1
𝑥3 = 1.609805
The successive iterations are shown in the table below:
Table 2.2: Secant’s Method Iterations
k 𝑥𝑘−1 𝑥𝑘 𝑥𝑘+1 f(𝑥𝑘+1 )
0 1.500000 2.000000 1.586207 0.1814342
1 2.000000 1.586207 1.609805 0.0478446
2 1.586207 1.609805 1.618257 0.0013040
3 1.609805 1.618257 1.618032 0.0000090

(b) User-defined MATLAB Solution (based on the secant method):


Since at 𝑥0 =1.5, f(𝑥0 ) = -0.625, and at 𝑥1 =2, f(𝑥1 )=3
We use the secant method iterative formula:
(𝑥 −𝑥 )𝑓(𝑥𝑛 )
𝑥𝑛+1 = 𝑥𝑛 − 𝑛 𝑛−1
𝑓(𝑥𝑛 ) − 𝑓(𝑥𝑛−1 )
MATLAB Program:
In the editor window create the following function (secant.m):

function f = secant( x )
f = x.^3 - 2.*x -1;
end

In the editor window create the following script


file (secant_solve.m):
% secant method
x0 = 1.5; x1 = 2.0;
while max(abs(feval(@secant,x1))) > 1e-4; % 1e-4 is
the required accuracy.
f0 = feval(@secant,x0);

34
f1 = feval(@secant,x1);
x2 = x1 -(x1-x0)*f1/(f1 - f0);
x0 = x1;
x1 = x2;
end
In the command window type the name of the script file:
>>secant_solve
2.1.3 MATLAB roots Function
If the nonlinear algebraic system is a polynomial equation then we can use the roots
function.
Let the function be in the form: f(x) = 𝑥 3 − 5𝑥 2 - 𝑥 + 2
First create a vector of the coefficients of the polynomial in descending order:
In the command window type p = [1 -5 -1 2] then type roots(p):
>> p = [1 -5 -1 2];
>> roots(p)
ans =
5.1190
-0.6874
0.5684
2.1.4 MATLAB built_in function (using symbolic mathematics)
Note: Symbolic Mathematics will be presented later on in the chapter on Symbolic
Mathematics.
Enter the equation (e.g. x^2 = 9) as an anonymous function as in the following
example:
Example 2.3
Solve the following equation using Newton method and MATLAB symbolic
mathematics:
x.^3-2*x = 1
MATLAB program:
%Program raphson2.m solves an algebraic equation using
%symbolic algebra and an anonymous function
x(1) = input('Enter Initial Guess:');
error = input('Enter allowed Error:');
% enter the equation as an anonymous function:
f = @(x) x.^3 - 2*x - 1;
% The anonymous function will next be converted to a
%symbolic function.% The variable (x) remains
%numeric.
dif=diff(sym(f)); % sym(f) converts function (f) to
%a symbolic function

35
k = inline(dif);
%inline generates an inline object from a sym
%object. G = inline(F) generates an inline object G
%from the symbolic expression F using the MATLAB
%Function sym method.
for i=1:100
x(i+1)=x(i)-((f(x(i))/k(x(i))));
err(i)=abs((x(i+1)-x(i))/x(i));
if err(i) < error
break
end
Solution:
>> raphson2
Enter Initial Guess: 1
Enter allowed Error: 0.001
root = 1.6183
2.2 Multiple Nonlinear Algebraic Equations
Given:
f1(x,y) = 0
f2(x,y) = 0
Using Taylor’s theorem for functions of two variables with an initial approximation
(x,y), and neglecting higher order terms:
∂f1 ∂f1
∂x ∂y xn+1 − xn f
(∂f ) (y y ) =( 1)
2 ∂f2 n+1− n f2
∂x ∂y
𝜕f1 𝜕f1 −1
xn+1 xn 𝜕x 𝜕y f1
(y ) = ( y ) - (𝜕f ) ( )
n+1 n 2 𝜕f2 f2
𝜕x 𝜕y
∂f1 ∂f1
∂x ∂y
We call the matrix (∂f ∂f2
) the jacobian matrix.
2
∂x ∂y
The following three methods will be presented:
1. Newton’s Method (Manual calculations)
2. MATLAB user-defined Method
3. MATLAB built-in function (based on Newton’s method)
Example 2.4 (system of nonlinear algebraic equations)
Solve the following system of two equations numerically using the Newton’s method.
𝑥2 + 𝑦2 = 4
𝑥𝑦 = 1

36
(a)Manually
(b) User-defined function
(c) Built_in MALAB function
Assume initial estimates of x0 = 3.0 and y0 = -1.5
(a)Manual Solution
∂f ∂f1
𝑓1 = 𝑥 2 + 𝑦 2 - 4 , ∂x1 = 2𝑥, = 2𝑦
∂y
∂f2 ∂f2
𝑓2 = 𝑥𝑦 - 1 , = 𝑦 , =𝑥
∂x ∂y
At the given initial guesses (3.0,-1.5), get:
∂f ∂f1
𝑓1 = 7.25 , 1 = 6, = - 3.0
∂x ∂y
∂f2 ∂f2
𝑓2 = −5.5 , = −1.5 , = 3.0
∂x ∂y
The next step is to determine the jacobian matrix and its inversion at the given point:
∂f1 ∂f1
∂x ∂y 6.0 − 3.0
J= (∂f ∂f2
) =( )
2 −1.5 3.0
∂x ∂y
Inversion of a 2x2 matrix (A) is accomplished through the following formulation:

a11 a12 −1 1 a −a12


A-1 =( ) = a a −a a ( 22 )
a21 a22 11 22 12 21 −a 21 a11

J-1 = 13.5 (3.0 3.0)


1
Therefore
1.5 6.0
Substituting these values:
x1 3.0 1 3.0 3.0 7.5 2.61112
( ) = ( ) - ( )( )= ( )
y1 − 1.5 13.5 1.5 6.0 −5.5 0.43889

Table 2.3 shows all the iterations:


(b) MATLAB User-defined Solution
Program two_equ.m.Function ftwo_equ calculates the values of functions f1, and f2.
Function jtwo_equ calculates the values of j(i,j) needed for the calculation of the
jacobian matrix
Table 2.3 Iterations for Example 2.4
k x y 𝑓1 𝑓2
0 3.00000 -1.50000 7.250000 -5.5000000
1 2.61112 0.138889 2.837240 -0.637344
2 2.053259 0.412649 0.386153 -0.152725
3 1.939689 0.509856 0.0223458 -0.011039
4 1.931894 0.5175954 0.0001194 -0.00000606
5 1.931852 0.5176381 0.00000135 -0.0000002

37
function f = ftwo_equ(x)
%function for solution of two simultaneous
%nonlinear algebraic %equations
f(1) = x(1).^2 + x(2).^2 - 13;
f(2) = x(1).*x(2) - 6;;
end

function j = jtwo_equ(x)
j(1,1)= 2*x(1);
j(1,2)= 2*x(2);
j(2,1)= x(2);
j(2,2)= x(1);
end
To run the program enter in command window >> two_equ
%Program two_equ.m
%function ftwo_equ calculates the values of
%functions f1,f2.
%function jtwo_equ calculates the values of j(i,j)
%needed for the calculation of the jacobian.
%Initial guesses for concentrations and
%temperature:
x0 = [1.0 2.0]';
while max(abs(feval(@ftwo_equ,x0))) > 1e-4;
f = feval(@ftwo_equ,x0);
j = feval(@jtwo_equ,x0);
x0 = x0 - (j\f');
end
fprintf(' x = %4.2f\n y = %4.2f\n ',x0)
Results:
x = 2.00
y = 3.00
(c)MATLAB Built-in function
The MATLAB function fsolve solves systems of nonlinear equations of several
variables. fsolve attempts to solve equations of the form: F(X) = 0 where F and X
may be vectors or matrices. X = folve(FUN,X0) starts at the matrix X0 and tries to
solve the equations in FUN. FUN accepts input X and returns a vector (matrix) of
equation values F evaluated at X.
X = fsolve(FUN,X0,OPTIONS) solves the equations with the default optimization
parameters replaced by values in OPTIONS, an argument created with the
OPTIMOPTIONS function.

38
[X,FVAL] = fsolve(FUN,X0,...) returns the value of the equations FUN at X.
X,FVAL,EXITFLAG] = fsolve(FUN,X0,...) returns an EXITFLAG that describes
the exit condition of fsolve. Possible values of EXITFLAG and the corresponding exit
conditions are listed below.:
1 fsolve converged to a root.
2 Change in X too small.
3 Change in residual norm too small.
4 Computed search direction too small.
0 Too many function evaluations or iterations.
-1 Stopped by output/plot function.
-2 Converged to a point that is not a root.
-3 Trust region radius too small (Trust-region-dogleg).
FUN can be specified using @:
x = fsolve(@myfun,[2 3 4],optimoptions('fsolve','Display','iter'))
where myfun is a MATLAB function such as:
function F = myfun(x)
F = sin(x);
FUN can also be an anonymous function:
x = fsolve(@(x) sin(3*x),[1 4],optimoptions('fsolve','Display','off'))
Solution:

function f = ftwo_equ(x)
% Rewrite the equations in the form f(x) = 0:
f(1) = x(1).^2 + x(2).^2 - 13;
f(2) = x(1).*x(2) - 6;;
end

Write Script file:


x0 = [1.0 2.0];
[x,FVAL,EXITFLAG] = fsolve(@ftwo_equ,x0)
MATLAB displays following information:
Equation solved.
fsolve completed because the vector of function values is near zero as measured by
the default value of the function tolerance, and the problem appears regular as
measured by the gradient.
<stopping criteria details>
x=
2.0000 3.0000
FVAL =
1.0e-06 *
0.1134 -0.0401
EXITFLAG =

39
1
Example 2.5
Solve the system of the following two non-linear algebraic equations:
2𝑥1 − 𝑥2 = 𝑒−𝑥1
-𝑥1 + 2𝑥2 = 𝑒−𝑥2
Rewrite the equations in the form f(x) = 0:
2𝑥1 − 𝑥2 − 𝑒−𝑥1 = 0
-𝑥1 + 2𝑥2 − 𝑒−𝑥2 = 0
Start your search for a solution at x0 = [-5 -5].
First, write a file (myfun.m) that computes f, the values of the equations at x.

function f = myfun(x)
f = [2*x(1) - x(2) - exp(-x(1));
-x(1) + 2*x(2) - exp(-x(2))];
end

ave this function file as myfun.m somewhere on your MATLAB path. Next, set up
the initial point and options and call fsolve:
>>x0 = [-5; -5]; % Make a starting guess at the solution
>>options = optimoptions('fsolve','Display','iter'); % Option to display output
>>[x,fval] = fsolve(@myfun,x0,options) % Call solver
After several iterations, fsolve finds an answer:
x=
0.5671
0.5671
fval =
1.0e-006 *
-0.4059
-0.4059
Example 2.6 (Material and Energy Balances Round CSTR)
Consider the following continuously stirred tank adiabatic reactor (CSTR):
operating at non-isothermal exothermic conditions:

A B C
Where:

F,𝐶𝐴0 , 𝑇𝑖𝑛

40
CSTR
F
𝐶𝐴 , 𝐶𝐵 , 𝐶𝐶
𝑇𝑂𝑈𝑇

Figure 2.4: CSTR for example 2.6

r1=k1 𝐶𝐴 exp(-E1/RT), r2=k2 𝐶𝐵 exp(-E2/RT)


r1 and r2 are in units per volume reactor
Given data in consistent units:
R = 1.987, F = 50, 𝐶𝐴0 = 1.0, volume (vol) = 100, σ (density) = 0.8,
cp (heat capacity) = 0.8, k1 = 1.8*106 , k2 = 3.84*106 , E1 = 10000, E2 = 15000
HR1 = -50000, HR2 = -40000, Tin = 10
(a)Calculate the exit component concentrations 𝐶𝐴 , 𝐶𝐵 , and 𝐶C
(b)Plot flow rate (F) versus component concentrations 𝐶𝐴 , 𝐶𝐵 , and 𝐶C
Solution:
Material balances for the three components are as follows:
𝐶𝐴 *F – 𝐶𝐴0 *F + vol*r1 = 0.0
𝐶𝐵 *F – vol*r1 + vol*r2 = 0.0
𝐶C *F – vol*r2 = 0.0
An energy balance round the adiabatic reactor (Q = 0) can be written as:
σFCp(TinT)  r1*HR1  r2*HR2 = 0
MATLAB Script file:
%Program tut32plot.m
%function ftut32 calculates the values of functions
%f1,f2,f3,f4.
%function jac32 calculates the values of j(i,j)
%needed for the calculation of the jacobian.
%global q ca0 vol E1 E2 R ro cp Tin HR1 HR2
% initial guesses for concentrations and
%temperature:
x0 = [0.5 0.5 0.5 50]';
R = 1.987;
F = 50;
ca0= 1.0;
vol = 100;
ro = 0.8; % ro is density
E1 = 10000; E2 = 15000; cp = 0.8;
HR1 = -50000; HR2 = -40000; Tin = 10;

41
while max(abs(feval('ftut32plot',x0))) > 1e-4;
f = feval('ftut32plot',x0);
j = feval('jac32plot',x0);
x0 = x0 - (j\f'); % This is more efficient than
inv(j)*f'
%x0 = x0 - inv(j)*f';
end
fprintf('CA = %4.2f\n CB = %4.2f\n CC = %4.2f\n
Temp. = %4.2f\n',x0)

function f = ftut32plot(x)
% Consecutive reactions in CSTR.
global q ca0 vol E1 E2 R ro cp Tin HR1 HR2
k1 = 1.8*1e6;
k2 = 3.84*1e8;
T = x(4)+ 273;
r1 = k1*x(1)*exp(-E1/R/T);
r2 = k2*x(2)*exp(-E2/R/T);
f(1) = x(1)*F - ca0*F + vol*r1;
f(2) = x(2)*F - vol*r1 + vol*r2;
f(3) = x(3)*F - vol*r2;
f(4) = ro*F*cp*1000*(Tin - x(4)) - HR1*vol*r1 -
HR2*vol*r2;

function j = jac32plot(x)
global F ca0 vol E1 E2 R ro cp Tin HR1 HR2
k1 = 1.8*1e6;
k2 = 3.84*1e8;
T = x(4) + 273; % x(4) is temp. in centigrade and T
is temp. in Kelvin
j(1,1)= F + vol*k1*exp(-E1/R/T);
j(1,2)= 0.0;
j(1,3)= 0.0;
j(1,4)= vol*k1*x(1)*(E1/R/T^2)*exp(-E1/R/T);
j(2,1)= -vol*k1*exp(-E1/R/T);
j(2,2)= F + vol*k2*exp(-E2/R/T);
j(2,3)= 0.0;
j(2,4)= - vol*k1*x(1)*(E1/R/T^2)*exp(-E1/R/T)...
+ vol*k2*x(2)*(E2/R/T^2)*exp(-E2/R/T);

42
j(3,1)= 0.0;
j(3,2)= -vol*k2*exp(-E2/R/T);
j(3,3)= F ;
j(3,4)= - vol*k2*x(2)*(E2/R/T^2)*exp(-E2/R/T);
j(4,1)= -HR1*vol*k1*exp(-E1/R/T);
j(4,2)= -HR2*vol*k2*exp(-E2/R/T);
j(4,3)= 0.0;
j(4,4)= -ro*F*cp- HR1*vol*k1*x(1)*(E1/R/T^2)...
*exp(-E1/R/T) - HR2*vol*k2*x(2)*(E2/R/T^2)...
*exp(-E2/R/T);
end

To run program enter in the command window:


>> tut32plot
Results:
CA = 0.24
CB = 0.46
CC = 0.30
Temp. = 88.28
Example 2.7
A CSTR is used for running the set of the parallel reactions:

Figure 2.5: CSTR for example 2.7


Where:

Given:

43
Reaction volume V =100 liters , Volumetric flow rate Q = 50 liters/sec,
C𝐴0 = 1.0 gmol/liter.
Hint: Out = in + generation – consumption
Material balances for individual components:
Component A: CAQ = CA0Q + V (r3) – V (r1+r2)
Component B: CBQ = V (2r1) – V (r4)
Component C: CAQ = V (r2+r4) – V (r3)
Component D: CAQ = V (r3)
(a) Compute the exit concentrations at a volumetric flow rate of 50 liter/sec.
(b) Prepare a plot of flow rate versus concentration in the range of 12 – 60
liter/sec.
This problem can be solved by considering only three unknowns.
Solution:
(a) Program tut23.m computes the exit concentrations at a volumetric flow rate of
50 liter/sec.

%Script file tut23.m


%function ftut23 calculates the volalues of
%functions f1,f2,f3,f4.
%function jac23 calculates the jacobian of
%f1,f2,f3,f4.
% To run program enter in command window >> tut23
global k q ca0 vol
% initial guesses for concentrations:
x0 = [0.3 0.3 0.3 0.3]';
k = [1.0 0.2 0.05 0.4];
q = 50; ca0= 1.0; vol = 100;
while max(abs(feval('ftut23',x0))) > 1e-4;
f = feval('ftut23',x0);
j = feval('jac23',x0);
x0 = x0 - (j\f');
% The above algorithm is more efficient than:
% x0 = x0 - inv(j)*f';
end
fprintf(' CA = %5.2f\n',x0(1))
fprintf(' CB = %5.2f\n',x0(2))
fprintf(' CC = %5.2f\n',x0(3))
fprintf(' CD = %5.2f\n',x0(4))

function f = ftut23(x)

44
% function for tutorial 2 ; problem can be solved
%using 3 %equations only.
global k q ca0 vol
r1 = k(1)*x(1); r2 = k(2)*x(1)^(3/2);
r3=k(3)*x(3)^2; r4=k(4)*x(2)^2;
f(1) = x(1)*q - ca0*q - vol*r3 + vol*(r1 + r2);
f(2) = x(2)*q - 2*vol*r1+ vol*r4;
f(3) = x(3)*q - vol*(r2 + r4) + vol*r3;
f(4) = x(4)*q - vol*r4;

function j = jac23(x)
global k q ca0 vol
j(1,1)= q+vol*(k(1)+(3/2)*k(2)*x(1)^0.5);
j(1,2)= 0.0;
j(1,3)= -2*vol*k(3)*x(3);
j(1,4)= 0.0;
j(2,1)= -2*vol*k(1) ;
j(2,2)= q+2*vol*k(4)*x(2);
j(2,3)= 0.0;
j(2,4)= 0.0;
j(3,1)= -vol*((3/2)*k(2)*x(1)^0.5);
j(3,2)= -2*vol*k(4)*x(2);
j(3,3)= q + 2*vol*k(3)*x(3);
j(3,4)= 0.0;
j(4,1)= 0.0;
j(4,2) = -2*vol*k(4)*x(2);
j(4,3)= 0.0;
j(4,4)= q;
end

Results of Program tut23.m:


>> tut23
CA = 0.32
CB = 0.78
CC = 0.53
CD = 0.49
(b)Program tut23plot.m computes and plots flow rate versus concentrations in the
range of 12 – 60 liter/sec:
%Script file tut23plot.m

45
%function ftut23 calculates the values of functions
%f1,f2,f3,f4.
%function jac23 calculates the jacobian of
%f1,f2,f3,f4.
%To run program enter in command window >> tut23plot
global k FlowRate ca0 vol
% initial guesses for concentrations:
x0 = [0.3 0.3 0.3 0.3]';
k = [1.0 0.2 0.05 0.4];
q = [12:2:60];
ca0= 1.0;
vol = 100 ;
for m =1:length(q)
FlowRate = q(m);
while max(abs(feval('ftut23plot',x0))) > 1e-4;
f = feval('ftut23plot',x0);
j = feval('jac23plot',x0);
x0 = x0 - (j\f');
% The above method is more efficient than inv(j)*f'
%x0 = x0 - inv(j)*f';
end
result(m,1)= q(m);
result(m,2)= x0(1);
result(m,3)= x0(2);
result(m,4)= x0(3);
result(m,5)= x0(4);
end
disp(result)
plot(result(:,1),result(:,2),'*r')
hold on
plot(result(:,1),result(:,3),'-b')
hold on
plot(result(:,1),result(:,4),'+k')
hold on
plot(result(:,1),result(:,5),'--c')
hold off
title('Flow Rate Versus Concentration ')
xlabel('Flow Rate (q)')
ylabel('Concentration')

46
legend('A','B','C','D','Location','Best')

function f = ftut23plot(x)
global k FlowRate ca0 vol
q = FlowRate;
r1 = k(1)*x(1); r2 = k(2)*x(1)^(3/2);
r3=k(3)*x(3)^2; r4=k(4)*x(2)^2;
f(1) = x(1)*q - ca0*q - vol*r3 + vol*(r1 + r2);
f(2) = x(2)*q - 2*vol*r1+ vol*r4;
f(3) = x(3)*q - vol*(r2 + r4) + vol*r3;
f(4) = x(4)*q - vol*r4;

function j = jac23plot(x)
global k FlowRate ca0 vol
q = FlowRate;
j(1,1)= q+vol*(k(1)+(3/2)*k(2)*x(1)^0.5);
j(1,2)= 0.0;
j(1,3)= -2*vol*k(3)*x(3);
j(1,4)= 0.0;
j(2,1)= -2*vol*k(1) ;
j(2,2)= q+2*vol*k(4)*x(2);
j(2,3)= 0.0;
j(2,4)= 0.0;
j(3,1)= -vol*((3/2)*k(2)*x(1)^0.5);
j(3,2)= 2*vol*k(4)*x(2);
j(3,3)= q + 2*vol*k(3)*x(3);j(3,4)= 0.0;
j(4,1)= 0.0;
j(4,2) = -2*vol*k(4)*x(2);
j(4,3)= 0.0;
j(4,4)= q;

47
Figure 2.5: Plot for Example 2.8
Example 2.9 (Material and energy balance round an adiabatic reactor)
Methanol at 675 C is fed to an adiabatic reactor where 25% of it is dehydrogenated to
formaldehyde according to the reaction:
CH3 OH → HCHO + H2
(a)Determine the degree of freedom of the problem
(b)Select a set of independent unknown variables.
(c)Select a set of independent equations.
(d)Write a MATLAB computer code to calculate the temperature of the gases leaving
the reactor.
(e) Write a MATLAB computer code to plot the variation of exit temperature versus
the inlet temperature
Heat capacities of methanol, formaldehyde, and hydrogen are 12, 17, and 7 cal/mol.C
respectively.
Heat of formation of methanol is - 48.08 kcal/mole
Heat of formation of formaldehyde is -27.70 kcal/mole

CH3OH REACTOR
RE HCHO, CH3OH, H2

Figure 2.6: Methanol Process


Solution:
(a) Basis : 100 moles of fresh methanol feed to reactor

48
Table 3-1 Degree of Freedom Table
PROCESS
Stream Flows 4
T, Q 3
Reaction rate (r) 1

Material Balances 3
Energy Balance 1
Given Temperature 1
Given Conversion 1
Given Heat load (Q) 1
Basis 1
Degrees of Freedom ZERO

Since degree of freedom is zero, the problem is correctly specified.


(b)The independent unknown variables are the exit flow rates of methanol,
formaldehyde, hydrogen in addition to temperature.
Let the symbols M, F, H, and T refer to the variables methanol, formaldehyde,
hydrogen , and exit temperature respectively.
Heat of reaction at 25 C = -27.70 – (-48.08) = 20.38 kcal
(c)Material balances round reactor:
Methanol balance: M = 100 – r (1)
Formaldehyde balance: F = r (2)
Hydrogen balance: H=r (3)
Conversion relation (100 – M)/100 = 0.25 (4)
The values of the four unknown variables in the previous equations can be
determined by solving the system of equations. However, since we want to calculate
the exit temperature, we need to take into account the energy balance round the
reactor.
Take reference temperature = 25 C.
Q = rxΔ𝐻𝑅 + (∑𝑚𝐶𝑃 ) 𝑜𝑢𝑡 (𝑇 − 25) − (𝑚𝐶𝑃 ) 𝑀𝑒𝑡ℎ𝑎𝑛𝑜𝑙 (675 – 25)
0.0 = rx20380 + (Mx12 + Fx17 + Hx7)(T-25) -100x12(675 – 25) (5)
Heat of reaction at 25 C = -27.70 – (-48.08) = 20.38 kcal
Take into account variation of heat of reaction with temperature.
MATLAB program methanol4 calculates the exit temperature on the basis of any
reference temperature.
Script file (methanol4):
%program methanol4 for solving a material and
%energy balance problem. Tref = at any temperature,
%Heat capacities (CP) are functions of temperature

49
%Integration of cp = f(T) using MATLAB Symbolic
%Mathematics.Basis : 100 mol/h methanol in feed
%stream. x1 = methanol flow rate, x2 = HCHO flow
%rate, x3 = H2 flow rate in stream 2. x4 = r
%(extent of reaction), x5 = exit temperature
Tref = input( 'Reference temperature = ');
x0 = [50 50 50 50 700]';
tol =[1e-10 1e-10 1e-10 1e-10 1e-10]';
old = x0 + 1;
while max(abs(x0-old)) > tol;
old = x0;
f = feval(@methanol_fn_4,Tref,old);
j = feval(@methanol_dfn_4,Tref,old);
x0 = old - ((j)\f');
% Left division is more efficient than the
%algorithm: x0 = old - (inv(j)*f');
end;
T_OUT = x0(5) - 273;
% Temperature conversion to centigrade
fprintf('\n')
fprintf(' Flow rate of CH3OH in stream 2 = %6.2f
mol/h', x0(1))
fprintf('\n')
fprintf(' Flow rate of HCHO in stream 2 = %6.2f
mol/h', x0(2))
fprintf('\n')
fprintf(' Flow rate of H2 in stream 2 = %6.2f
mol/h', x0(3))
fprintf('\n')
fprintf(' Temperature of stream 2 = %6.2f C', T_OUT)
fprintf('\n')

% Tref at any temerature


function f = methanol_fn_4(Tref,x)
f(1) = x(1) - 100 + x(4);% Methanol matreial balance
f(2) = x(2) - x(4); % Formaldehyde material balance
f(3) = x(3) - x(4); % Hydrogen material balance
f(4) = 100 - x(1) - 0.25*100; % Conversion relation
A = x(4)*feval(@Heat_Reaction_4,Tref);

50
%T = x(5);
B = x(1)*feval(@Enth_4,1,Tref,T);
C = x(2)*feval(@Enth_4,2,Tref,T);
D = x(3)*feval(@Enth_4,3,Tref,T);
E = 100*feval(@Enth_4,1,Tref,973);
% Feed stream temperature = 675 + 273 = 973 K
f(5) = A + B + C + D - E; % Energy balance
%function j = methanol_dfn_4(Tref,x)
j(1,1) = 1 ;j(1,2) = 0 ;j(1,3)= 0 ;
j(1,4)= 1 ;j(1,5)= 0;
j(2,1) = 0 ;j(2,2) = 1 ;j(2,3)= 0 ;
j(2,4)= -1 ;j(2,5)= 0;
j(3,1) = 0 ;j(3,2) = 0 ;j(3,3)= 1 ;
j(3,4)= -1 ;j(3,5)= 0;
j(4,1) = -1 ;j(4,2) = 0 ;j(4,3)= 0 ;
j(4,4)= 0;j(4,5)=0;
j(5,1) = feval(@Enth_4,1,Tref,T) ;
j(5,2) = feval(@Enth_4,2,Tref,T) ;
j(5,3) = feval(@Enth_4,3,Tref,T) ;
j(5,4) = feval(@Heat_Reaction_4,Tref) ;
%METHANOL :
a = 3.45e01;
b = -2.92e-02;
c = 2.87e-04;
d = -3.13e-07;
e = 1.098e-10;
H_CH3OH = 0.239*(a + b*x(5) + c*x(5)^2 + …
d*x(5)^3 + e*x(5)^4);
% Conversion factor: 1.0 Joule = 0.239 Calorie
%FORMALDEHYDE :
a = 3.28e01;
b = -3.78e-03;
c = 4.72e-05;
d = -3.60e-08;
e = 8.8e-12;
H_CHO = 0.239*(a + b*x(5) + c*x(5)^2 + d*x(5)^3 ...
+ e*x(5)^4);
% HYDROGEN :
a = 1.76e01;

51
b = 6.70e-02;
c = -1.31e-04;
d = 1.0588e-07;
e = -2.92e-11;
H_H2 = 0.239*(a + b*x(5) + c*x(5)^2 + d*x(5)^3 ...
+ e*x(5)^4);
j(5,5)= x(1)*H_CH3OH + x(2)*H_CHO + x(3)*H_H2;
% See Explanations Below :
% Q = x(4)*Heat_Reaction + SUM(ENTHALPIES OF STREAM
%2) - (ENTHALPY OF STREAM 1)......equation (5)
% j(5,5) = Partial derivative of equation (5) with
%respect to x(5)
% j(5,5) = x(1)*(a + b*x(5) + c*x(5)^2 + ...
%d*x(5)^3 + %e*x(5)^4),for methanol +
%x(2)*(a + b*x(5) + c*x(5)^2 + d*x(5)^3 +...
%e*x(5)^4),for formaldehyde,
%x(3)*(a + b*x(5) + c*x(5)^2 + d*x(5)^3 +...
%e*x(5)^4),for hydrogen

function y = Enth_4(I,Tref,T)
if(I==1) % Methanol
a = 3.45e01;
b = -2.92e-02;
c = 2.87e-04;
d = -3.13e-07;
e = 1.098e-10;
elseif (I==2) %Formaldehyde
a = 3.28e01;
b = -3.78e-03;
c = 4.72e-05;
d = -3.60e-08;
e = 8.8e-12;
else % Hydrogen
a = 1.76e01;
b = 6.70e-02;
c = -1.31e-04;
d = 1.0588e-07;
e = -2.92e-11;
end

52
% Integration can be implemented using MATLAB
%symbolic mathematics:
y = 0.239*sym('a+b*x+c*x^2+d*x^3+e*x^4');
y = int(y,Tref,T); % integration using symbolic
%mathematics
y = eval(y)
% An alternative to using symbolic mathematics above
%is as follows:
% y = 0.239*(a*(T-Tref)+b*(T^2-Tref^2)/2+c*(T^3-
%Tref^3)/3+d*(T^4-%Tref^4)/4+e*(T^5-Tref^5)/5)
% The MATLAB integral function can also be used
%for the above integration
%0.239 is conversion factor, 1.0 Joule = 0.239
%calorie

function HEAT = Heat_Reaction_4(Tref)


%This function calculates the heat of reaction at
%Temperature = Tref
HEAT = 20380 + feval(@Enth_4,2,298,Tref)+ ...
feval(@Enth_4,3,298,Tref)-feval(@Enth_4,1,298,Tref);

Results of execution of program methanol4 above:


>> methanol4
Reference temperature = 25
Flow rate of CH3OH in stream 2 = 75.00 mol/h
Flow rate of HCHO in stream 2 = 25.00 mol/h
Flow rate of H2 in stream 2 = 25.00 mol/h
Temperature of stream 2 = 395.93 C
(e)MATLAB program solve_methanol3 plots the variation of exit temperature versus
the inlet temperature. Heat of reaction variation with temperature is not accounted for
in this program.
Script file (solve_methanol3):

%Plotting variation of exit temp with inlet


temperature:
inlet_temp = [650:10:750];
global T1;
for k = 1:length(inlet_temp)
T1 = inlet_temp(k);
x0 =[100,100,100,100,100];

53
x = fsolve(@methanol3,x0);
result(k,1)= inlet_temp(k);
result(k,2) = x(5);
end
disp(result);
plot(result(:,1),result(:,2),'r')
xlabel('Inlet Temperature C')
ylabel('Exit Temperature C')

function f = methanol3(x):
global T1;
Heat_Reaction= 20.38*1e+3;Heat of reaction at 25 C
f(1) = x(1) - 100 + x(4); % Methanol balance
f(2) = x(2) - x(4); % Formaldehyde balance:
f(3) = x(3) - x(4); % Hydrogen balance
f(4) = (100 - x(1))/100-0.25; % Conversion relation
f(5) = x(4)*Heat_Reaction + (x(1)*12+x(2)*17+ ...
x(3)*7)*(x(5)-25) - 100*12*(T1 - 25);

Figure 2.7: Plot of variation of exit temp with inlet temperature


2.3 The Phase Rule
The phase rule (also called Gibbs phase rule) determines the required number of
intensive properties for the complete description of any system in steady state. And
the system is considered completely described if all the intensive properties of the
system are known.

54
The intensive properties are the properties which do not depend on the volume or
the mass of the system (the properties which depend on the volume or the mass of the
system are called extensive properties). The intensive properties include temperature,
pressure, concentration and density (or the invert of density which is known as specific
volume).
The number of intensive properties required to completely describe the steady state
system is known as thermodynamic degree of freedom. And according to the phase
rule this number of intensive properties (D) can be determined from the following
equation:
D=C-+2 (2.1)
D: thermodynamic degree of freedom.
C: number of components.
 : number of phases (gas, liquid and solid).
Notice that the word “components, C” and “molecular species, S” are identical in
systems which do not involve chemical reactions. In such cases, C = S. Thus, the
phase rule in the absence of chemical reactions is:
D=S-+2 (2.2)
However when chemical reactions exist, then C  S. In such cases, these two variables
are related as follows:
C=S–R
Where R refers to the number of independent reactions in the system. Thus, the
phase rule in the presence of chemical reactions is:

D = (S - R ) -  + 2 (2.3)

It is clear from equation (2.3) that the presence of chemical reactions decreases the
thermodynamic degree of freedom of the system.
2.4 Single-Component Systems
The phase rule for this type of systems is:
D = S - + 2

= 1-  + 2

=3- (2.4)

Equation (2.4) shows that the maximum number of phases for a single component
system is three phases.
This unique case is known as the triple point. See Fig. 2-8.

55
When the system consists of two phases, then there is only one degree of freedom:
D=3–2=1
Thus once the temperature is specified, then the pressure becomes determined
automatically. Antoine relation is used to determine the pressure (P) when the
temperature is known (or vice versa). This equation represents the vapor pressure
curve in Fig. 2-8.

Figure 2.8: P-T for water


𝐵
ln 𝑝 = 𝐴 − (2.5)
𝑇+𝐶
Where A, B and C are constants specific to each component.
2.5 Multi-Component, Multiphase Systems
In these types of systems beside T, P and 𝑉̃ , we need to deal with concentration of
materials in more than one phase. In case of presence of two components and two
phases, the phase rule gives the following results:
D=2–2+2=2
And we have the option to determine only two of the following properties:
T, P, 𝑥𝑖 , 𝑦𝑖
Where xi, yi refer to the molar fraction in liquid and gas phases respectively. Notice
that as:
𝑥1 + 𝑥2 = 1.0
𝑦1 + 𝑦2 = 1.0

56
then we cannot choose 𝑦1 and 𝑦2 (for example) independently because they are
related.
2.6 The Equilibrium Coefficient (K) and Raoult’s Law
The coefficient K (also known as the equilibrium constant) determines the
mathematical relationship between the molar concentrations of materials in the liquid
and gas phases as follows:
𝑦𝑖
𝐾𝑖 = (2.6)
𝑥𝑖
Where:
𝐾𝑖 = 𝐾𝑖 (T, P)
While Raoult’s Law determines the mathematical relation between vapor pressure at
temperature T;
𝑝𝑖 (𝑇), and the total pressure as follows:
𝑝𝑖 (𝑇)
𝐾𝑖 = (2.7)
𝑃
Example 2.10 Using the coefficient K in calculating the concentration in two phases
A system consists of two components and two phases, gas and liquid, at temperature
(T) and pressure (P). Use the coefficient K for calculating the molar fraction of the
two components in the two phases.
Solution:
Firstly, we write the values of 𝐾1 and 𝐾2 from the tables in the appendixes at T and P
for the two components.
𝐾1 𝑥1 = 𝑦1
𝐾1 (1 – 𝑥2 ) =1 – 𝑦2
= 1 – 𝐾2 𝑥2
𝐾1 − 1
𝑥2 =
𝐾1 − 𝐾2
Then we can calculate the remaining molar fractions:
𝑥1 = (1 – 𝑥2 )
𝑦1 = 𝐾1 𝑥1
𝑦2 = 𝐾2 𝑥2
Notice that by using the K coefficients and Raoult’s Law equations we can determine
the concentrations in the two phases, however the determination of the amounts of
each component in each phase requires more information as will be presented later.
2.7 Determination of Temperature and Concentrations in Two
Phase Systems
57
For a system of two components in two phases:
𝑥1 + 𝑥2 = 1.0
𝑦
Since 𝐾𝑖 = 𝑥𝑖 , then
𝑖
𝑦1 𝑦2
+ = 1.0 (2.8)
𝐾1 𝐾2
From Antoine’s equation:
𝐵𝑖
ln 𝑝𝑖 = 𝐴𝑖 −
𝑇 + 𝐶𝑖
𝐵𝑖
𝑝 = exp ( 𝐴𝑖 − )
𝑇 + 𝐶𝑖
𝑝𝑖
𝐾𝑖 =
𝑃
𝐵
exp (𝐴𝑖 − 𝑇+𝐶𝑖 )
𝑖 (2.9)
𝐾𝑖 =
𝑃
By substituting equation (2.9) in equation (2.8) we get the following equation:
𝑦1 𝑃 (1 − 𝑦1 ) 𝑃
𝐵1
+ 𝐵2
= 1.0 (2.10)
exp (𝐴1 − 𝑇+𝐶 ) exp (𝐴2 − 𝑇+𝐶 )
1 2
As the only unknown in equation (2.10) is T, then this nonlinear equation can be
solved to get the value of T. Once T is determined, we can calculate the value of 𝐾1 .
As 𝑦1 is given, we can calculate the required concentration 𝑥1 from the following
equations:
y1
𝑥1 =
K1
𝑥2 = 1 – 𝑥1
𝑦2 = 1 – 𝑦1
Example 2-11 Application of Antoine’s Equation
A two phase mixture consists of benzene and toluene with molar concentrations of
50% for each of them in the gas phase. If the total pressure is 500 mmHg, Calculate:
The mixture temperature and the molar concentrations in the liquid phase.
Solution:
Substituting in equation (6.24) from the appendix table at the end of the book (note
that 500 mmHg = 66.65 kPa)
0.5 × 66.65 0.5 × 66.65
2948.78
+ 3242.38
= 1.0
exp (14.1603 − 𝑇−44.5633) exp (14.2515 − 𝑇−47.1806)

58
The above nonlinear equation was solved using MATLAB function fsolve according
to the following code:
MATLAB Script file:
x0 = 300;
T = fsolve(@Ex2_11,x0);
K1 = 66.65/exp(14.1603-2948.78/(T-44.5633));
x1 = 0.5/K1;
x2 = 1.0 - x1;
fprintf('\n Temperature = %6.4f K\n',T)
fprintf('\n x1 = %4.2f \n',x1)
fprintf('\n x2 = %4.2f \n',x2)

function f = Ex2_11(x)
T = x;
f= (0.5*66.65)/exp(14.1603-2948.78/(T-44.5633))...
+(0.5*66.65)/exp(14.2515-3242.38/(T-47.1806))-1.0;
end

Results:
Temperature = 358.5649 K
x1 = 0.88
x2 = 0.12
2.8 Dew Point and Bubble Point Temperatures
If the system contains two components with mole fraction concentrations 𝑍1 and 𝑍2 ,
and total pressure P, then the phase rule states that this system may contain more than
one phase. To determine the number of phases in such systems it is required to
determine dew point and bubble point temperatures.
If the system consists of one component, we indicate boiling point (or condensation
point). But in case of more than one component we talk about the dew point and
bubble point temperatures.
If the system consists of two component in liquid phase, the bubble point temperature
TB is the temperature in which the first vapor bubble is formed when the temperature
is increased with constant pressure (this bubble will be with concentrations 𝑍1 and 𝑍2 ),
where 𝑍1 and 𝑍2 are the initial mole fractions of the solution.
If the system consists of two component in gas phase, the dew point temperature TD is
the temperature in which the first liquid dew is formed when the temperature is
decreased with constant pressure (this dew will be with concentrations 𝑍1 and 𝑍2 ).
If the system temperature is T, then there will be three probabilities:

59
If T > TD then the system consists of gas phase only.
If T < TB then the system consists of liquid phase only.
If TB < T < TD then the system consists of gas and liquid phases.
Thus the determination of the possibility of the existence of one or more phases can
be done via the calculation of the dew temperature and bubble temperature as will be
explained in a subsequent solved example.
2.8.1 Determination of the Dew Point Temperature
At the dew point, the concentration of the first liquid dew will be the same as that in
the gas phase. Therefore 𝑥1 = 𝑍1 and 𝑥2 = 𝑍2 . Now we can derive the following
relations:
𝑥1 + 𝑥2 = 1.0
𝑧1 𝑧2
+ = 1.0
𝐾1 𝐾2
𝑧1 (1 − 𝑧1 )
+ = 1.0 (2.11)
𝐾1 𝐾2
By substituting equation (2.9) in equation (2.11) we obtain the following equation to
calculate the dew point temperature:
𝑧1 𝑃 𝑧2 𝑃
𝐵1
+ 𝐵2
= 1.0 (2.12)
exp (𝐴1 − 𝑇+𝐶 ) exp (𝐴2 − 𝑇+𝐶 )
1 2
If there are more than two components ( S components) then we need to solve the
following polynomial:
𝑧𝑖 𝑃
∑ 𝐵𝑖
= 1.0 (2.13)
𝑆 exp (𝐴 𝑖 − )
𝑇+𝐶 𝑖

2.8.2 Determination of the Bubble Point Temperature


The bubble point temperature can be determined by assuming that the system is in
liquid phase and by increasing the temperature at constant pressure the first bubble is
formed with concentrations 𝑍1 and 𝑍2 , where 𝑍1 and 𝑍2 are the initial mole fractions
of the solution. It means that 𝑦1 = 𝑍1 and 𝑦2 = 𝑍2 . Now we can derive the following
relations:
𝑦1 + 𝑦2 = 1.0
𝑦1 = 𝐾1 𝑥1
𝑦2 = 𝐾2 𝑥2
𝑍1 𝐾1 + (1 - 𝑍1 ) 𝐾2 = 1.0 (2.14)
Substituting equation (2.9) in equation (2.14) we get the following nonlinear equation
which need to be solved to calculate bubble point temperature

60
TB =
1 𝐵 2 𝐵
𝑧1 exp (𝐴1 − 𝑇+𝐶 ) 𝑧2 exp (𝐴2 − 𝑇+𝐶 )
1 2 (2.15)
+ = 1.0
𝑃 𝑃
For more than two components (S components), then solving the following
polynomial is required:
𝐵
𝑧𝑖 exp (𝐴𝑖 − 𝑇+𝐶𝑖 )
∑ 𝑖
= 1.0 (2.16)
𝑃
𝑆

Example 2.12 ( Number of Phases in a Two-Component System)


An equimolar mixture of benzene and toluene is stored at 1000 mm Hg and a
temperature of 378oK. Determine the number of phases at these conditions.
Solution:
As mentioned earlier, the first step in the solution is the calculation of the dew point
and bubble point temperatures.
Calculation of the dew point temperature:
1000 mmHg = 133.22 kPa
Substituting constants A, B and C of the two components (as obtained from appendix
tables) in equation (2.12), we obtain the following equation in terms of TD =
0.5 × 133.22 0.5 × 133.22
2948.78
+ 3242.38
= 1.0 (2.17)
exp (14.1603 − 𝑇 −44.5633) exp (14.2515 − 𝑇 −47.1806)
𝐷 𝐷
Calculation of the bubble point temperature:
Substituting constants A, B and C of the two components (as obtained from appendix
tables) in equation (2.15), we obtain the following equation in terms of TB =
2948.78 3242.38
0.5 × exp (14.1603 − 𝑇 ) 0.5 × exp (14.2515 − 𝑇 )
𝐵 −44.5633 𝐵 −47.1806
+ (2.18)
133.22 133.22
= 1.0
TD and TB were calculated using the following computer codes:
MATLAB Script file:
x0 = [300,300];
x = fsolve(@Ex2_12,x0);
fprintf('\n Dew Point = %6.4f K\n',x(1))
fprintf('\n Bubble Point = %6.4f K\n',x(2))

function f = Ex2_12(x)
TD = x(1); TB = x(2);

61
f(1)=(0.5*133.22)/exp(14.1603-2948.78/(TD-44.5633))
+(0.5*133.22)/exp(14.2515-3242.38/(TD-47.1806))-1.0;
f(2)=(0.5*exp(14.1603-2948.78/(TB-44.5633)))/133.22+
(0.5*exp(14.2515-3242.38/(TB-47.1806)))/133.22-1.0;
end

Results:
Dew Point = 381.5007 K
Bubble Point = 375.0174 K
As the given system temperature is 378 oK, then the system consists of two phases
vapor and liquid.
2.9 Equilibrium Flash Vaporization
The next diagram represents equilibrium flash vaporization unit. In this unit a liquid
mixture is partially vaporized then the vapor phase resulting from the partial
vaporization is separated from the liquid phase. The vaporization temperature must
be lower than the dew point temperature and higher than the bubble point
temperature.

,(2) Vapour
Flash
T,
, (1) vaporizati EquilibriumP relation betw
(3)
(3) , Liquid
Q T,
P
Figure 2.9: Equilibrium Flash vaporization
Pressure and/or temperature can be adjusted to get the desired vaporization (and if
necessary adding the required amount of heat to increase the temperature to the
desired value). In case of decreasing the pressure with constant temperature (by
adding a suitable amount of heat) the process is called Isothermal Flash Vaporization.
And in case of decreasing the pressure without adding heat the process is called
Adiabatic Flash Vaporization. In both cases the two phases, liquid and vapor, leave
the device at the same pressure and temperature as those inside the device.

62
If the number of components is S in a two-phase system, then the phase rule
determines the thermodynamic degree of freedom D as follows:
D=S–2+2=S
To calculate T and P, the degree of freedom becomes (S – 2), which means that we
only need number of concentrations equals (S – 2) to describe the system completely
and fix the other thermodynamic specifications. But if the aim is to carry out material
balances then it is necessary to determine (S – 1) of concentrations for this purpose.

2.10 Isothermal Flash Calculation


In this section material and energy balances for an isothermal vaporization unit are
presented. The aim of these calculations is to determine the phase distributions as a
result of the vaporization. Thus we determine the amount of vapor V and the amount
of liquid L rates leaving the unit as well as the concentrations of the components in
the two phases. For S components, the degree of freedom table for material and
energy balances is as follows:
Table 2.4: Degree of freedom table
Material balances Energy balances
Streams variables:
Flow rates 3S 3S
Temperatures 3
Heat Load 1
S S
Number of material balances
Number of energy balances 1
Independent given concentrations S–1 S–1
(in feed stream)
Given temperatures 3
K coefficient relations S S
Basis 1 1
Degree of freedom Zero Zero

The derivations of the required equations to make these calculations are as follows:
Material balance around the device per unit mole of feed to the unit with 𝑧𝑖
concentration
𝑧𝑖 = V𝑦𝑖 + L𝑥𝑖 i = 1,...,S (2.19)
K coefficient relations:

63
𝑦𝑖 = K𝑥𝑖 i = 1,...,S (2.20)
Substitute 𝑦𝑖 from equation (2.20) in equation (2.19):
𝑧𝑖 = (𝑉𝐾𝑖 + L) 𝑥𝑖 i = 1,...,S (2.21)

𝑧
∑𝑆𝑖 𝑥𝑖 = 1.0 = ∑𝑆𝑖 𝑖 (2.22)
𝑉𝐾 +𝐿 𝑖
Substitute xi from equation (2.20) in equation (2.21):
𝑦
𝑧𝑖 = (𝑉𝐾𝑖 + 𝐿) (𝐾𝑖 ) i = 1,...,S (2.23)
𝑖
𝐾𝑖 𝑧𝑖
∑𝑆𝑖 𝑦𝑖 = 1.0 = ∑𝑆𝑖 (2.24)
𝑉𝐾𝑖 +𝐿
Substitute equation (2.24) from equation (2.23) we get:
𝑧𝑖 −𝐾𝑖 𝑧𝑖
∑𝑆𝑖 =0 (2.25)
𝑉𝐾𝑖 +𝐿
Since L = 1 – V, then:
𝑧𝑖 (1−𝐾𝑖 )
∑𝑆𝑖 =0 (2.26)
1+𝑉(𝐾𝑖 −1)
Equation (2.26) is known as isothermal flash vaporization equation. Notice that as 𝑧𝑖 is
given and 𝐾𝑖 can be calculated from the relation 𝐾𝑖 = 𝐾𝑖 (T, P) (where T and P are
given), then the only unknown in equation (2.26) is vapor flow rate V.
Example 2.13 (Using isothermal flash vaporization equation)
Calculate the amount of vapor produced from flash vaporization when an equimolar
mixture of benzene and toluene is stored at 1000 mm Hg and a temperature of
378oK.
Solution:
Isothermal flash vaporization equation is:
0.5(1 − 𝐾1 ) 0.5(1 − 𝐾2 )
+ =0
1 + 𝑉(𝐾1 − 1) 1 + 𝑉(𝐾2 − 1)
Where 𝐾1 and 𝐾2 represent the coefficients of benzene and toluene respectively.
𝑝𝑖
𝐾𝑖 =
𝑃
𝐵𝑖
exp(𝐴𝑖 − )
𝑇 + 𝐶𝑖
𝐾𝑖 = (2.27)
𝑃
The following computer code does these calculations and the result is:
Amount of Vapor = 0.4557
Example 2.14: Material and energy balance around isothermal flash vaporization unit
The feed stream in the diagram below is a mixture of n-heptane and n-dodecane with
flow rate of 1 mol/h and molar fraction 0.6 and 0.4 respectively. This mixture is

64
separated by reducing the pressure from 5 bar to 1 bar isothermally at 500 K via
discharging heat. Calculate:
(a)System degree of freedom.
(b) The number of phases in the feed stream
(c)Flow rates of vapor and liquid resulting from the vaporization.
(d)Concentrations of materials in outlet streams.
(e)Amount of heat discharged from the device.
Assume the validity of Raoult’s law for this system.
Solution:
This example contains the following calculation steps:
1. We need first to determine the number of phases in the feed stream. We will
determine the bubble pressure and dew pressure at the feed conditions. If the
feed pressure is greater than the dew pressure and less than the bubble
pressure then we have two phases in the feed stream.
2. In case of the existence of two phases in the feed stream, we calculate the
phase distribution.
3. Using equation (2.26) to calculate V and L as well as concentrations
calculation in vapor and liquid outlet streams (as in example 2.10).
4. Calculation of the heat load on the vaporizer.

Vapour V
(2)
T=
Flash 5
, 0 relation betwe
(1) vaporizati Equilibrium
P
(3) 0
= (3) Liquid
K L
Q P=1
5 ba
r
b
a
r 65
.
Figure 2.10: Isothermal flash vaporization
(a) The degree of freedom table is shown in Table 2.5 below
(b)Program phase_number.m calls two functions bubble_pressue.m and
dew_pressure to determine the bubble and dew pressures to ascertain the number of
phases.
%Script file:phase_number to determine bubble
%pressure and dew pressure
%and then conclude number of phases
x0 = 100;
x = fsolve(@bubble_pressure,x0);
fprintf(' \n bubble pressure = %7.3f \n',x)
x0 = 100;
x = fsolve(@dew_pressure,x0);
fprintf(' \n dew pressure = %7.3f \n',x)

Table 2.5: Degree of freedom table for example 2.14

function f = bubble_pressure(x)

66
%Determination of bubble pressure in an Isothermal
%Flash Unit. Feed: 70% n-dodecane, 30% n-hexane.
%Feed stream pressure(P)=500 kPa.Temperature= 500 K.
BP = x;
Z1 = 0.7; Z2 = 0.3;T = 500;P_Feed = 500;
VP_Dod = exp(14.0587 - 3744.01/(T - 92.8311));
VP_Hex = exp(14.0587 - 2825.42/(T - 42.7089));
f = Z1*VP_Dod/BP + Z2*VP_Hex/BP - 1.0;

function f = dew_pressure(x)
%Determination of dew pressure in an Isothermal
%Flash Unit. Feed: 70% n-dodecane, 30% n-hexane.Feed
%stream pressure(P) = 500 %kPa.Temperature = 500 K.
DP = x;
Z1 = 0.7; Z2 = 0.3;T = 500;P_Feed = 500;
VP_Dod = exp(14.0587 - 3744.01/(T - 92.8311));
VP_Hex = exp(14.0587 - 2825.42/(T - 42.7089));
f = Z1*DP/VP_Dod + Z2*DP/VP_Hex - 1.0;
Results:
bubble pressure = 883.712 kPa
dew pressure = 181.160 kPa
Since feed pressure is 500 kPa, the feed stream consists of two phases.
The flow rates, and concentrations, and heat load Q are calculated via taking material
and energy balances. A computer code was prepared to accomplish these targets.
The flow rates of vapor and liquid streams which are resulted from vaporization are
calculated using isothermal flash vaporization equation (equation 6.31):
0.7 × (1 − 𝐾1 ) 0.3 × (1 − 𝐾2 )
+ =0
1 + 𝑉(𝐾1 − 1) 1 + 𝑉(𝐾2 − 1)
Notice that the coefficient K in the computer code is calculated in paragraph:
//FLASH DRUM FLASHING by calling a function subroutine called K by writing
K(1,500,500). The numbers between brackets refer to n-dodecane (number 1) then
the temperature the pressure respectively.
(c)The concentrations of materials in outlet streams were calculated after calculating V
in paragraph (b) above using the previously derived equations as in the code.
The number of phases in feed stream was determined.
In these two paragraphs the bubble and dew pressures were calculated. If the mixture
was in liquid phase, then reducing the pressure will result in formation of the first
bubble in some stage where vapor concentration in this bubble is the same as the

67
liquid concentration. This pressure is called bubble pressure (notice the similarity with
the explanation of bubble point temperature in previous paragraphs).
At bubble pressure (PB) we can write the following equations:
y1 + y2 = 1.0
K1z1 + K2z2 = 1.0
𝑝1 𝑧1 𝑝2 𝑧2 (2.28)
+ = 1.0
𝑃𝐵 𝑃𝐵
By solving equation (2.27) we determine the bubble pressure. If the system pressure is
higher than bubble pressure, then there is only liquid phase.
And if the mixture is in vapor phase, then increasing the pressure will result in
forming the first liquid dew in some stage where the concentration at this dew is the
same as the vapor concentration (notice the similarity with the explanation of dew
point temperature in previous paragraphs).
At dew pressure (PD) we can write the following equations:
𝑥1 + 𝑥2 = 1.0
𝑧1 / 𝐾1 + 𝑧2 / 𝐾2 = 1.0
𝑧1 𝑃𝐷 𝑧2 𝑃𝐷
+ = 1.0 (2.29)
𝑝1 𝑝2
By solving equation (2.29) we determine the dew pressure. If the system pressure is
lower than dew pressure then there is only vapor phase.
The code calculation shows that the bubble and dew pressures were 882 kPa and 181
kPa respectively. As the given system pressure is 500 kPa then the feed stream
consists of two phases. Notice that as the device pressure was reduced to 250 kPa then
the product also consists of two phases.
The amount of heat withdrawn from the device were determined via making heat
balance around the device. As the temperature of the basis stream and all other
streams are equal, then the vapor phase enthalpy at any stream is in fact the latent heat
of vaporization enthalpy and the symbol (for example) HVAP_Dod refers to the
latent heat of vaporization of n-dodecane at 500 K temperature.
MATLAB code for Example 2.14:
function f = ISOTHERMAL_Ex2_14(x)
%Isothermal Flash Unit
%Isothermal flash calculations needed to determine
%phase distributions of feed %Stream and output
%phase distributions, and concentrations.

68
%Combined M&E Balances and determination of Heat
%Load. Feed: 70% n-dodecane, 30% n-hexane. Feed
%stream %pressure(P) = 500 kPa.Temperature = 500 K.
%Feed pressure is reduced to 250 kPa.
%Isthermal flash equation: Z1*(1-K1)/(1+V*(K1-
%1))+Z2*(1-K2)/(1+V*(K2-1))
%Watson Correlation: H_VAP(T) = H_vap(T0)*(TC-
T)/(TC-%T0))^n
%H_VAP(T) = Latent heat of Vaporization at Temp. T
%TC = Critical Temp., n = 0.38 for most substances
%V_Feed = Flow rate of vapor phase in feed stream
%L_Feed = Flow rate of liquid phase in feed stream
%X1_Feed = Concentration OF n-heptane in Feed Liquid
%Phase. Y1_Feed = Concentration OF n-hexane in Feed
%Liquid Phase
%V = Flow rate of exit vapor phase
%L = Flow rate of exit liquid phase
%X1 = Concentration OF n-heptane in exit Liquid
%Phase
%Y1 = Concentration OF n-hexane in exit vapor Phase
%HVAP_Dod = Latent heat of vaporization of n-
%dodecane
%HVAP_Hex = Latent heat of vaporization of Hexane
BP = x(1);DP = x(2); V_Feed = x(3);L_Feed =
x(4);X1_Feed = x(5); X2_Feed = x(6);
Y1_Feed = x(7); Y2_Feed = x(8); X1 = x(9); X2 =
x(10);Y1 = x(11); Y2 = x(12);
V = x(13); L = x(14);Q = x(15);
Z1 = 0.7; Z2 = 0.3;T = 500;P_Feed = 500;P_Flash =
250;
%Determination of Feed Mixture Bubble Pressure:
VP_Dod = exp(14.0587 - 3744.01/(T - 92.8311));
VP_Hex = exp(14.0587 - 2825.42/(T - 42.7089));
f(1) = Z1*VP_Dod/BP + Z2*VP_Hex/BP - 1.0;
%Determination of Feed Mixture Dew Pressure:
f(2) = Z1*DP/VP_Dod + Z2*DP/VP_Hex-1.0;
%Feed Sream Flashing to Examine Existence of Number
of Phases

69
%and determine Feed Phases Quatities and
Concentrations
K1 = VP_Dod/P_Feed; K2 = VP_Hex/P_Feed;
%Isothermal Flash Equation:
f(3)= Z1*(1-K1)/(1.0 + V_Feed*(K1 - 1))+ Z2*(1-
K2)/(1.0 + V_Feed*(K2 - 1));
f(4) = X1_Feed - Z1/(1.0 + V_Feed*K1 + 1.0);
f(5) = X1_Feed + X2_Feed - 1.0;
f(6) = Y1_Feed - K1*X1_Feed;
f(7) = Y1_Feed + Y2_Feed - 1.0;
f(8) = L_Feed + V_Feed -1.0;
%Flash Drum Flashing to Determine Exit Phase Flows
and Concentrations
P_Flash = 250;
K1 = VP_Dod/P_Flash; K2 = VP_Hex/P_Flash;
f(9)= Z1*(1-K1)/(1.0 + V*(K1 - 1))+ Z2*(1-K2)/(1.0 +
V*(K2 - 1));
f(10) = X1 - Z1/(1.0 + V*K1 + 1.0);
f(11) = X1 + X2 - 1.0;
f(12) = Y1 - K1*X1;
f(13) = Y1 + Y2 - 1.0;
f(14) = L + V - 1.0;
%Energy Balance
%Basis: Liquid phase at 500 K for both components
%HVAP_Dod Estimation:
TC = 660.161;
%TC = Critical Temp. K
T0 = 489.439;
%T0 = Normal boiling point K
HVAP_Dod0 = 43685.1;
%Latent heat of vaporization at normal boiling point
%T0
% Watson Correlation:
HVAP_Dod = HVAP_Dod0*((TC-T)/(TC-T0))^0.38;
%HVAP_Hex Estimation:
TC = 507.861;
%TC = Critical Temp. K
T0 = 341.901;
%T0 = Normal boiling point K

70
HVAP_Hex0 = 28851.3;
%Latent heat of vaporization at normal boiling point
%T0
% Watson Correlation:
HVAP_Hex = HVAP_Hex0*((TC-T)/(TC-T0))^0.38;
H_EXIT_VAPOR = V*(Y1*HVAP_Dod+Y2*HVAP_Hex);
H_Feed_VAPOR =
V_Feed*(Y1_Feed*HVAP_Dod+Y2_Feed*HVAP_Hex);
f(15) = Q - H_EXIT_VAPOR + H_Feed_VAPOR;
Script file:
clc
x0 = [ones(1,14),10000];
x = fsolve(@ISOTHERMAL_Ex2_15,x0);
fprintf(' \n exit vapor flow rate = %7.3f \n',x(13))
fprintf(' \n exit liquidflow rate = %7.3f \n',x(14))
fprintf(' \n heat load = %7.3f \n',x(15))
Results:
exit vapor flow rate = 0.549
exit liquid flow rate = 0.451
heat load = 4998.680
Example 2.15: Adiabatic Flash Vaporization
Calculate the temperature of outlet streams in the device referred to in example 2.14
in case of operating the device by reducing the pressure from 500 kPa to 250 kPa
without adding any heat energy (i.e. adiabatically). The diagram below depicts the
revised configuration of the new adiabatic arrangement.
As a reminder, the feed stream in example 2.14 was a mixture of n-heptane and n-
dodecane with a flow rate of 1 mol/h and molar fractions 0.6 and 0.4 respectively. In
example 2.14, the feed mixture was separated by reducing the pressure from 5 bar to
1 bar isothermally at 500 K via discharging heat.

Figure 2.11: Adiabatic flash vaporization

71
Solution:
We can observe that the system degree of freedom is still zero because we replaced an
unknown variable by another one, as Q is known now (Q = 0.0) but the outlet streams
temperature (T) is unknown now.
The basis in these calculations is also the liquid phase in the feed stream, which is: HL
(500 K, 500 kPa) where HL refers to liquid enthalpy. On this basis the following are
the different streams’ enthalpies (where 𝐻 ̂𝐿 and 𝐻 ̂𝑉 refer to liquid and vapor
enthalpies in J/mole):
Enthalpy of exit vapor = 𝑉(𝐻 ̂𝑉 (500 𝐾, 250 𝑘𝑃𝑎) − 𝐻 ̂𝐿 (500 𝐾, 500 𝑘𝑃𝑎))
Enthalpy of exit liquid = 𝐿(𝐻̂𝐿 (500 𝐾, 250 𝑘𝑃𝑎) − 𝐻 ̂𝐿 (500 𝐾, 500 𝑘𝑃𝑎))
Enthalpy of vapor in feed stream = 𝑉_𝐹𝐸𝐸𝐷(𝐻 ̂𝑉 (500 𝐾, 250 𝑘𝑃𝑎) −
𝐻̂𝐿 (500 𝐾, 500 𝑘𝑃𝑎))
Enthalpy of liquid in feed stream enthalpy (the basis = zero):
𝐿_𝐹𝐸𝐸𝐷(𝐻 ̂𝐿 (500 𝐾, 250 𝑘𝑃𝑎) − 𝐻 ̂𝐿 (500 𝐾, 500 𝑘𝑃𝑎)) = zero
We calculate the exit vapor enthalpy in terms of the unknown temperature T as the
following:
𝑇
𝑉 ∑𝑖 𝑦𝑖 [∆𝐻𝑉,𝑖 (𝑇) + ∫ 𝐶𝑃𝐿,𝑖 𝑑𝑇] = 𝑉 (𝐻 ̂𝑉 (500𝐾, 250 𝑘𝑃𝑎) −
500
̂𝐿 (500𝐾, 250 𝑘𝑃𝑎))
𝐻
A MATLAB code was prepared assuming constant heat capacity. And here is the
calling statements in the code
V*(Y1*(H_vap(1,T)+CP(1,T)*(T-500))+Y2*(H_vap(2,T)+CP(2,T)*(T-500))).
The numbers 1 and 2 refer to the two components n-heptane and n-dodecane
respectively.
Where (H_vap(1,T)) and CP(1,T) are MATLAB function M.files to calculate latent
heat and heat capacity for each component in terms of T.
Similarly, the exit liquid enthalpy is calculated as follows:
𝑇
̂𝐿 (500 𝐾, 250 𝑘𝑃𝑎) − 𝐻
𝐿 (𝐻 ̂𝐿 (500 𝐾, 500 𝑘𝑃𝑎)) = 𝐿 ∑ 𝑥𝑖 ∫ 𝐶𝑃𝐿,𝑖 𝑑𝑇
𝑖 500
The relevant calling statement is:
L*(X1*CP(1,T)*(T-500) + X2*CP(2,T)*(T-500))
The vapor in feed stream enthalpy is calculated as:
𝑉_𝐹𝐸𝐸𝐷 ∑ 𝑦 _𝐹𝐸𝐸𝐷,𝑖 [∆𝐻𝑉,𝑖 (𝑇)]
𝑖
The relevant calling statement is:
V_Feed*(Y1_Feed*H_vap(1,500)+Y2_Feed*H_vap(2,500))
72
%Script file:adiabatic_flash
%Example 2.15, Adiabatic flash operation
x0 = [ones(1,14),400]
x = fsolve(@ADIABATIC_Ex2_15,x0);
fprintf('\n Exit Temperature = %7.3f \n',x(15))

function f = ADIABATIC_Ex2_15(x)
%Adiabatic Flash Unit
%Isothermal Flash Calculations needed to determine
%Phase Distributions of Feed Stream .
%Combined M&E Balances are carried out to determine
%output temperature
%Feed: 70% n-dodecane, 30% n-hexane.
%Feed stream pressure(P) = 500 kPa. Temperature =
%500 K.
%Feed pressure is reduced to 250 kPa.
%Isthermal flash equation: Z1*(1-K1)/(1+V*(K1-...
1))+Z2*(1-K2)/(1+V*(K2-1))
%Watson Correlation: H_VAP(T) = H_VAP(T0)*(TC-...
T)/(TC-T0))^n
%H_VAP(T) = Latent heat of Vaporization at Temp. T
%TC = Critical Temp., n = 0.38 for most substances
%V_Feed = Flow rate of vapor phase in feed stream
%L_Feed = Flow rate of liquid phase in feed stream
%X1_Feed = Concentration of n-dodecane in Feed ...
Liquid Phase
%Y1_Feed = Concentration of n-hexane in Feed Liquid
%Phase. V = Flow rate of exit vapor phase
%L = Flow rate of exit liquid phase
%X1 = Concentration of n-dodecane in exit Liquid...
Phase
%Y1 = Concentration OF n-hexane in exit vapor Phase
%Hvap_Dod = Latent heat of vaporization of n-...
dodecane
%HVAP_Hex = Latent heat of vaporization of n-Hexane
BP = x(1);DP = x(2); V_Feed = x(3);L_Feed =...
x(4);X1_Feed = x(5); X2_Feed = x(6);
Y1_Feed = x(7); Y2_Feed = x(8); X1 = x(9); X2 =
x(10);Y1 = x(11); Y2 = x(12);V = x(13); L = x(14);

73
T = x(15);
Z1 = 0.7; Z2 = 0.3;Q = 0.0;P_Feed = 500;
P_Flash = 250;
%Determination of Feed Mixture Bubble Pressure:
VP_Dod = exp(14.0587 - 3744.01/(T - 92.8311));
VP_Hex = exp(14.0587 - 2825.42/(T - 42.7089));
f(1) = Z1*VP_Dod/BP + Z2*VP_Hex/BP - 1.0;
%Determination of Feed Mixture Dew Pressure:
f(2) = Z1*DP/VP_Dod + Z2*DP/VP_Hex-1.0;
%Feed Sream Flashing to Examine Existence of Number
%of Phases
%and determine Feed Phases Quatities and
%Concentrations
K1 = VP_Dod/P_Feed; K2 = VP_Hex/P_Feed;
%Isothermal Flash Equation:
f(3)= Z1*(1-K1)/(1.0 + V_Feed*(K1 - 1))+ ...
Z2*(1-K2)/(1.0 + V_Feed*(K2 - … 1));
f(4) = X1_Feed - Z1/(1.0 + V_Feed*K1 + 1.0);
f(5) = X1_Feed + X2_Feed - 1.0;
f(6) = Y1_Feed - K1*X1_Feed;
f(7) = Y1_Feed + Y2_Feed - 1.0;
f(8) = L_Feed + V_Feed -1.0;
%Flash Drum Flashing to Determine Exit Phase Flows
%and Concentrations
P_Flash = 250;
K1 = VP_Dod/P_Flash; K2 = VP_Hex/P_Flash;
f(9)= Z1*(1-K1)/(1.0 + V*(K1 - 1))+ ...
Z2*(1-K2)/(1.0 + V*(K2 - 1));
f(10) = X1 - Z1/(1.0 + V*K1 + 1.0);
f(11) = X1 + X2 - 1.0;
f(12) = Y1 - K1*X1;
f(13) = Y1 + Y2 - 1.0;
f(14) = L + V - 1.0;
%Energy Balance
%Basis: Liquid Phase at 500 K for both components
%Hvap_Dod Estimation:
TC = 660.161;
%TC = Critical Temp. K
T0 = 489.439;

74
%T0 = Normal boiling point K
Hvap_Dod0 = 43685.1;
%Latent heat of vaporization at normal boiling
%point T0
% Watson Correlation:
Hvap_Dod = HVAP_Dod0*((TC-T)/(TC-T0))^0.38;
%Hvap_Hex Estimation:
TC = 507.861;
%TC = Critical Temp. K
T0 = 341.901;
%T0 = Normal boiling point K
Hvap_Hex0 = 28851.3;
%Latent heat of vaporization at normal boiling
%point T0
% Watson Correlation:
HVAP_Hex = HVAP_Hex0*((TC-T)/(TC-T0))^0.38;
H_EXIT_VAPOR = V*(Y1*HVAP_Dod+Y2*HVAP_Hex);
H_Feed_VAPOR =
V_Feed*(Y1_Feed*HVAP_Dod+Y2_Feed*HVAP_Hex);
f(15) = Q - H_EXIT_VAPOR + H_Feed_VAPOR;
end

Result:
Exit Temperature = 448.611
2.11 Ammonia Plant: Case Study 1 ((Material and Energy
Balances)
Ammonia is produced via the reaction:
𝑁2 + 3𝐻2 𝑁𝐻3
using the process flow diagram in Fig. 2.12. The reaction takes place in a two-stage
adiabatic reactor. The conversion in the first reactor is 10%. Calculate the refrigeration
load in the separator per mole of ammonia produced.
Constant average molar heat capacities of gases: 𝑁𝐻3 9.5, 𝑁2 7.0, 𝐻2 7.0
Constant average molar heat capacities of 𝑁𝐻3 liquid 30.0
Heat of vaporization of 𝑁𝐻3 = 5.581 kcal/mol at -33.4 C, the normal boiling point
Degree of freedom of process is shown below:
The program ammonia.m performs material and energy balances for the entire
ammonia process plant shown below.
To run the program ammonia.m, run the following script file (ammonia_run) by
typing the name of the script file (ammonia_run) in the command window.

75
% Script file: ammonia.m
% file.Materal and energy balances for %ammonia
%plant
% Basis 1.0 mole of ammonia produced
global Q
x0 = [1:15,400,400,-20];
[x,fval,exitflag] = fsolve(@ammonia,x0);
fprintf('\n Separator Refrigeration Load ...
= %6.4g kcal/mol\n', Q)

Figure 2.12: Ammonia plant


Table 2.6 Degree of Freedom Table
Number of variables: Process
Stream 18
T,Q 13
Number of Balances:
Material 12
Energy 5
Number of specifications:
Feed Composition 1
Separator outlet temp. 1

76
Q=0 4
Conversion 1
Temperatures:
Reactor inlets 2
R2 outlet 1
Feed 1
Separator outlets 2
Basis 1
Degree of freedom zero

function f = ammonia(x,x0)
global Q
% Input data:
% Heat capacity data:
CPN =7.0*1e-3;CPH=7.0*1e-3;CPA =9.5*1e-3;CPAL...
=30.0*1e-3; %kcal/(mol.C),heat capcities of gases
%and liquid ammonia(CPAL)
% Definition of parameters:
H1 = x(1); N2 = x(2); H2 = x(3); A2 = x(4); N3 =
x(5); H3 = x(6); A3 = x(7); N5 = x(8);
H5 = x(9); H6 = x(10); N8 = x(11); H8 = x(12);
A8 = x(13); r1 = x(14); r2 = x(15); T4 = x(16);
T8 = x(17); Q = x(18);
%Heat of vaporization of ammonia at -33 C
Heat_Vaporizatin = 5.581; % kcal/mol
% Heat of Reaction at 425 C is given in problem = -
%25.640 kcal/mol
Heat_Reaction = -25.640; % kcal/mol
% Mixer Material Balances
f(1) = N2 - (25/75)*H1 - N8; % Nitrogen balance
f(2) = H2 - H1 - H8; % Hydrogen balance
f(3) = A2 - A8; % Ammonia balance
% Reactrer_2 Material Balances
f(4) = N3 - N2 + r2;
f(5) = H3 - H2 + 3*r2;
f(6) = A3 - A2 - 2*r2;
% Separater Material Balances
f(7) = N5 - N3 + (25/75)*H6;
f(8) = H5 - H3 + H6;

77
f(9) = A3 - 1.0; % Basis of calculations is 1.0
%mole of ammonia produced.
% Reacter_1 Material Balances
f(10) = N8 - (25/75)*H6 + r1;
f(11) = H8 - H6 + 3*r1;
f(12) = A8 - 2*r1;
% Mixer Energy Balance (Tref = 425 C)
f(13) = ((25/75)*H1*CPN + H1*CPH)*(50 - 425) +...
(N8*CPN + H8*CPH + A8*CPA)*(T8 - 425);
% Reacter_2 Energy Balance (Tref = 425 C)
f(14) = r2*Heat_Reaction + (N3*CPN + H3*CPH +...
A3*CPA)*(535 - 425);
% Separater Energy Balance:
% Temperature reference conditions:
% Hydrogen and nitrogen gases at -50 C.
% Ammonia Liquid at -50 C. Q is condenser
%refrigeration load.
f(15) = Q - ((25/75)*H6*CPN + H6*CPH)*(425 ...
- (-50)) + (N3*CPN + H3*CPH)*(535 - (-50))...
+ A3*(CPA*(535 - (-33.4)) + Heat_Vaporizatin...
+ CPAL*((-33.4) - (-50)));
% Heat Exchanger Energy Balance (Tref = 535 C)
f(16) = (N3*CPN + H3*CPH + A3*CPA)*(T4 -...
535)+((25/75)*H6*CPN + H6*CPH)*(425 - 535)...
-((25/75)*H6*CPN + H6*CPH)*(425 - 535);
% Reacter_1 Energy Balance (Tref = 425 C)
f(17) = r1*Heat_Reaction + (N8*CPN + H8*CPH +...
A8*CPA)*(T8 - 425);
% Conversion relation
f(18) = H6 - H8 - 0.1*H6;
Result:
Separator Refrigeration Load = -18.03 kcal/mol
2.12 Ammonia Plant: Case Study 2 (Sensitivity Analysis)
The program ammonia_s.m performs sensitivity analysis for the effect of inlet
temperature on separator refrigeration load. To run the program ammonia_s.m, run
the following script file (ammonia_run_s) by typing ‘ammonia_run_s’ in the command
window.
% script file ammonia_run_s.m to run function
%ammonia_s.m

78
global TEMP Q
x0 = [1:15,400,400,-20];
for k=1:10
TEMP = 30 + 20*k;
[x,fval,exitflag] = fsolve(@ammonia_s,x0);
%fprintf('\n Separater Refrigeration Load ...
= %6.4g kcal/mol\n',Q)
result(k,1) = TEMP;
result(k,2) = Q;
end
plot(result(:,1),result(:,2))
xlabel('Feed Temperature, C')
ylabel('Refrigeration Load, kcal/mole')
title('Ammonia Plant: Q versus T')

% function :ammonia_s.m ..... Sensitivity Analysis;


% Ammonia problem no. 8.12 page 512 in Rekalitis
% Refrigeration load vusus Inlet temperature
% Basis 1.0 mole of ammonia produced
function f = ammonia_s(x,x0)
global TEMP Q
% Input data:
% Heat capacity data:
CPN = 7.0*1e-3;CPH =7.0*1e-3;CPA =9.5*1e-3;
CPAL =30.0*1e-3;%kcal/(mol.C),heat capcities of
%gases and liquid ammonia(CPAL)
% Definition of unknown variables:
H1 = x(1); N2 = x(2); H2 = x(3); A2 = x(4);
N3 = x(5); H3 = x(6); A3 = x(7); N5 = x(8);
H5 = x(9); H6 = x(10); N8 = x(11); H8 = x(12);
A8 = x(13); r1 = x(14); r2 = x(15); T4 = x(16);
T8 = x(17); Q = x(18);
%Heat of vaporization of ammonia at -33 C
Heat_Vaporizatin = 5.581; % kcal/mol
% Heat of Reaction at 425 C is given in problem as =
%-25.640 kcal/mol
Heat_Reaction = -25.640; % kcal/mol
% Mixer Material Balances
f(1) = N2 - (25/75)*H1 - N8; % Nitrogen balance

79
f(2) = H2 - H1 - H8; % Hydrogen balance
f(3) = A2 - A8; % Ammonia balance
% Reactrer_2 Material Balances
f(4) = N3 - N2 + r2;
f(5) = H3 - H2 + 3*r2;
f(6) = A3 - A2 - 2*r2;
% Separater Material Balances
f(7) = N5 - N3 + (25/75)*H6;
f(8) = H5 - H3 + H6;
f(9) = A3 - 1.0; % Basis of calculations is 1.0
%mole of ammonia produced.
% Reacter_1 Material Balances
f(10) = N8 - (25/75)*H6 + r1;
f(11) = H8 - H6 + 3*r1;
f(12) = A8 - 2*r1;
% Mixer Energy Balance (Tref = 425 C)
f(13) = ((25/75)*H1*CPN + H1*CPH)*(TEMP - 425)...
+ (N8*CPN + H8*CPH + A8*CPA)*(T8 - 425);
% Reacter_2 Energy Balance (Tref = 425 C)
f(14) = r2*Heat_Reaction + (N3*CPN + H3*CPH +...
A3*CPA)*(535 - 425);
% Separater Energy Balance:
% Temperature reference conditions: Hydrogen and
%nitrogen gases at -50 C.
% Ammonia Liquid at -50 C. Q is condenser
%refrigeration load.
f(15) = Q - ((25/75)*H6*CPN + H6*CPH)*(425 –...
(-50)) + (N3*CPN + H3*CPH)*(535 - (-50))...
+ A3*(CPA*(535 - (-33.4)) + Heat_Vaporizatin +...
CPAL*((-33.4) - (-50)));
% Heat Exchanger Energy Balance (Tref = 535 C)
f(16) = (N3*CPN + H3*CPH + A3*CPA)*(T4 -...
535)+((25/75)*H6*CPN + H6*CPH)*(425 - 535)...
-((25/75)*H6*CPN + H6*CPH)*(425 - 535);
% Reacter_1 Energy Balance (Tref = 425 C)
f(17) = r1*Heat_Reaction + (N8*CPN + H8*CPH +...
A8*CPA)*(T8 - 425);
% Conversion relation
f(18) = H6 - H8 - 0.1*H6;

80
Results: 50.0000 -18.0272
70.0000 -18.3962
90.0000 -18.8035
110.0000 -19.2556
130.0000 -19.7600
150.0000 -20.3265
170.0000 -20.9673
190.0000 -21.6981
210.0000 -22.5391
230.0000 -23.5176
Ammonia Plant: Q versus T
-18

-19
Refrigeration Load, kcal/mole

-20

-21

-22

-23

-24
40 60 80 100 120 140 160 180 200 220 240
Feed Temperature, C

Figure 2.13 Sensitivity study for Ammonia Plant

2.13 Synthesis Gas Plant: Case Study 3


A synthesis gas containing 𝐶𝑂, 𝐻2 , and a small amount of 𝐶𝐻4 , with a 𝐶𝑂 − 𝐻2 molar
ratio of 1:2.9, is to be upgraded to a higher methane content via:
CO + 3H2 CH4 + H2O
using the recycle system shown in Fig. 1.14 below. The reactor must be operated
adiabatically with a maximum outlet temperature of 1000 F to produce a product
stream containing 50% CH4and 12% CO. The heat removal rate in heat exchanger 1
is adjusted to cool the reactor effluent stream to 500 F. The separator is operated so
as to result in a recycle stream containing 1% H2O and a pure liquid water stream,
both at 100 F. Except for stream 8, all streams are gas phase. Assuming that the entire
system operates at a constant pressure of 100 psia, calculate all flows and temperatures
for a production of 100 lbmol/h. Heat of reaction at 77 F = -88.685 X 103Btu/lbmol
Relative enthalpy of stream 8 (liquid water at 100 F) = 413.29 Btu/lbmol
Use MATLAB function for the (integral) integration of the heat capacity polynomial:
81
CP = 0.956 +(5.91124e-05)*T -(5.0758e-07)*T2
i.e. CP = 6.956 +(5.91124e-05)*x -(5.0758e-07)*x.^2
between Tref and 500 is:
integral(@(x) 6.956 +(5.91124e-05)*x -(5.0758e-07)*x.^2,Tref,500)

Figure 2.14: Synthesis Gas Plant


Solution: Basis = 100 lbmoles of methane production

Table 2.7 Degree of Freedom Table

82
Table 2.8 Table of variables

Number of independent equations:


Material Balances = 16
Energy Balances = 6
CO:H2 Relation = 1
Splitter Restrictions:

83
Compositions = 3
Temperatures = 1
------
Total = 27
% script file syngas11_run.m to run function
syngas.m
% example 9.13 page 602 Reklaitis
x0 = diag(ones(27))*300;x0(26) =-6.5e+06;
x0(27) = -2.1e+06;
options = optimset('TolX',1e-10);
[x,fval,exitflag] = fsolve(@syngas11,x0,options);
fprintf(' Q1 = %4.2e\n',x(26))
fprintf(' Q2 = %4.2e\n',x(27))
fprintf(' r = %4.2f\n',x(21))
fprintf(' T2 = %4.2f\n',x(22))

function f = syngas11(x)
% example 9.13 Reklaitis page 602
% CO = C,H2 = H, CH4, M, H2O = W
C1 = x(1);H1 = x(2);M1 = x(3); C2 = x(4);
H2 = x(5);M2 = x(6);W2 = x(7);
C3 = x(8);H3 = x(9);M3 = x(10); W3 = x(11);
H6 = x(12);C7 = x(13); H7 = x(14);
M7 = x(15);W7 = x(16);W8 = x(17);C9 = x(18);
H9 = x(19);M9 = x(20);r = x(21);
T2 = x(22);T5 = x(23);T7 = x(24); T10 = x(25);
Q1 = x(26); Q2 = x(27);
Heat_Reaction = -88.685e+03;
% Heat_Reaction is given at 77 F in Btu/lbmol
% Relative enthalpy of stream 9 (basis sat liquid
%water at 100 F) = 1036.4*18 Btu/lbmol
% Enthalpies of components with heat capacities as
%functions of temperature:
ENTH_C = @(x) 6.956e+00 + (5.91124e-05).*x ...
+ (5.0758e-07)*x.^2 + (7.64118e-10)*x.^3 -...
(6.54036e-13)*x.^4;
ENTH_H = @(x) 6.64782e+00 + (2.47265e-03).*x -...
(4.55763e-06)*x.^2 + (3.11770e-09)*x.^3 –...
(6.64368e-13)*x.^4;

84
ENTH_M = @(x) 8.24522e+00 + (3.8033e-03).*x +...
(8.86474e-06)*x.^2 - (7.46115e-09)*x.^3 +...
(1.82296e-12)*x.^4;
ENTH_W = @(x) 7.98574e+00 + (4.63319e-04).*x ...
+ (1.40284e-06)*x.^2 - (6.57839e-10)*x.^3 +...
(9.79529e-14)*x.^4;
% Ehtnapies of streams 2 and 10 with Tref = 200 F
Tref = 200;
ENTH_2_200 = C2*integral(ENTH_C,Tref,T2)+...
H2*integral(ENTH_H,Tref,T2)...
+ M2*integral(ENTH_M,Tref,T2) +...
W2*integral(ENTH_W,Tref,T2);
ENTH_10_200 = C9*integral(ENTH_C,Tref,T10)+
H9*integral(ENTH_H,Tref,T10)...
+ M9*integral(ENTH_M,Tref,T10) +...
(1/99)*(C9+H9+M9)*integral(ENTH_W,Tref,T10);
% Ehtnapies of streams 2 and 3 with Tref = 77 F
Tref = 77;
ENTH_2_77 = C2*integral(ENTH_C,Tref,T2)+...
H2*integral(ENTH_H,Tref,T2)...
+ M2*integral(ENTH_M,Tref,T2) +...
W2*integral(ENTH_W,Tref,T2);
ENTH_3_77 = C3*integral(ENTH_C,Tref,1000)+...
H3*integral(ENTH_H,Tref,1000)...
+ M3*integral(ENTH_M,Tref,1000) +...
W3*integral(ENTH_W,Tref,1000);
% Ehtnapies of streams 3 with Tref = 500 F
Tref = 500;
ENTH_3_500 = C3*integral(ENTH_C,Tref,1000)+...
H3*integral(ENTH_H,Tref,1000)...
+ M3*integral(ENTH_M,Tref,1000) +...
W3*integral(ENTH_W,Tref,1000);
%Ehtnapies of streams 4, 10, and 5 with Tref = 100 F
Tref = 100;
Enth_4_100 = C3*integral(ENTH_C,Tref,500)+...
H3*integral(ENTH_H,Tref,500)...
+ M3*integral(ENTH_M,Tref,500) +...
W3*integral(ENTH_W,Tref,500);

85
ENTH_10_100 = C9*integral(ENTH_C,Tref,T10)+...
H9*integral(ENTH_H,Tref,T10)...
+ M9*integral(ENTH_M,Tref,T10) +...
(1/99)*(C9+H9+M9)*integral(ENTH_W,Tref,T10);
ENTH_5_100 = C3*integral(ENTH_C,Tref,T5)+...
H3*integral(ENTH_H,Tref,T5)...
+ M3*integral(ENTH_M,Tref,T5) +...
W3*integral(ENTH_W,Tref,T5);
% Ehtnapies of streams 5 an 7 with Tref = 200 F
Tref = 200;
ENTH_5_200 = C3*integral(ENTH_C,Tref,T5)+...
H3*integral(ENTH_H,Tref,T5)...
+ M3*integral(ENTH_M,Tref,T5) +...
W3*integral(ENTH_W,Tref,T5);
ENTH_7_Tref = C7*integral(ENTH_C,Tref,T7)+...
H7*integral(ENTH_H,Tref,T7)...
+ M7*integral(ENTH_M,Tref,T7) +...
W7*integral(ENTH_W,Tref,T7);
% Ehtnapies of streams 7,with Tref = 200 F
Tref = 200;
ENTH_7_200 = C7*integral(ENTH_C,Tref,T7)+...
H7*integral(ENTH_H,Tref,T7)...
+ M7*integral(ENTH_M,Tref,T7) +...
W7*integral(ENTH_W,Tref,T7);
% Ehtnapies of streams 7, 8, and 9 with Tref = 100 F
Tref = 100 ;
ENTH_7_100 = C7*integral(ENTH_C,Tref,T7)+...
H7*integral(ENTH_H,Tref,T7)...
+ M7*integral(ENTH_M,Tref,T7) +...
W7*integral(ENTH_W,Tref,T7);
ENTH_8 = W8*67.97*18; % Enthalpy of liquid water at
%standard conditions of 32 F is taken as reference.
ENTH_9_100 = (1/99)*(C9+H9+M9)*(67.97+1036.4)*18;
%Enthalpies of C02,H2, and CH4 = 0.0
% 1036.4*18 is the latent heat of vaporization of
%water at 100 F in Btu/lbmol
stream_5 = C3 + H3 + M3 + W3;
stream_7 = C7 + H7 + M7 + W7;
% Mixer Material Balances

86
f(1)= C2 - C1 - C9; % CO balance
f(2)= H2 - H1 - H9; % Hydrogen balance
f(3)= M2 - M1 - M9; % Methane balance
f(4)= W2 - (1/99)*(C9+H9+M9); % Water balance
% Reactrer Material Balances
f(5)= C3 - C2 + r;
f(6)= H3 - H2 + 3*r;
f(7)= M3 - M2 - r;
f(8)= W3 - W2 - r;
% Splitter Material Balances
f(9)=(12/50)*100 + C7 - C3; % CO balance
f(10)= H6 + H7 - H3; % Hydrogen balance
f(11)= 100 + M7 - M3; % Methane balance ;
Basis 100 lbmoles of product
W6 = 200 - 124 - H6;
%200 - 124 is quantity of (H6 + water in stream 6)
f(12)= W6 + W7 - W3; % Water balance
% Separator Material Balances
f(13)= C9 - C7; % CO balance
f(14)= H9 - H7; % Hydrogen balance
f(15)= M9 - M7; % Methane balance
f(16)= W8 + (1/99)*(C9 + H9 + M9) - W7;
% f(16) is the Water balance
% Mixer energy balance
f(17)= ENTH_2_200 - ENTH_10_200;
% Reactor energy balance
f(18)= r*Heat_Reaction + ENTH_3_77 - ENTH_2_77 ;
% Heat exchanger 1 energy balance
f(19)= Q1 + ENTH_3_500;
% Heat exchanger 2 energy balance
f(20)= ENTH_5_100 + ENTH_10_100 - Enth_4_100;
% Splitter energy balance
f(21)= ENTH_5_200 - ENTH_7_200;
% Separtor energy balance
% Reference conditions water at standard conditions
%of O C (32 F). In this case enthapy of water in
%stream 8 = 67.97 Btu/lb (67.97*18
% Btu/lbmol and enthapy of saturated steam in stream
%9 = 1104.4*18 Btu/lbmol.

87
f(22)= Q2 - ENTH_8 + ENTH_7_100 - ENTH_9_100;
% splitter relations
f(23)= C3/stream_5 - C7/stream_7;
f(24)= H3/stream_5 - H7/stream_7;
f(25)= W3/stream_5 - W7/stream_7;
f(26)= T5 - T7;
% CO to H2 relation in feed stream
f(27)= 2.9*C1 - H1;

Solution:
Q1 = -6.57e+06, Q2 = -5.73e+05
r = 81.83
T2 = 416.47

Exercises
In each case, the student is encouraged to solve the relevant problem using:
Manual calculations up to 5 successive iterations
(b)User-defined function accurate to 10-7.
(c)MATLAB built-in function.

2.1Consider the following two simultaneous algebraic equations:


𝑥13 − 3 𝑥1 𝑥22 = 0
𝑥12 − 4 𝑥12 𝑥2 = 0
From an initial guess 𝑥0 = [2 1], write a MATLAB code to solve the problem using:
(a)user-defined code
(b)built-in code

2.2 Solve each of the following problems using, Newton’s method:


(a)x4 - 10x3
(b)2x2 + ln(x) = 4
(c)ln(x) + 30e-x = 10

88
2.3 Solve each of the following problems using the secant method to an accuracy
within 10-5 in the interval [-5 +5]:
(a)x5 - 10x3 = 4
(b)2x2 + ln(x) = 3
(c)ln(x) + 30e-x = 3

2.4 Solve the following problem using Newton’s method:


4𝑥 3 + 𝑦 = 6
𝑥2𝑦 = 3
You may start with an initial guess of x0 = y0 =1.

2.5 Solve the following problem using Newton’s method:


𝑥2 + 𝑦2 = 3
2𝑥 2 + 𝑦 = 6
You may start with an initial guess of x0 = y0 = 0.5

2.6 Solve part (b) in example 2.6

2.7 Sulphur dioxide is converted to sulphur trioxide by oxidation over vanadium


pentoxide at atmospheric pressure. In the reactor configuration shown in Fig. 2.15
below sulphur dioxide and oxygen are fed in stoichiometric ratio to the reactor.
Conversion is 96%. The reactor is cooled by removing 10 kcal/mole of combined
feed. The last heat exchanger is used to generate 300steam by cooling the reactor
effluent to 400 C.
Assume following thermodynamic data:
Cp (𝑂2 , S𝑂2 , 𝑆𝑂3 ) = (7.5, 11, 16) cal/mole. C
Standard heat of reaction = -24 kcal/mole.
Latent heat of vaporization of water at 300 psia = 1888 kJ/kg.
1.0 cal = 4.18 J
(a) Carry out a degree of freedom analysis and show that the problem is correctly
specified.
(b) Use MATLAB to develop a computer code for plotting the effect of inlet
temperature (from 200OC to 400OC) on the production of SO3.

89
Figure 2.15: Sulphur tri oxide plant
2.8 Solve problem 5 with the heat capacities expressed as functions of temperature.
(See Appendix for complete solution)

2.9 A catalytic reactor is charged with a feed consisting of 5 mol H2 to 1 mol CO2 at
400 OC. In the reactor, the reactions:
CO(g) + 3H2 CH4(g) + H2O(g)
CO2(g) + H2 CO(g) + H2O(g)
take place with 90% conversion of CO2 . At present, 20 kJ of heat are removed from
the reactor per mole of feed. The reactor is operated isothermally at 400OC.
Is the problem correctly specified ?
Write a MATLAB code to plot the variation of the exit temperature as the heat
removal rate is changed (at 5 kJ intervals) from 20 to 50 kJ per mole of feed.
Gas heat capacities: Cp = a + b*T + c*T2 in SI units (J,K)

Table 2.8: Thermodynamic Data:


a b c Standard
ΔHf, kJ/mol
CO 6.9D+00 5.9D-05 5.07D-07 -110.4
H2 6.6D+00 2.47D-03 -4.6D-06 -
CH4 8.2D+00 3.8D-03 8.8D-06 -74.89
H2O 3.4D+01 -9.7D-03 3.3D-05 -241.8
CO2 8.4D+00 6.5D-03 -3.6D-06 -393.1

2.10 A synthesis gas is upgraded to a higher methane content in the recycle system
shown in Fig. 2.16 below. The fresh feed gas composition (in mole %) is CO (22),

90
CO2 (13), H2 (65), plus a small amount of CH4. Both fresh feed and final product
temperatures are 93OC. In the reactor the following reactions take place:
CH4 + CO2 ⇌ 2CO + 2H2
CO2 + H2 ⇌ CO + H2O
CH4 + H2O ⇌ CO + 3H2
CH4 + 2H2O ⇌ CO2 + 4H2
Ninety five percent of water in stream 7 is separated as liquid in stream 8. Assume that
the mixer, the splitter, exchanger 2, and the reactor are operated adiabatically.
(a)Show that the system correctly specified.
(b)Develop a MATLAB program to calculate the reactor outlet temperature.
Thermodynamic data:
CP(g), J/mol.K CP(l), J/mol.K
CO 29.0 -
H2 17.6 -
CH4 38.3 -
CO2 19.0 -
H2O 34.0 18.0
Latent heat of vaporization of water = 40656 J/mol. Standard heat of formation (in
kcal/mol):
C0 (-26.4), CH4 (-18 ), CO2 (-94 ), H2O (-58 ).
1.0 Cal = 4.18 J

Figure 2.16: Synthesis gas plant


2.11 ( Material and energy balances around isothermal flash vaporization unit)

91
A one mole two phase mixture consists of benzene and toluene with molar
concentrations of 50% for each of them in the gas phase. If the total pressure is 500
mmHg, calculate:
(a)The mixture temperature.
(b)The molar concentrations in the liquid phase.

2.12 An equimolar feed of benzene and toluene at 105 C and 1000 mmHg is flashed
adiabatically at 500 mmHg. Determine the outlet phase flows, assuming Raoult’s law
is applicable.

2.13 A flash evaporator must separate ethylene and ethane from a feed stream which
also contains propane and n-butane. Fig. 2.17 depicts a diagram of the evaporator.

Figure 2.17: Flash evaporator

F = total feed flow rate in lb-mol/hr


V = total vapor flow rate in lb-mol/hr
L = total liquid flow rate in lb-mol/hr
𝑍𝑗 = mole fraction of component j in the feed stream
𝑦𝑗 = mole fraction of component j in the vapor phase
𝑥𝑗 = mole fraction of component j in the liquid phase
𝑛𝑐 = total number of components
The feed composition entering the evaporator is given in the table below together with
Antoine constants [4], where pressure is in units of mmHg. The evaporator will
operate under high pressure, between 15 and 25 atm, with a feed stream at 50 C.

Component Mole Fraction A B C


Ethylene 0.1 6.64380 395.74 266.681

92
Ethane 0.25 6.82915 663.72 256.681
Propane 0.5 6.80338 804.00 247.04
n-butane 0.15 6.80776 935.77 238.789

(a) Determine the dew and bubble temperatures of the feed stream.
(b) Calculate the percent of the total feed at 50 C that is evaporated and the
corresponding mole fractions in the liquid and vapor streams for the following
pressures P = 15, 17,19, 21,23,and 25 atm.
Solution:
69.67% of the feed has been evaporated at a pressure of 20 atm.
The corresponding mole fractions in the vapor and liquid streams are shown below:

Table 2.9: Vapor and liquid streams data


Component Mole Ethylene Ethane Propane n-Butane
Fractions
Feed 0.1 0.25 0.5 0.15
Vapor 0.1398 0.3139 0.4692 0.07713
Liquid 0.008574 0.1032 0.5708 0.3174

2.13 The following sketch represents the steps of producing Methyl iodide CH3 I
according to the following reaction:

HI + CH3 OH  CH3 I + H2 O

1- The reactor feed stream contains 2 moles of CH3 OH for every 1 mole of HI.
2- The chemical conversion of HI in the reactor is 50%.
3- The amount of water in stream (5) is 90% of the water in stream (4).
4- All the concentrations in the sketch are on mole basis.
Calculate the produced amount of CH3 I for every 1 mole of HI in the feed stream (1).

93
Figure 2.18: Methyl iodide process

2.14 Fig. 2.19 represents flow sheet to produce 10 tons of 20% Oleum* and 40 tons of
sulphuric acid (98% concentration). Calculate the amount of the acid fed to each
column per day.

*
Oleum is a solution of sulphur trioxide in sulphuric acid.

94
Figure 2.19: Sulfuric acid plant

2.15 The flow diagram (Fig. 2.20) below represents the steps of ammonia production
using three adiabatic reactors according to the reaction [1]:
N2 + 3H2 ⇌ 2NH3
The molar flow rate ratio of streams (7) and (8) are 0.2:1.0
Calculate the temperature in stream (2).

Figure 2.20: Ammonia plant

95
96
CHAPTER

3
3.1 Cramer’s Rule
Linear Algebraic Equations

If Ax = C, the solution according to Cramer's rule is:


|𝐴𝑗 |
𝑥𝑗 = 𝑗 = 1, 2, … , 𝑛
|𝐴 |
Where |A| and |Aj| are the determinants of matrices A and Aj respectively.
|𝐴𝑗 | is the substituted matrix obtained by replacing column j of matrix A with the
constant vector C.
3.1.1 Cramer’s Rule using MATLAB Command Window
Example 3.1
Solve the following system using Cramer’s rule:
2𝑥1 + 3𝑥2 + 𝑥3 –𝑥4 = 2
3𝑥1 + 2𝑥2 + 5𝑥3 + 3𝑥4 = 5
−𝑥1 + 3𝑥3 + 𝑥4 = 1
𝑥1 -2𝑥2 + 𝑥3 = −2
Solution:
A = [2 3 1 -1; 3 2 5 3;-1 0 3 1; 1 -2 1 0];
b = [2; 5; 1; -2];
A1 = [b A(:,[2:4])];
x(1) = det(A1)/det(A);
97
A2 = [A(:,1) b A(:,[3:4])];
x(2) = det(A2)/det(A);
A3 = [A(:,[1:2]) b A(:,4)];
x(3) = det(A3)/det(A);
A4 = [A(:,[1:3]) b];
x(4) = det(A4)/det(A);
Results:
x = -0.0000 1.0000 0.0000 1.0000
3.1.2 MATLAB using Uof K Application (University of Khartoum
Application)
This method is a MATLAB application of Cramer’s method.

Example 3.2
Using UofK MATLAB application, solve the system of algebraic equations:
Ax = b where: A = [4 1 -3; 3 2 -6; 1 -5 3], b = [9 -2 1]’
Solution:
%script file: uofk application based on Cramer's
rule
A = input('enter coefficient matrix = ');
b = input('enter constants matrix = ');
n = length(b);
[nr nb] = size(A);
%check coefficient matrix and vector of constants:
if nr ~= nb
error ('coefficient matrix is not square')
end
if nr ~= n
error ('coefficient matrix and vector of
constants do not have same length')
end
%check if coefficient matrix is singular
if det(A) == 0
fprintf('\n Rank = %7.3g\n',rank(A))
error('The coefficient matrix is singular')
end
for k= 1:length(b)
C = A;
C(:,k) = b;
x(k) = det(C)/det(A);
fprintf('x(%d) = %7.4f\n',k,x(k))
98
end
Type the following commands in the command window:
>>uofk
enter coefficient matrix = [4 1 -3; 3 2 -6; 1 -5 3]
enter constants matrix = [9 -2 1]'
Solution:
x(1) = 4.0000
x(2) = 2.5000
x(3) = 3.1667
Example 3.3 (Simple separation system)
A separation system balances result in the following set of linear equations:
𝑥1 + 𝑥2 + 𝑥3 = 10
0.04𝑥1 + 0.54𝑥2 + 0.26𝑥3 = 2
0.93𝑥1 + 0.24𝑥2 = 6
Calculate the values of the flow rates 𝑥1 , 𝑥2 , and 𝑥3 . Note that the coefficients in the
above sytem of equations are not percentage concentrations and can be any physical
property expressed as units of that property per unit mass or volume of flow.
Solution:
% sep_system_example.m
% This MATLAB program solves a linear system to
compute the mass %flowrates in a simple separation
%system.
% K. Beers. MIT
function iflag_main = sep_system_example()
iflag_main = 0;
% set matrix of coefficients
A = zeros(3,3);
A(1,:) = [ 1 1 1];
A(2,:) = [0.04 0.54 0.26];
A(3,:) = [0.93 0.24 0];
% set right hand side vector
b = [10; 2; 6];
% solve for unknown and display results
x = A\b;
disp(' '); disp('solution x = '); disp(x');
iflag_main = 1;
return;
Solution x = 5.8238 2.4330 1.7433
ans = 1
3.2 Gauss Elimination Methods

99
Carl Friedrich Gauss was a remarkable mathematician and contributed to many other
fields as well, including physics, astronomy, and electricity.
There are three main Gauss elimination methods[16]:
1. The simple Gauss elimination method
2. The Gauss elimination method with partial pivoting
3. The Gauss elimination method with total pivoting
The Gauss elimination method, in its different forms, is the most widely used method
for solving a set of linear algebraic equations. It converts the set of (n) equations in (n)
unknown to an equivalent triangular set.
Elementary operations on the linear system of equations:
1.Any equation in the set can be multiplied (or divided) by a nonzero scalar.
2.Any equation in the set can be added (or subtracted from) another equation.
3.Any 2 equations can be interchanged.
3.2.1 Simple Gauss Elimination Method
Example 3.4 (Simple Gauss Elimination Method)
Solve the following linear system using simple Gauss elimination:
3𝑥1 + 18𝑥2 + 9𝑥3 = 18
2𝑥1 + 3𝑥2 + 3𝑥3 = 117
4𝑥1 + 𝑥2 + 2𝑥3 = 283
The matrix composed of the coefficients of the equations is called the matrix of
coefficients (A):
3 18 9
A =  2 3 3
 
4 1 2
The column vector composed of the constants is the array of constants:
 18 
117 
 
283
First form the augmented matrix of coefficients and constants:
3 18 9 18 
2 3 3 105 
 
4 1 2 283
Let Ri refer to row number i, then carry out the following matrix operations:
3 18 9 18 
Step (1): R2-(R1/3)*2 0  9  3 105 
 
4 1 2 283

3 18 9 18 
0  9  3 105 
 100 
0  23  10 259 
Step (2): R3-(R1/3)*4

3 18 9 18 
0  9  3 105 
Step (3): R3-(R2/-9)*23 
0 0  7 / 3  28 / 3

The triangulation of the coefficient part of the augmented matrix is now complete and
the last matrix represents the triangular set of equations:
3𝑥1 + 18𝑥2 + 9𝑥3 = 18
−9𝑥2 − 3𝑥3 = 105
(−7/3)𝑥3 = − 28/3
The solution is obtained by back substitution, therefore 𝑥3 = 4. Substituting in
equation (2), 𝑥2 = -13. Substituting in equation (1), 𝑥1 = 72. Therefore, we have in
effect forward elimination and back substitution.
General MATLAB m.file for the simple Gauss elimination method [3]:
function x = WP(AUG) %AUG is the augmented matrix
[n,t] = size(AUG); U=AUG;
for k = 1:n-1;
for I =k:n-1;
m=U(i+1,k)/U(k,k);
for j = 1,t;
U(i+1,j) = U(i+1,j) – m*U(k,j);
end
end
end
i= n;
x(i,1) = U(i,t)/U(i,i);
for i = n-1: -1: 1;
s = 0;
for k = n: -1: i+1;
s = s + U(I,k)*x(k,1);
end
x(I,1) = (U(I,t)- s)/U(I,i);
end;
A;U;x;
end
The procedure for applying the above program is for a 3x3 matrix is as follows:

101
>>AUG = [1 2 03;-1 0 -2 -5; -3 -5 1 -4];
>>sol = WP(AUG);
>>disp(sol)
Where AUG is the augmented matrix for the following system of equations:
𝑥1 + 2𝑥2 = 3
−𝑥1 − 2𝑥3 = −5
−3𝑥1 −5𝑥2 + 𝑥3 = −4
The simple Gauss elimination method outlined above does not work if any diagonal
coefficient is zero (or becomes zero in the process of solution). For this reason two
pivoting strategies (partial and total pivoting) are used to change the sequential order
of the equations for two purposes:
1. To prevent diagonal coefficients from becoming zero.
2. To make each diagonal coefficient larger than any other coefficient below it in
order to decrease round off error.
3.2.2 Gauss Elimination Method Using Partial Pivoting
The basic idea of this technique is to use the largest (in absolute value) element on or
below the diagonal in the column of current interest as the pivotal element for
elimination in the rest of the column.
Example 3.5 (Gauss Elimination Method Using Partial Pivoting)
2𝑥1 + 2𝑥2 − 2𝑥3 = 8
−4𝑥1 − 2𝑥2 + 2𝑥3 = −14
−2𝑥1 + 3𝑥2 + 9𝑥3 = 9
First elimination step:
Since -4 is the largest absolute coefficient of first variable 𝑥1 , interchange the first and
second rows to give:
−4𝑥1 − 2𝑥2 + 2𝑥3 = −14
2𝑥1 + 2𝑥2 − 2𝑥3 = 8
−2𝑥1 + 3𝑥2 + 9𝑥3 = 9
Eliminate first variable 𝑥1 from the second and third rows by subtracting the multiple
m_21 = -2/4 of row 1:(-2/4)*(−4𝑥1 − 2𝑥2 + 2𝑥3 = −14) from row 2, and the
multiple m_31 = 2/4 of row 1:(2/4)*(−4𝑥1 -2𝑥2 + 2𝑥3 = −14) from row3 to obtain:
−4𝑥1 − 2𝑥2 + 2𝑥3 = −14
𝑥2 − 𝑥3 = 1
4𝑥2 + 8𝑥3 = 16
Second elimination step:
The coefficient 4 is the largest absolute coefficient of second variable 𝑥2 , therefore
interchange second and third rows:
−4𝑥1 − 2𝑥2 + 2𝑥3 = −14
4𝑥2 + 8𝑥3 = 16
𝑥2 − 𝑥3 = 1

102
Eliminate second variable 𝑥2 from the third row by subtracting the multiple m_32 = ¼
of row 2: (1/4)*( 4𝑥2 + 8𝑥3 = 16)from row 3 to obtain the following result:
−4𝑥1 − 2𝑥2 + 2𝑥3 = −14
4𝑥2 + 8𝑥3 = 16
−3𝑥3 = −3
Now use backward substitution to obtain the solution x = [3, 2, 1]"
A General MATLAB program for partial pivoting has been prepared by Butt and
Benhadid [5].
3.2.3 Gauss Elimination Method Using Total Pivoting
In this method, we search for the largest number (in absolute value) in the entire array
and this number is used as the pivot. This means that we shall interchange the
columns as well as the rows. Each row interchange is equivalent to interchanging two
equations while each column interchange is equivalent to interchanging the two
unknowns.

Example 3.6 (Gauss Elimination Method Using Total Pivoting)


Solve the following system using Gauss elimination with total pivoting:
2𝑥1 + 2𝑥2 − 2𝑥3 = 8
4𝑥1 − 2𝑥2 + 2𝑥3 = −14
−2𝑥1 + 3𝑥2 + 9𝑥3 = 9
First elimination step:
Since coefficient 9 is the largest coefficient, therefore the first row and the third rows
are interchanged, as well as the first column and third column, giving us:
9𝑥3 + 3𝑥2 − 2𝑥1 = 9
2𝑥3 − 2𝑥2 − 4𝑥1 = −14
– 2𝑥3 + 2𝑥2 + 2𝑥1 = 8
Eliminate 𝑥3 from the second and third rows by subtracting the multiples m_21 and
m_31 of row 1 from rows 2 and 3 respectively, gives:
9𝑥3 + 3𝑥2 − 2𝑥1 = 9
− (8/3)𝑥2 − (32/9)𝑥1 = −16
(8/3)𝑥2 + (14/9)𝑥1 = 10
Second elimination step:
(-32/9) is the largest absolute coefficient in the remaining system, so the second and
third columns are interchanged:
9𝑥3 − 2𝑥1 + 3𝑥2 = 9
−(32/9)𝑥1 − (8/3)𝑥2 = −16
(14/9)𝑥1 + (8/3)𝑥2 = 10
Eliminate 𝑥1 from the third row by subtracting the multiple m_32 = (14/9)/(-32/9) = -
7/16 of row two from row 3:
9𝑥2 − 2𝑥1 + 3𝑥2 = 9
−(32/9)𝑥1 − (8/3)𝑥2 = −16

103
(8/3)𝑥2 = 3
Back substitution gives the results x = [3,2,1]’. A General MATLAB program for
total pivoting has been prepared by Butt and Benhadid [5].
3.3 Built_in MATLAB Function
We can write the system of linear equations in matrix form: Ax = B
Where A is the coefficient matrix and B is the constants column vector supplied as a
column vector [16].
The solution is:
x = A\B
Or x = inv(A)*B
In general, using the matrix inverse, inv(A), to solve linear systems can result in
excessive round-off errors and should be avoided
Example 3.7 (Built_in MATLAB Function)
3𝑥 + 2𝑦 − 𝑧 = 10
−𝑥 + 3𝑦 + 2𝑧 = 5
𝑥 – 𝑦 – 𝑧 = −1
Solution:
>> A = [3 2 -1; -1 3 2; 1 -1 -1];
>> B = [10; 5; -1];% note that B is supplied as a
column vector
>> x = A\B
x =
-2.0000
5.0000
-6.0000
>> x = inv(A)*B
x=
-2.0000
5.0000
-6.0000
3.4 Iterative Methods in Matrix Algebra
The iterative techniques have the drawback of requiring initial guesses for all
unknown variables. These methods include:
1. Jacobi Iterative Method
2. Gauss-Seidel Iterative Method
3. Successive Over-Relaxation Method
3.4.1 Jacobi Iterative Method
The Gauss elimination methods were direct methods with a finite number of
arithmetic operations. Such methods are suitable for 20 to 25 equations. For large
sparse coefficient matrices (involving hundreds of equations) we need iterative
methods.

104
Consider
𝑎11 𝑥1 + 𝑎12 𝑥2 + 𝑎13 𝑥3 = 𝑏1
𝑎21 𝑥1 + 𝑎22 𝑥2 + 𝑎23 𝑥3 = 𝑏2
𝑎31 𝑥1 + 𝑎32 𝑥2 + 𝑎33 𝑥3 = 𝑏3
The solution process starts by solving for x1 from the first equation, solving for x2
from the second equation, and solving for x3 from the third equation:
𝑎11 𝑥1 = 𝑏1 − 𝑎12 𝑥2 − 𝑎13 𝑥3
𝑎22 𝑥2 = 𝑏2 − 𝑎21 𝑥1 − 𝑎23 𝑥3
𝑎33 𝑥3 = 𝑏3 − 𝑎31 𝑥1 − 𝑎32 𝑥2
Divide both sides of the above three equations by their diagonal elements a11, a22,
and a33 respectively:
𝑥1 = (𝑏1 − 𝑎12 𝑥2 − 𝑎13 𝑥3 )/𝑎11
𝑥2 = (𝑏2 − 𝑎21 𝑥1 − 𝑎23 𝑥3 )/𝑎22
𝑥3 = (𝑏3 − 𝑎31 𝑥1 − 𝑎32 𝑥2 )/𝑎33
Let x0 = [x01, x02, x03]’ be an initial estimate, then define the following iterative
procedure:
𝑥1𝑘+1 = (𝑏1 − 𝑎12 𝑥2𝑘 − 𝑎13 𝑥3𝑘 )/𝑎11
𝑥2𝑘+1 = (𝑏2 − 𝑎21 𝑥1𝑘 − 𝑎23 𝑥3𝑘 )/𝑎22
𝑥3𝑘+1 = (𝑏3 − 𝑎31 𝑥1𝑘 − 𝑎32 𝑥2𝑘 )/𝑎33

Example 3.8 (Jacobi iterative method)


Solve the following system of equations numerically using the Jacobi iterative method;
5𝑥1 – 𝑥2 + 𝑥3 = 10
2𝑥1 + 8𝑥2 – 𝑥3 = 11
−𝑥1 + 𝑥2 + 4𝑥3 = 3
Start with the initial guess x0 = [0,0,0]’
Solution:
𝑥1𝑘+1 = (10 + 𝑥2𝑘 − 𝑥3𝑘 )/5
𝑥2𝑘+1 = (11 − 2𝑥1𝑘 + 𝑥3𝑘 )/8
𝑥3𝑘+1 = (3 + 𝑥1𝑘 − 𝑥2𝑘 )/4
Starting with k=0;
𝑥11 = (10 + 𝑥20 − 𝑥30 )/5
𝑥21 = (11 − 2𝑥10 + 𝑥30 )/8
𝑥31 = (3 + 𝑥10 − 𝑥20 )/4
The iterations are listed below:
Table 3.1: Jacobi iterative method iterations
k 𝑥1𝑘 𝑥2𝑘 𝑥3𝑘
0 0 0 0
1 2.000000 1.375000 0.750000
2 2.125000 0.968750 0.906250

105
3 2.012500 0.957031 1.039063
4 1.983594 1.001758 1.013867
… … … …
16 2.000000 1.000000 1.000000

3.4.2 The Jacobi Iterative Method in Matrix Form


For a general set of n equations in n unknowns:
𝐴𝑥 = C (3.1)
The matrix of coefficients A can be written as:
𝐴 = (𝐴 – 𝐷) + 𝐷 (3.2)
where D is a diagonal matrix whose elements are those of the main diagonal of matrix
A. All elements of matrix D are zeros except those elements on its diagonal. In
MATLAB, matrix D can be obtained from matrix A as follows:
𝐷 = diag(diag(𝐴))
The matrix (A – D) is similar to matrix A, with the difference that its main diagonal
elements are equal to zero. Substitute for A in equation 3.1 from equation 3.2 and
rearranging:
𝐷𝑥 = 𝑐 – (𝐴 – 𝐷)𝑥 (3.3)
The vector x can be calculated from equation 3.3:
𝑥 = 𝐷−1 𝑐 – 𝐷−1 (𝐴 – 𝐷)𝑥
𝑥 = 𝐷 −1 𝑐 – (𝐷−1 𝐴 – 𝐼)𝑥 (3.4)
where I is the identity matrix. In an iterative procedure, equation 3.4 should be
written as:
𝑥 𝑘 = 𝐷 −1 𝑐 – (𝐷−1 𝐴 – 𝐼)𝑥 𝑘−1 (3.4)
where the superscript (k) represents the iteration number. The Jacobi method
requires an initial guess of all unknowns and the newly calculated values of the vector
x replace the old ones at the end of each iteration.
Example 3.9 ( Jacobi method in matrix form)
A chemical reaction takes place in a series of four continuous stirred tank reactors
arranged as shown below:

Figure 3.1 Reactors in Series

106
The chemical reaction is a first-order irreversible reaction of the type:
𝐴+𝐵 →𝐶
The following assumptions apply:
1. The system is at steady state
2. The reactions are in the liquid phase
3. There is no change in volume or density in the system
4. The rate of disappearance of component A in each reactor is given by:
𝑅𝑖 = 𝑉𝑖 𝑘𝑖 𝐶𝐴𝑖 𝑚𝑜𝑙/ℎ
The values of 𝑘𝑖 and 𝑉𝑖 are given in the table below.
Table 3.2: Reactors’ data
Reactor 𝑉𝑖 (lit) 𝑘𝑖 (h-1) Reactor 𝑉𝑖 (lit) 𝑘𝑖 (h-1)
1 1000 0.1 3 100 0.4
2 1500 0.2 4 500 0.3
1. Set up the material balance equations for each of the four reactors. What type
of equations do you have in this set of material balances?
2. Write a MATLAB script to solve this set of equations to compute the exit
concentration from each reactor.
Solution:
Input = output + disappearance by reaction + accumulation
Because the system is at steady state, the accumulation term is zero; therefore the
material balance reduces to:
Input = output + disappearance by reaction
This balance applied to each of the four reactors yields the following set of equations:
(1000)(1) = 1000𝐶𝐴1 + 𝑉1 𝑘1 𝐶𝐴1
1000𝐶𝐴1 + 100𝐶𝐴3 = 1100𝐶𝐴2 +𝑉2 𝑘2 𝐶𝐴2
1100𝐶𝐴2 + 100𝐶𝐴4 = 1200𝐶𝐴3 +𝑉3 𝑘3 𝐶𝐴3
1100𝐶𝐴3 = 1100𝐶𝐴4 +𝑉4 𝑘4 𝐶𝐴4
Substituting the values of 𝑉𝑖 and 𝑘𝑖 and rearranging:
1100𝐶𝐴1 = 1000
1000𝐶𝐴1 - 1400𝐶𝐴2 + 100𝐶𝐴3 = 0
1100𝐶𝐴2 - 1240𝐶𝐴3 + 100𝐶𝐴4 = 0
1100𝐶𝐴3 - 1250𝐶𝐴4 =0
The above is a set of four simultaneous linear algebraic equations. This set will be
solved by the Jacobi method in matrix form. An initial guess of 0.6 will be used for all
unknowns 𝐶𝐴1 to 𝐶𝐴4 .
Jacobi_matrix is a script m-file that finds the unknown variables of a set of linear
algebraic equations and uses TOL as the convergence test. A is the matrix of
coefficients, C is the vector of constants and X0 is the vector of initial guesses. Below
is the script file (Jacobi_inverse), which invokes function m_file Jacobi_iterative.m
[15]
% Script file Jacobi.m

107
clc
clear
%Input data
fprintf(' Solution of a set of linear algebraic
equations by the Jacobi method in matrix form\n\n')
n = input('Number of equations = ');
for k = 1:n
fprintf('\n Coefficients of equation %2d =',k)
A(k,1:n) = input(' ');
fprintf('Constant of equation %2d =',k)
c(k) = input(' ');
end
disp(' ')
tol = input(' Convergence criterion = ');
guess = input(' Vector of initial guesses = ')
ca = Jacobi(A, c, guess, tol);
fprintf('\n\n Results :\n')
for k = 1: n
fprintf(' CA(%2d) = %6.4g\n', k, ca(k))
end

function x = Jacobi(A, c, x0, tol)


%function Jacobi(A,C,X0,TOL) finds unknowns of a set
%of linear algebraic equations and uses TOL as the
%convergence test.
c = (c(:).')'; % Makes sure it's a column vector
x0 =(x0(:).')';% Makes sure it's a column vector
n = length(c);
[nr nc] = size(A);
%check coefficient matrix, vector of constants and
%vector of unknowns
if nr ~= nc
error('Coefficient matrix is not square.')
end
if nr ~= n
error('Coefficient matrix and vector ...
of constants do not have the same length.')
end
if length(x0) ~= n

108
error('Vector of unknowns and vector ...
of constants do not have the same length.')
end
%Check if the coefficient matrix is singular
if det(A) == 0
fprintf('\n Rank = %7.3g\n',rank(A))
error('The coefficient matrix is singular.')
end
%Building modified coefficient matrix and modified
%vector of constants
D = diag(diag(A)); %The diagonal matrix
% The modified matrix of coefficients:
a0 = inv(D)*A - eye(n);
c0 = inv(D)*c;% modified vector of constants
x = x0;
x0 = x + 2*tol;

while max(abs(x - x0)) >= tol


x0 = x;
x = c0 - a0*x0;
%The above line of code is the actual computations!
end

Solution of a set of linear algebraic equations by the Jacobi method in matrix form
Number of equations = 4
Coefficients of equation 1 = [1100, 0, 0, 0]
Constant of equation 1 = 1000
Coefficients of equation 2 = [1000, -1400, 100, 0]
Constant of equation 2 = 0
Coefficients of equation 3 = [0, 1100, -1200, 100]
Constant of equation 3 = 0
Coefficients of equation 4 = [0, 0, 1100, -1250]
Constant of equation 4 = 0
Convergence criterion = 1e-5
Vector of initial guesses = 0.6*ones(1,4)
guess = 0.6000 0.6000 0.6000 0.6000
Results :
CA( 1) = 0.9091
CA( 2) = 0.6987
CA( 3) = 0.6912
CA( 4) = 0.6082
109
Exercises
3.1 Solve numerically the following equations:
2𝑥1 + 3𝑥2 + 𝑥3 − 𝑥4 = 2
𝑥1 + 2𝑥2 + 5𝑥3 + 3𝑥4 = 5
−𝑥1 + 3𝑥3 + 𝑥4 = 1
𝑥1 − 2𝑥2 + 𝑥3 = −2
Using:
(a)University of Khartoum application
(b)Simple Gauss Elimination method
(c)Gauss Elimination method (partial pivoting)
(d)Gauss Elimination method (total pivoting)
(e)Jacobi iterative method
(f)Jacobi iterative method in matrix form
(g)MATLAB built_in function

3.2 The flow diagram shown below consists of a two distillation column unit for the
separation of a BTX feed stream. In the second column, 90% of the original (T)
charged to the unit is recovered in the overhead stream. Furthermore, 95% of the (X)
fed to the unit is recovered in the bottoms of the second column.
Write a MATLAB computer code to calculate the missing compositions of the output
streams.

110
Figure 3.2: Distillation system
c
3.3 In the following process, the ratio of the flow rate of stream (3) to that of stream
(1) is given equal to 0.3.
Determine:
(1)The degree of freedom for this unit
(2)The number of independent variables
(3)The number of independent equations
(4)Select a complete set of independent variables
(5)Write a MATLAB program to determine the concentrations in stream (4)
(a)Without using overall balances
(b)Using overall balances

111
112
CHAPTER

4 Initial Value Ordinary


Differential Equations

4.1 Classification of Differential Equations


There are two major types of differential equations (ODEs) and partial differential
equations (PDEs).
If an equation contains only ordinary derivatives of one or more dependent variables,
with respect to a single independent variable, it is then said to be an ODE. For
instance all the equations (a) – (d) below are ODE because there is only one
independent variable x.
An equation involving partial derivatives of two or more independent variables is a
PDE.
𝑑𝑦 𝑑𝑦
(𝑎) = 3𝑥 (𝑏) 𝑑 2 𝑦/𝑑𝑥 2 + 4 +𝑦 =0
𝑑𝑥 𝑑𝑥
𝑑𝑦 2
5𝑑 𝑦
(𝑐) = 𝑥 2 + 𝑦 2 (𝑑) (𝑑 3 𝑦/𝑑𝑥 3 )2 − 2 + 2𝑦 = 5
𝑑𝑥 𝑑𝑥

113
4.1.1 Definitions
ODEs are classified according to their order, degree, linearity, and boundary
conditions.
Order of a differential equation: is the order of the highest derivative involved.
Equations (a) and (c) are of first-order. Equations (b) and (d) are respectively second
and third orders.
Degree of differential equation: Is the power to which the highest-order derivative is
raised. For instance, (a) - (c) are differential equations of degree 1 while the differential
equation (d) is of degree 2.
Linearity of differential equations: A differential equation is linear if:
The dependent variable y and all its derivatives are of the first-order, that is, the power
of each term involving y or its derivatives is one, i.e. it does not contain products of
the dependent variable y or its derivatives or both.
Each coefficient depends on only independent x or is a constant.
For instance, (a) and (b) are linear differential equations while differential equation
(c) and (d) are non-linear.
4.2 Initial-Value ODE Problems:
The simplest form of the ODE is: y’ = f(x) where f(x) is a given function.
The general solution of this equation is:
𝑦(𝑥) = ∫ 𝑓(𝑥)𝑑𝑥 + 𝐶
where C is an arbitrary constant.
In chemical engineering applications, x can be the independent variable as an array of
time values (for dynamic or batch systems) or position along the length of a tubular
reactor or reactor incremental volume. The array y would be an array of values of the
dependent vector when there is only one dependent variable or a matrix of dependent
variable values if there are several such variables (such as temperature, concentrations,
and conversions).
The constant C can be calculated by specifying the value of function y(x) at a
particular point x0, y(x0) = y0. The point x0 is called the initial point, and the number
y0 is called the initial value. We call the problem of solving:
y’ = f(x,y); y(x0) = y0 the initial value problem (IVP).
4.3 Boundary-Value ODE Problems:
ODEs may be classified as initial-value problems or boundary-value problems. In
initial-value problems, the values of the dependent variables and/or their derivatives
are all known at the initial value of the independent variable. In boundary-value
problems, the dependent variables and or their derivatives are known at more than
one point of the independent variable. If some of the dependent variables (or their
derivatives) are specified at the final value of the independent variable, then the
problem is known as a two-point boundary-value problem.
4.4 Numerical Methods for Solving IVP

114
1. Euler’s Method
2. Higher-Order Taylor’s Method
3. Runge-Kutta Methods
4. Heun’s Mehod
5. Kutta Merson Method
6. Runge-Kutta-Butcher Sixth-Order Method
4.4.1 Fourth-Order Runge-Kutta Method:
The most popular most commonly used formula of Runge-Kutta Methods and is
based on Simpson’s 1/3 rule:

𝑦𝑖+1 = 𝑦𝑖 + [ 𝑘1 + 2𝑘2 + 2𝑘3 + 𝑘4 ]
𝑘
Where:
𝑘1 = 𝑓(𝑥𝑖 , 𝑦𝑖 )
ℎ ℎ
𝑘2 = 𝑓(𝑥𝑖 + 2 , 𝑦𝑖 + 2 𝑘1 )
ℎ ℎ
𝑘3 = 𝑓(𝑥𝑖 + 2 , 𝑦𝑖 + 2 𝑘2 )
𝑘4 = 𝑓(𝑥𝑖 + ℎ , 𝑦𝑖 + ℎ𝑘3 )
For each i = 0,1,…,n-1

Example 4.1 (Runge-Kutta method of fourth order)


Use Runge-Kutta method of fourth order to approximate the solution for the
following initial value problem:
𝑦’ = 𝑥𝑦 + 𝑥 0 =< 𝑥 <= 1 𝑦(0) = 0, with ℎ = 0.2
Solution:
We set f(x,y) = xy + x and x0 = 0, y0 = 0, and h = 0.2. Then for i = 0, we first
calculate value of y.
𝑘1 = (𝑥0 𝑦0 , 𝑥0 ) = 0.0000
ℎ ℎ ℎ
𝑘2 = [(𝑥0 + 2 ) (𝑦0 + 2 𝑘1 ) + (𝑥0 + 2 )] = 0.1000
ℎ ℎ ℎ
𝑘3 = [(𝑥0 + 2 ) (𝑦0 + 2 𝑘2 ) + (𝑥0 + 2 )] = 0.1010
𝑘4 = [(𝑥0 + ℎ ) (𝑦0 + ℎ𝑘3 ) + (𝑥0 + ℎ )] = 1.6491
Hence

𝑦1 = 𝑦0 + 𝑘 [ 𝑘1 + 2𝑘2 + 2𝑘3 + 𝑘4 ] = 0.0202
Similarly the other calculated values of k’s are as follows:
𝑘1 = 0.2040, 𝑘2 = 0.3122, 𝑘3 = 0.3154, 𝑘4 = 0.4333
𝑘1 = 0.4333, 𝑘2 = 0.5633, 𝑘3 = 0.5698, 𝑘4 = 0.7183
𝑘1 = 0.7183, 𝑘2 = 0.8883, 𝑘3 = 0.9002, 𝑘4 = 0.1018
𝑘1 = 1.1017, 𝑘2 = 1.3386, 𝑘3 = 1.3599, 𝑘4 = 1.64912
and the calculated values of y are given below:
𝑦2 = 0.0833, 𝑦3 = 0.1972, 𝑦4 = 0.3771, 𝑦5 = 0.6487

115
4.5 MATLAB User_Defined Function
Example 4.2 (MATLAB user_defined function)
Apply a MATLAB User_Defined Function to solve the following initial value
problem:
y’ = x + y 0 =< x <= 0.5 y(0)=0 n=10
(a)Show results in tabular form
(b)Plot results
Solution:
(a)From the editor window, define MATLAB function as follows:
function f = fun2(x,y)
f = x + y;
end
Construct MATLAB m-file for 4th order Runge-Kutta method:
function sol = RK4(fun2,a,b,y0,n)
h = (b-a)/n; x = a + (0:n)*h; y(1) = y0;
for k= 1:n
k1 = feval(fun2,x(k),y(k));
k2 = feval(fun2,x(k)+h/2, y(k)+h*k1/2);
k3 = feval(fun2,x(k)+h/2, y(k)+h*k2/2);
k4 = feval(fun2,x(k)+h, y(k)+h*k3);
y(k+1) = y(k) + h*(k1+2*(k2+k3)+k4)/6;
end; sol=[x',y'];
From command window type to obtain results in tabular form:
(b)To obtain results as a plot, do not include the operator (;) in the command
window.
function sol = RK4(fun2,a,b,y0,n)
h = (b-a)/n; x = a + (0:n)*h; y(1) = y0;
for k= 1:n
k1 = feval(fun2,x(k),y(k));
k2 = feval(fun2,x(k)+ h/2, y(k)+ h*k1/2);
k3 = feval(fun2,x(k)+ h/2, y(k)+ h*k2/2);
k4 = feval(fun2,x(k)+ h, y(k)+ h*k3);
y(k+1) = y(k) + h*(k1+2*(k2+k3)+k4)/6;
end;
plot(x,y);title('Laboratory Experiment')
xlabel('Time, sec'), ylabel('Distance, meters')
sol=[x',y'];
>>sol = RK4('fun2',0,0.5,0,10)

116
Laboratory Experiment
0.16

0.14

0.12

Distance, meters
0.1

0.08

0.06

0.04

0.02

0
0 0.05 0.1 0.15 0.2 0.25 0.3 0.35 0.4 0.45 0.5
Time, sec

Figure 4.1 Plot of Distance versus time

4.6 MATLAB ODE Solvers


The following table shows a list of some MATLAB solvers.

Table 4.1: A list of some MATLAB solvers


ODE
Type of problems Numerical
Solver Comments
likely to be solved solution method
function
Best choice for a first-guess
ode45 Nonstiff ODE Runge-Kutta
technique if you do not know
much about the function
Modified If the function is ‘mildly stiff’
ode23 Nonstiff ODE Explicit Runge- this may be a better choice than
Kutta ode45
ode113 Nonstiff ODE Adams Multistep solver
Stiff ODE and Uses numerical differentiation
ode15s differential NDF’s (BDFs) formulas (NDFs) or backward
algebraic equations differential formulas (BDFs)
Modified second-order
ode23s stiff ODEs Rosenbrock
Rosenbrock formulation
If a differential equation contains decaying exponentials then the problem is probably
a stiff one and it is better in such cases to use ode15s or ode23s solvers instead of
ode45.
Each MATLAB solver requires the following three inputs as a minimum:

117
1. A function handle to a function that describes the first-order differential
equation or system of equations in terms of t and y
2. The time span of interest
3. An initial condition for each equation
The solvers all return an array of t- and y- values:
[t,y] = ode solver (function-handle, [initial_time, final_time], [initial_condition]).
A function handle is a ‘nick name’ for a function. It can refer to either a standard
MATLAB function, stored as an M_file, or an anonymous MATLAB function.
𝑑𝑦 𝑑𝑦
When 𝑑𝑡 = 𝑓(𝑡, 𝑦), the function handle is equivalent to 𝑑𝑡
𝑑𝑦
In MATLAB notation dydt = @(t,y) 2*t is equivalent to 𝑑𝑡 = 2𝑡. Although this
particular function doesn’t use a value of y in the result (2t), y still needs to be part of
the input. For a system of equations it is probably easier to define a function M-file.
For the system:
𝑑𝑦
=𝑥
𝑑𝑡
𝑑𝑥
= −𝑦
𝑑𝑡
the output of the function must be a column vector of first-derivative values, as in:
function dy=twofuns(t,y)
dy(1) = y(2); % y(2) refers to x
dy(2)= -y(1); % y(1) refers to y
dy=[dy(1); dy(2)];
end
An alternative arrangement is as follows:
function f = twofuns(t,y)
f(1) = y(2);
f(2) =-y(1);
f = [f(1); f(2)];
% The output must be a column vector
end
4.7 ODE45 MATLAB Function
ODE45 solves non-stiff differential equations. The structure is:
[Tout,Yout] = ode45(FUN,Tspan,y0)
Tspan = [T0 Tfinal]
ODE45 integrates the system of differential equations y' = f(t,y) from time T0 to
Tfinal with initial conditions y0.
FUN is a function handle. For a scalar T and a vector Y, FUN(T,Y) must return a
column vector corresponding to f(t,y). Each row in the solution array Yout
corresponds to a time returned in the column vector Tout. To obtain solutions at

118
specific times T0,T1,...,TFINAL (all increasing or all decreasing), use TSPAN = [T0
T1 ... TFINAL].
If we have more than one differential equation, the initial condition for each
dependent variable must be provided.
Example 4.3
[t,y]=ode45(@vdp1,[0 20],[2 0]);
%the initial conditions [2 0] because we have two
%dependent variables y(1) and y(2)
plot(t,y(:,1));
Above program solves the system y' = vdp1(t,y), using the default relative error
tolerance 1e-3 and the default absolute tolerance of 1e-6 for each component, and
plots the first component of the solution.
Example 4.4
Consider the system:
dy/dx = x*y + x
Plot y versus x over the span 0 to 1, with the initial condition y(0) = 0
Solution:
>> fun = @(x,y) x*y + x;
>> [x,y] = ode45(fun,[0 1],0);
>> plot (x,y)
0.7

0.6

0.5

0.4

0.3

0.2

0.1

0
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

Figure 4.2 Plot for example 4.4


Example 4.5
Plot y=f(t) if dy/dt = 2*t over time span -1 to +1, y(0) = 1
Solution:
>> dydt = @(t,y) 2*t;
>> [t,y] = ode45(dydt, [-1,1],1);
>> plot(t,y)

119
1

0.9

0.8

0.7

0.6

0.5

0.4

0.3

0.2

0.1

0
-1 -0.8 -0.6 -0.4 -0.2 0 0.2 0.4 0.6 0.8 1

Figure 4.3 Plot for example 4.5


Example 4.6 (A case of an output consisting of 2 components; y1 and y2)
The statements[t,y]=ode45(@vdp1,[0 20],[2 0]); plot(t,y(:,1)); solves the system y' =
vdp1(t,y), using the default relative error tolerance 1e-3 and the default absolute
tolerance of 1e-6 for each component, and plots the first component of the solution.
The input [2 0] refers to the initial condition of y1 and y2.

Example 4.7 (Stiff differential equations)


Vapor phase cracking of acetone to ketene and methane, described by the following
endothermic reaction:
𝐶𝐻3 𝐶𝑂𝐶𝐻3 → 𝐶𝐻2 𝐶𝑂 + 𝐶𝐻3
takes place in a jacketed tubular reactor. Pure acetone enters the reactor at a
temperature of 1035 K and a pressure of 162000 Pa. The temperature of the external
gas in the heat exchanger is constant at 1150 K. Other data are as follows:
Volumetric flow rate (V0) = 0.001m3/s
Volume of the reactor (V) = 1 m3
Overall heat transfer coefficient (U) = 110 W/m2.K
Heat transfer area (a) = 150 m2/m3 reactor
Heat of reaction as a function of temperature:
ΔHR = 80770+6.8(T-298)-5.75X10-3(T2-2982)-1.27X10-6(T3-2983) J/mol
Heat capacity of acetone = 26.63+0.1830T-45.86X10-6T2 J/mol.K
Heat capacity of ketene = 20.04+0.0945T-30.95X10-6T2 J/mol.K
Heat capacity of methane = 13.39+0.077T-18.71X10-6T2 J/mol.K
Determine the temperature profile of the gas along the length of the reactor.
The reaction rate (assuming constant pressure throughout the reactor), is given by:
1 − 𝑋 T0
−𝑟𝐴 = 𝑘𝐶𝐴0 ( )( )
1+𝑋 𝑇
Solution:
We need to solve the material and energy balances simultaneously.
Let X = conversion of acetone, V = volume of reactor, CA0 is the concentration of
acetone vapor at inlet. FA0 = CA0V0 is molar flow rate of acetone at the inlet

120
T = temperature of the reactor
𝛥𝐶𝑃 = 𝐶𝑃𝐵 + 𝐶𝑃𝐶 − 𝐶𝑃𝐴
𝑑𝑋 −rA
Mole balance: =
𝑑𝑉 𝐹𝐴0
𝑑𝑇 Ua(𝑇𝑎 − T) + 𝑟𝐴 Δ𝐻𝑅
Energy balance: =
𝑑𝑉 𝐹𝐴0 (𝐶𝑃𝐴 + XΔ𝐶𝑃 )
Script file (15):
%Solution of Non_isothermal Plug_flow Reactor
%Acetone cracking.
% y(1) = conversion, y(2) = temperature K
X0 = 0.0; %inlet conversion of acetone
V0 = 0.002; % Volumetric flow rate m^3/s
T0 = 1035; %Inlet reactor temperature K
VR = 0.001; % Reactor volume 0.001 m^3
P0 = 162000; %Inlet reactor pressue kPa
CA0 = P0*(1 - X0)/(8.314+T0);
FA0 = CA0 * V0;
[v,y] = ode23(@Ex4_7,[0 VR],[X0 T0]);
conversion = y(:,1)*100; temperature = y(:,2);
plot(v,conversion)
xlabel('volume'); ylabel('conversion');
function f = Example4_7(v,y)
V0 = 0.002; %Volumetric flow rate m^3/s
U = 110; %Overall heat transfer coefficient W/m^2.K
a = 150; %Heat transfer area m^2/m^3 reactor
T0 = 1035; %Inlet reactor temperature K
%Temperature of external gas in the heat exchanger:
Ta = 1200;
P0 = 162000; %Inlet reactor pressure kPa
X0 = 0.0; %inlet conversion of acetone
CA0 = P0*(1 - X0)/(8.314+T0);
FA0 = CA0 * V0;
X = y(1);
T = y(2);
k = 3.58*exp(34222*(1/1035 - 1/T));
% Heat of reaction J/mol:
Heat_React = 80770 + 6.8*(T - 298) - 5.75e-3*...
(T^2 - 298^2) - 1.27e-6*(T^3 - 298^3);
%Heat capacity acetone J/mol.K:

121
CpA =26.63+0.1830*T-45.86e-6*T^2;
%Heat capacity ketene J/mol.K:
CpB =20.04+0.0945*T-30.95e-6*T^2;
%Heat capacity methane J/mol.K:
CpC =13.39+0.0770*T-18.71e-6*T^2;
DELTA_Cp = CpB + CpC - CpA;
rA =-k*CA0*(1-X)/(1.0 + X)*T0/T;
%mole balance and energy balance
f(1) = -rA/FA0;
f(2) = (U*a*(Ta - T) + rA*Heat_React)/(FA0*(CpA +
X*DELTA_Cp));
f =[f(1);f(2)]; % ode23s must return a column vector
end

Figure 4.4 Plot concentration versus volume


1040

1030

1020
temperature

1010

1000

990

980

970
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
volume -3
x 10

Figure 4.5 Plot temperature versus volume


Example 4.8: (Batch Reactor)

122
A batch reactor has the following reacting system [10]:
𝐴+𝐵 →𝐶
𝐶+𝐵 →𝐷
𝑑𝐶𝐴 𝑑𝐶𝐵 𝑑𝐶𝑐 𝑑𝐶𝐷
= −𝑟1 , = −𝑟1 − 𝑟2 , = 𝑟1 − 𝑟2 , = 𝑟2
𝑑𝑡 𝑑𝑡 𝑑𝑡 𝑑𝑡
𝑟1 = 𝑘1 𝐶𝐴 𝐶𝐵 𝑟2 = 𝑘2 𝐶𝐶 𝐶𝐵
𝑘1 = 1.0, 𝑘2 = 0.5
𝐶𝐴0 = 1, 𝐶𝐵0 = 2, 𝐶𝐶0 = 0, 𝐶𝐷0 = 0
Plot the concentration profiles of the reactor over the specified time span of t_end =
10.
Solution:
% Script M-file BATCH.m
k1 = 1; k2 = 0.5; t_end = 10;
cA0 = 1; cB0 = 2; cC0 = 0; cD0 = 0;
x0 = [cA0;cB0;cC0;cD0];
[t,x]= ode45(@batch_reactor,[0 t_end],x0,[],k1,k2);
% t is the time trajectory,
% x is the array of concentrations
%Plot results
plot(t,x(:,1),'k'); hold on; plot(t,x(:,2),'--');
plot(t,x(:,3),'r'); plot(t,x(:,4),'g');
xlabel('time t');ylabel(' concentration_j(t)');
title('Batch Reactor Concentration Profiles');
legend('A','B','C','D','Location','Best');
function f = batch_reactor(t, x, k1, k2)
f = zeros(size(x));
%extract concentrations from state vector
CA = x(1); CB = x(2); CC = x(3);CD = x(4);
% Compute rates of each reaction
r1 = k1*CA*CB; r2 = k2*CC*CB;
f(1) = -r1; % mole balance on A
f(2) = -r1 - r2; % mole balance on B
f(3) = r1 - r2; % mole balance on C
f(4) = r2; % mole balance on D
end
>> BATCH

123
Batch Reactor Concentration Profiles
2

1.8 A
B
1.6 C
D
1.4
concentration (t)

1.2
j

0.8

0.6

0.4

0.2

0
0 1 2 3 4 5 6 7 8 9 10
time t

Figure 4.5 Plot concentrations versus time (example 4.6)

Example 4.9
Apply ode23 or ode45 MATLAB functions to solve the initial value problem for the
first-order differential equation:
𝑑𝑦 −𝑡𝑦
= , 𝑦(0) = 1, 𝑡 𝜖[0, 5]
𝑑𝑡 √2 − 𝑦
First create a MATLAB function and name it fun1.m
function f = fun1(t,y)
f = -t*y/sqrt(2 - y^2);
end
Now use MATLAB ode23 and compare its solution against the solution obtained
from code ode45 and plot the two numerical solutions.
Create the following script file (or enter the following commands in MATLAB
window line by line):
[tv1,f1] = ode23('fun1', [0 5], 1);
[tv2,f2] = ode45('fun1', [0 5], 1);
plot(tv1,f1,'O-',tv2,f2,'--')
title('y= - ty/sqrt(2-y^2),y(0)=1, t in [0, 5]')
grid
axis [0 5 0 1]
Note:
The numerical solutions f1 and f2 respectively generated by ode23 and ode45 are
almost the same in this example as shown below.

124
Figure 4.6 Comparison of solutions obtained from ode23 and ode45

4.8 Membrane Reactors


Membrane reactors can be used in two types of applications [24]:
(a) Increasing conversion in a thermodynamically limited reversible raction
(b) Increasing selectivity of a desirable product in multiple competing reactions
A typical example is the production of ammonia from hydrogen and nitrogen:
3H2 + N2 ⇄ NH3
The reaction conversion is limited at thequilibrium conversion. To increase
conversion we need to shift the reaction to the right hand side. This calls for the
reduction of the number of moles. According to LeChatlier’s principle, we should
operate at very high pressure which favours a decrease in the number of moles.
Removal of hydrogen from the reacrion mixture as the reaction proceeds would thus
enhance conversion.
In general, if the reversible reaction is exothermic, increasing the temperature to
enhance rate of reaction, will drive the reaction to the left which would decrease
conversion. On the other hand decreasing the temperature will result in a reaction
rate so low that there is very little conversion. If the reaction is endothermic,
Increasing the temperature, will move the reaction in the desirable direction to the
right which favours higher conversion, but the high temperatue might damage and
deactivate the catalyst.
A membrane reactor can serve a number of functions:
(a) It can provide a barrier to certain components while being permeable to
others. In the ammonia case the semipermeable membrane surrounding the

125
reation mixture would allow hydrogen only to pass through its pores and thus
drive the reaction to the right toward completion.
(b) It can prevent certain components, such as particulates, from contacting the
catalyst.
(c) The membrane may contain active sites and be a catalyst itself.
There are two main types of membrane reactors:
(a) The inert membrane reactor with catalyst pellets on the feed side (IMRCF). In
this type the membrane is inert and srves as a barrier to the reactants and
some of the products.
(b) The catalytic membrane reactor (CMR). Here the catalyst is deposited directly
on the membrane and only specific reaction products can permeate through
the pores of the membrane.
Examples of the CMR type are the production of ammonia from hydrogen and
nitrogen, the dehydrogenationof ethylbenzene to styrene, and of butane to butane,
and propane to propylene.
Example 4.10 :( Catalytic Reactor with Membrane Separation)
The dehydration of a compound (elementary kinetics) is taking place in a selective
membrane reactor under isothermal conditions [3].
The advantage in using a membrane reactor is that the membrane removes selectively
one product (in this case H2) as it diffuses out through the pores of the membrane and
the reaction is driven to completion. The conversion thus achieved will be higher than
the conversion limited by thermodynamic equilibrium of the reversible reaction.
The rate of the mass transfer across the inert membrane depends not only on the
resistance offered by the membrane, but also on any boundary layers on each side of
the membrane.

Figure 4.7: Catalytic membrane reactor


The mass transfer dependence on velocity is assumed here to be given by:
𝑣
𝑘𝐶 = 𝑘𝐶0 ( )1/2
𝑣0
and the membrane transport of component C is given by 𝑘𝐶 𝑎𝐶𝐶 when permeate
concentration of C is low.
The following parameter values apply:

126
dm3 dm3 1/2
𝑘 = 0.5 , 𝑣0 = 50 , 𝐾𝐶 = 0.5 (kg.mol/dm3 )
kg.min min
kg.mol atm
𝑃0 = 10 atm , 𝐹𝐴0 = 10 , 𝛼 = 0.002
min kg
2
dm dm
𝑘𝐶0 = 0.1 , 𝑎=2 , W = 200kg
min kg
𝐹𝐴 , 𝐹𝐵 and 𝐹𝐶 are the molar flow rates of the components at any position in the reactor
in mol/min.
The solution involves simultaneous ordinary initial value differential equations and
explicit algebraic equations.
The applicable differential equations which describe the changes along the length of
the plug flow reactor are:
1. Three mole balances for the three components
2. A pressure drop equation
3. The explicit algebraic equations are:
Stoichiometric equations:
4. The kinetic rate law
5. The mass transfer coefficient given relation
The Set of equations are:
Mole balances differential equations:
𝑑𝐹𝐴
= 𝑟𝐴
𝑑𝑊
𝑑𝐹𝐵
= −𝑟𝐴
𝑑𝑊
𝑑𝐹𝐶 1
= − 𝑟𝐴 − 𝑘𝐶 𝑎𝐶𝐶
𝑑𝑊 2
Rate law:
1
𝐶𝐵 𝐶𝐶 2
𝑟𝐴 = −𝑘(𝐶𝐴 − )
𝐾𝐶
Stoichiometry

𝐹𝐴 𝐹𝐵 𝐹𝐶
𝑐𝐴 = , 𝑐𝐵 = , 𝑐𝐶 =
𝑣 𝑣 𝑣

𝐹𝐴 + 𝐹𝐵 + 𝐹𝐶 𝑃0
𝑣 = 𝑣0 ( )
𝐹𝐴0 𝑃

𝐹𝐴 + 𝐹𝐵 + 𝐹𝐶 1
= 𝑣0 ( )
𝐹𝐴0 𝑦
Where

127
𝑃
𝑦=
𝑃0
Pressure drop
𝐹𝐴 +𝐹𝐵 +𝐹𝐶
𝑑𝑦 −𝛼( )
𝐹𝐴0
=
𝑑𝑊 2𝑦
Mass transfer coefficient
𝑣 1/2
𝑘𝐶 = 𝑘𝐶0 ( )
𝑣0
Example 4.11 :( IMRCF membrane reactor for dehydrogenation of ethylbenzene)
A catalytic membrane reactor is to be used for the production of styrene by the
dehydrogenation of ethylbenzene:
𝐶6 𝐻5 𝐶2 𝐻5 ⇄ 𝐶6 𝐻5 𝐶2 𝐻3 + 𝐻2

The equilibrium constant for the reaction, 𝐾𝐶 , is 0.05 mol/dm3 . The membrane is
permeable to hydrogen only. Pure gaseous ethylbenzene enters the reactorat 8.2 atm
and 227O C at a rate of (𝐹𝐴0 ) 10 mol/min.
Transport out of the reactor:
The rate of diffusion of styrene (ST) through the membrane can be taken as:
𝑅𝑆𝑇 = 𝑘𝐶 𝐶𝐵
−1
𝑘𝐶 = 0.2 𝑚𝑖𝑛
The mole balances are:
𝑑𝐹𝐴
= 𝑟𝐴
𝑑𝑉
𝑑𝐹𝐵 𝐹𝐵
= −𝑟𝐴 − 𝑘𝐶 𝐶𝑇0 ( )
𝑑𝑉 𝐹𝑇
𝑑𝐹𝐶
= − 𝑟𝐴
𝑑𝑉
Rate law:
𝐶𝐵 𝐶𝐶
−𝑟𝐴 = k(𝐶𝐴 − )
𝐾𝐶
𝑘 = 0.7 𝑚𝑖𝑛−1
The rate law can be expressed in terms of flow rate parameters as follows:
𝐹𝐴 𝐶𝑇0 𝐹𝐵 𝐹𝐶
−𝑟𝐴 = k𝐶𝑇0 [(( ) − ( )( )( ))]
𝐹𝑇 𝐾𝐶 𝐹𝑇 𝐹𝑇
Prameter estimation:
𝑃0 830.6 𝑘𝑃𝑎
𝐶𝑇0 = = = 0.2 𝑚𝑜𝑙/𝑑𝑚3
𝑅𝑇0 8.314 𝑘𝑃𝑎 .𝑑𝑚3 /(𝑚𝑜𝑙.𝐾)(500 𝐾)

128
𝐹𝑇 = 𝐹𝐴 + 𝐹𝐵 + 𝐹𝐶
𝐹𝐵0 = 𝐹𝐶0 = 0
4.9 Higher-Order Differential Equations
As outlined above, systems of single first-order as well as systems of simultaneous
differential equations can be solved by ODE45 or ODE23 and other MATLAB
solvers.
Higher-order differential equations can also be solved by ODE solvers but we need to
convert such equations into an equivalent set of first-order equations first.
Consider the following second-order differential equation.
𝑑2 𝑦/𝑑𝑡 2 + 𝑑𝑦/𝑑𝑡 = 𝑦 + 𝑡
The range of time over which the integration is to be carried out is -1 to +1. The initial
dy
conditions are y = 1.0 and dt = 0.0. Reformulate the equation as a set of two first-
order differential equations as follows:
Let 𝑧 = 𝑑𝑦/𝑑𝑡
then 𝑑𝑧/𝑑𝑡 = 𝑑 2 𝑦/𝑑𝑡 2
Substituting in the original equation we obtain:
𝑑𝑧/𝑑𝑡 + 𝑑𝑦/𝑑𝑡 = 𝑦 + 𝑡
Which is a first-order differential equation. Thus the original second-order differential
equation has been replaced by the following two differential equations:
𝑑𝑦/𝑑𝑡 = 𝑧
𝑑𝑧/𝑑𝑡 = 𝑦 + 𝑡 − 𝑑𝑦/𝑑𝑡
The above system is a system of two first-order equations which can now be solved in
the usual way with any MATLAB ODE solver. The variable t is the independent
variable, and y is an array of dependent variables.
In the following function which contains the two differential equations, y(1)
corresponds to y and y(2) corresponds to z (i.e. corresponds to 𝑑𝑦/𝑑𝑡 ).
function dydt = twoeq(t,y)
dydt(1) = y(2); % dy/dt = z
dydt(2) = y(1) + t - dydt(1);
%dz/dt = y+t- dy/dt
dydt = dydt';
end
The statement (dydt = dydt’) is needed because the output must be a column vector.
The following command executes the ODE45 solver:
>> ode45 (@twoeq, [-1,1],[0,0])
The output is the graphical result shown Fig. 4.8 below:

129
0

y-axis, often represents distance,concentration, ...etc -0.05

-0.1

-0.15

-0.2

-0.25

-0.3

-0.35

-0.4

-0.45

-0.5
-1 -0.8 -0.6 -0.4 -0.2 0 0.2 0.4 0.6 0.8 1
x-axis, often represents time

Figure 4.8: Plot for second-order differential equation

Exercises
𝑑𝑦
4.1 Use a MATLAB solver to solve the equation = 2𝑡. Evaluate y from -1 to 1
𝑑𝑡
with the initial condition y(-1) = 1. Plot your results

4.2 Construct MATLAB computer programs to integrate the following initial value
differential equations:
𝑑𝐶𝐴
= −4𝐶𝐴 + 𝐶𝐵 𝐶𝐴 (0) = 100.0
𝑑𝑡
𝑑𝐶𝐵
= 4𝐶𝐴 − 4𝐶𝐵 𝐶𝐵 (0) = 0.0
𝑑𝑡
for the time period 0 ≤ t ≤ 5

4.3 Use ode23 to solve the following set of differential equations:


𝑑𝑦1
= 2𝑦1 + 𝑦2 + 5 𝑦3 + 𝑒 −2𝑡
𝑑𝑡

130
𝑑𝑦2
= −3𝑦1 − 2𝑦2 − 8 𝑦3 + 2𝑒 −2𝑡 − cos(3𝑡)
𝑑𝑡
𝑑𝑦3
= 3𝑦1 + 3𝑦2 + 2 𝑦3 + cos(3𝑡)
𝑑𝑡
𝑦1 (0) = 1, 𝑦2 (0) = −1, 𝑦3 (0) = 0
t in [0, pi/2]

4.4 A radioactive material (A) decomposes according to the series reaction:


𝑘1 𝑘2
𝐴→𝐵→𝐶
Where k1 and k2are the rate constants and B and C are the intermediate and final
products. The rate equations are:
𝑑𝐶𝐴
= −𝑘1 𝐶𝐴
𝑑𝑡
𝑑𝐶𝐵
= −𝑘1 𝐶𝐴 − 𝑘2 𝐶𝐵
𝑑𝑡
𝑑𝐶𝐶
= 𝑘2 𝐶𝐵
𝑑𝑡
CA, CB and Cc are the concentrations of materials A, B, and C respectively. The values
of the rate constants are:
𝑘1 = 3 𝑠 −1 𝑘2 = 1 𝑠 −1
Initial conditions are:
CA(0) = 1 mol/m3, CB(0) = 0, Cc(0) = 0
Sketch the concentration profiles for A, B, and C.

4.5 Integrate the following differential equations:


dCA
= −5CA + CB CA(0) = 20.0
dt
dCB
= 4CA − 4CB CB(0) = 0.0
dt

4.6 Solve the following system of differential equations:


dy
= 1 + 2 1 ≤ x ≤ 2, y (1) = −1
dx
dz
= y − x 1 ≤ x ≤ 2, z (1) = 0
dx

4.7 Solve the following system of differential equations:


dy
= 1 0 ≤ x ≤ 1, y (0) = −1
dx

131
dz
= 3y 2 0 ≤ x ≤ 1, z (0) = 0
dx

4.8 Determine the concentration profiles of all components of the following chemical
reaction system:
k1 k 2
A ⇌ B ⇌C
k3 k4

Assume that all steps are first-order reactions for the following values of the rate
constants:
k1 = 1 min−1 , k 2 = 0 min−1 , k 3 = 2 min−1 , k 4 = 3 min−1
The initial concentrations of the three components are:
CA (0) = 1.0, CB (0) = 0.0, CC (0) = 0.0,
The set of differential equations that give the rate of formation of each component is:
𝑑𝐶𝐴
= −𝑘1 𝐶𝐴 + 𝑘2 𝐶𝐵
𝑑𝑡
𝑑𝐶𝐵
= 𝑘1 𝐶𝐴 − 𝑘2 𝐶𝐵 − 𝑘3 𝐶𝐵 + 𝑘4 𝐶𝑐
𝑑𝑡
𝑑𝐶𝐶
= 𝑘3 𝐶𝐵 − 𝑘4 𝐶𝐶
𝑑𝑡

4.9 Plot the profiles of the following second-order differential equation


𝑑2𝑦 𝑑𝑦
2
+2 =𝑦+𝑡
𝑑𝑡 𝑑𝑡
The range of time is -1 to +1.
dy
The initial conditions are y= 1.0 and dt = 0.0

4.10 The vapor-phase cracking of acetone into ketone and methane in a non-
isothermal, non-adiabatic tubular reactor is described by the endothermic reaction:
𝐶𝐻3 𝐶𝑂𝐶𝐻3 → 𝐶𝐻2 𝐶𝑂 + 𝐶𝐻4
This takes place in a jacketed tubular reactor. Pure acetone enters the reactor at a
temperature ofT0= 1030 K and a pressure of P0= 1.58 atm. The temperature of the
external cooling medium in the heat exchanger is constant at TJ = 1200 K. The other
data is as follows:
Volumetric flow rate: q = qf = 0.003 m3/s,
Volume of the reactor: VR= 1.0 m3
Overall heat transfer coefficient between reactor and heat exchanger: U= 110
J/(m2.sec.K).
Total heat transfer area between reactor and exchanger: A = 160 m2/(m3of the
reactor).

132
Reaction rate constant: k = 3.56 exp[34200(1/1030−1/T)] s−1
Heat of reaction: ΔHR= 80700 + 6.7(T − 298) −5.7*10 (T – 298 ) −1.27 *10-6(T3–
-3 2 2

2983) J/mol
Heat capacity of acetone: CPA= 26.65 + 0.182T − 45.82*10-6 *T2 J/(mol · K)
Heat capacity of ketone: CPk= 20.05 + 0.095T– 31.01*10-6 *T2 J/(mol · K)
Heat capacity of methane: CPM= 13.59 + 0.076T – 18.82*10 *T J/(mol · K)
-6 2

Develop the material and energy balance equations in terms of conversion (X) and
temperature (T) as initial value differential equations:
𝑑𝑋
= 𝑓(𝑋, 𝑇)
𝑑𝑉
𝑑𝑇
= 𝑓(𝑋, 𝑇)
𝑑𝑉
(c)Write a MATLAB code to determine the conversion and temperature profiles of
the reacting gas along the length of the reactor.

4.11 An irreversible, endothermic, elementary, liquid phase reaction:


𝑘
𝐴+𝐵 →𝐶
is to be carried out in an agitated batch reactor that is heated by a steam jacket on the
reactor exterior. Initially the concentrations are CA0 = 2.5 g-mol/dm3, CB0 = 5 g-mol/dm3,
and CC0 = 0. The reactor volume is V = 1200 dm3, and the steam in the surrounding
jacket is kept at Tj = 150 OC. Additional data are given below.

Mole balance (Design equation expressed in terms of conversion 𝑥𝐴 ):


𝑑𝑥𝐴 −𝑟𝐴
=
𝑑𝑡 𝐶𝐴0
Energy balance:
𝑑𝑇 𝑈𝐴(𝑇𝑗 − 𝑇) + 𝑟𝐴 𝑉∆𝐻𝑅
=
𝑑𝑡 𝑁𝐴0 (𝐶𝑃𝐴 + 𝛳𝐵 𝐶𝑃𝐵 )
Rate Law
2 (1
𝑟𝐴 = −𝑘𝐶𝐴0 − 𝑥𝐴 ) (𝛳𝐵 − 𝑥𝐴 )
−𝐸 1 1
𝑘 = 0.001exp [ ( − )]
𝑅 𝑇 300
Where 𝑁𝐴0 is the initial molar amount of A that is calculated from 𝑁𝐴0 = 𝑉𝐶𝐴0 ,
𝑥𝐴 is the conversion of A, 𝛳𝐵 is the initial molar ratio given by 𝐶𝐵0 /𝐶𝐴0 and T is the
absolute temperature.
Table 4.2: Thermodynamic and reactor data
Activation Energy E = 83.6 kJ/g-mol
Rate Coefficient k = 0.001 dm3lg-mol.min at 27OC
Heat of Reaction at 273 K ∆𝐻𝑅 = 27.85 kJ/g-mol
Mean Heat Capacities CPA = 14 J/g-mol.K

133
CPB = 28 J/g-mol.K
CPC = 42 J/g-mol.K
Heat Transfer Area A = 5 m2
Heat Transfer Coefficient U = 3.76 kJ/min.m2.K

Write a MATLAB code and plot the conversion of A, 𝑥𝐴 , and the reactor
temperature during the first 60 minutes of reactor operation for an initial reactor
temperature of
T0 = 30OC.
Determine the minimal initial heating time to assure that 𝑥𝐴 = 0.99 for an initial
reactor temperature of T0 = 30OC.

4.12 The elementary irreversible liquid phase reaction:


𝐴+𝐵 →𝐶
is to be carried out in a series of three CSTRs as shown below. Species A and B are
fed in separate streams to the first CSTR, with the volumetric flow of each stream
controlled at 6 dm3 /min. The volume of each CSTR is 200 dm3, and each reactor is
initially filled with inert solvent. The initial concentrations of reactants are CAO = CBO =
2.0 G-mol/dm3. The reaction rate coefficient is k = 0.5 dm3/g-mol.min.

Figure 4.9: Three reactors in series


F1 = F2= F3 = 12
(a)Calculate the steady state concentrations of all reacting components exiting the third
reactor.
(b)Determine the time necessary to reach steady state (i.e. when CA exiting the third
reactor is 99% of the steady state value).
(c)Plot the concentration of A exiting each tank during start up to the steady state time
determined in part (b).
(d)Compare the results of (a) with that of a plug flow reactor with the same total
volume of 600 dm3 and the same reactor feed.
Hint:

134
For parts (a) to (c) material balances can be made on each reactor i. For a liquid phase
reaction, the volume change with reaction can be neglected. Thus the unsteady state
balances yield the following ODEs:
𝑑𝐶𝐴1
= (𝐹0𝐴 𝐶𝐴0 − 𝐹1 𝐶𝐴1 − k𝐶𝐴1 𝐶𝐵1 𝑉 1 )/𝑉1 (1)
𝑑𝑡
𝑑𝐶𝐴2
= (𝐹0𝐵 𝐶𝐵0 − 𝐹1 𝐶𝐵1 − k𝐶𝐴1 𝐶𝐵1 𝑉1 )/𝑉1 (2)
𝑑𝑡
𝑑𝐶𝐴1
= (𝐹1 𝐶𝐴1 − 𝐹2 𝐶𝐴2 − k𝐶𝐴2 𝐶𝐵2 𝑉 2 )/𝑉2 (3)
𝑑𝑡
𝑑𝐶𝐴1
= (𝐹1 𝐶𝐵1 − 𝐹2 𝐶𝐵2 − k𝐶𝐴2 𝐶𝐵2 𝑉2 )/𝑉2 (4)
𝑑𝑡
𝑑𝐶𝐴1
= (𝐹2 𝐶𝐴2 − 𝐹3 𝐶𝐴3 − k𝐶𝐴3 𝐶𝐵3 𝑉 3 )/𝑉3 (5)
𝑑𝑡
𝑑𝐶𝐵3
= (𝐹2 𝐶𝐵2 − 𝐹3 𝐶𝐵3 − k𝐶𝐴3 𝐶𝐵3 𝑉 3 )/𝑉3 (6)
𝑑𝑡

4.13 Three tanks in sequence are used to heat a multi-component oil solution. Each
tank is initially filled with 1000 kg of oil at 20OC. Saturated steam at a temperature of
250OC condenses within coils immersed in each tank. The oil is fed into the first tank
at the rate of 100 kg/min and overflows into the second and third tanks at the same
flow rate. The temperature of the oil fed to the first tank is 20OC. The tanks are well
mixed so that the temperature inside the tanks is uniform, and the outlet stream
temperature is the temperature within the tank. The heat capacity, Cp, of the oil is 2.0
kJ/kg.OC. The mass flow rate to each tank will remain the same fixed value, thus W =
W1 = W2 = W3. The mass in each tank will be assumed constant, thus M= M1 = M2 =
M3.

Figure 4.10: Three tanks in series

For tank number (𝑖) , the energy balance can be expressed as:
Accumulation = Input – Output
𝑑𝑇𝑖
𝑀𝐶𝑃 = 𝑊𝐶𝑃 𝑇𝑖𝑛 + 𝑈𝐴(𝑇𝑆𝑡𝑒𝑎𝑚 − 𝑇𝑖 ) − 𝑊𝐶𝑃 𝑇𝑖
𝑑𝑡

135
Where:
UA = 10 kJ/min.OC for each tank
𝑇𝑖 = Temperature of the oil in tank number (𝑖) in OC
𝑇𝑖𝑛 = Temperature of the oil in feed stream to tank in OC
𝑡 = time in minutes
Construct a MATLAB computer code for plotting the temperature in each tank
over the first 20 minutes of operation.

4.14 Solve example 4.10 (Catalytic Reactor with Membrane Separation):


Plot, on the same graph, the molar flow rate profile for the following cases:
(a)The base case (i.e. with membrane transport)
(b)Base case with no membrane transport
(c)Base case with no pressure drop
(d)Base case with no membrane transport and no pressure drop.

4.15 For example 4.11:


(a)Plot the molar flow rate profiles of components as a function of catalyst weight
(b) Caculate the conversion at V = 400 𝑑𝑚3
Take catalyst bulk density = 1.5 gm/𝑐𝑚3 and a 2-cm inside diameter tube containing
the catalyst pellets.

CHAPTER

5 Boundary Value Ordinary


Differential Equations
5.1 Types of Boundary value Problems
ODEs may be classified as initial-value problems or boundary-value problems. In
initial-value problems, the values of the dependent variables and/or their derivatives
are all known at the initial value of the independent variable. In boundary-value
problems, the dependent variables and or their derivatives are known at more than

136
one point of the independent variable. If some of the dependent variables (or their
derivatives) are specified at the final value of the independent variable, then the
problem is known as a two-point boundary-value problem.
Boundary value problems are similar to initial value problems. A boundary value
problem has conditions specified at the extremes ("boundaries") of the independent
variable in the equation whereas an initial value problem has all of the conditions
specified at the same value of the independent variable (and that value is at the lower
boundary of the domain, thus the term "initial" value).
For instance, if the independent variable is time over the domain [0,1], a boundary
value problem would specify values for y(t) at both t = 0 and t =1, whereas an initial
value problem would specify a value of y(t) and y’(t) at time
t = 0.
5.2 Boundary-value ODEs Applications in Chemical
Engineering
There are many chemical engineering applications that result in boundary-value
ODEs:
1. Diffusion with chemical reaction in the study of chemical catalysis or enzyme
catalysis.
2. Heat and mass transfer in boundary-layer problems.
3. Reactor with axial dispersion
4. Packed beds
5. Counter current heat transfer
6. Application of rigorous optimization methods, such as Pontryagin’s maximum
principle or the calculus of variations.
7. Discretization of nonlinear elliptical partial differential equations.

5.2.1 Porous Catalyst Pellet


(Diffusion and Reaction in Spherical Catalyst Pellets)

𝐷𝐴𝑆 Surface concentration


Bulk gas phase
𝐷𝐴𝐵 porous
𝐷𝐴𝑟 catalyst
pellet
External diffusion Internal diffusion

External Surface

Figure 5.1 Porous Catalyst Pellet

137
The following differential equation describes the profile of the concentration inside
the catalyst pellet:
𝑑 2 𝐶𝐴 𝑑𝐶𝐴 𝑘𝑛 𝑛
+ − 𝐶𝐴 = 0
𝑑𝑟 2 𝑑𝑟 𝐷𝑒
Where:
𝐷𝑒 = Effective diffusivity
r = distance from center of catalyst towards surface of catalyst (i.e. the radius of the
catalyst pellet)
The boundary conditions are:
The concentration remains finite at the centre of the pellet

CA is finite at r = 0

At the external surface of the catalyst pellet, the concentration is 𝐶𝐴𝑆


CA = CAS at r = R

5.2.2 The Plug Flow Axial Dispersion Model


A distributed model, which often arise with tubular equipment, is usually described by
differential equations. Such models differ from lumped parameter models which are
generally described by transcendental equations.
When a one-dimensional model is used for a distributed system, there are two types
of model (18):
1. If mixing, diffusion, and conduction are neglected then the system is described
by the so called plug flow model, expressed in terms of initial value ODEs
(ODEs) i.e. by initial value problems, or IVPs.
2. If the model accounts for the effects of axial dispersion, then the system is
described by an axial dispersion model in terms of two-point boundary ODEs,
i.e. by boundary value problems, or BVPs.
5.2.2.1 Formulation of the Axial Dispersion Model
The simplest description of axial dispersion of mass for constant diffusivities is given
by Fick’s law [19]:
𝑑𝐶𝑖
𝑁𝑖 = −𝐷𝑖
𝑑𝑙
Where 𝑁𝑖 is the mass flux of component i, measured in 𝑚𝑜𝑙𝑒𝑠/(𝑐𝑚2 . sec), 𝐷𝑖 is the
diffusion coefficient of component i in 𝑐𝑚2 /sec, 𝐶𝑖 is the concentration of
component i in 𝑚𝑜𝑙𝑒𝑠/𝑐𝑚3, and 𝑙 is the length co-ordinate in 𝑐𝑚.
The axial dispersion of heat (axial heat conduction) is described by Fourier’s law:
𝑑T
𝑞̅ = −λ
𝑑𝑙
Where 𝑞̅ is the heat flux in 𝐽/(𝑐𝑚2 . sec), λ is the thermal conductivity in

138
𝐽/(cm. sec. K), and T is the temperature in K.
For the case of axial dispersion of mass and heat for a single reaction in a tubular
reactor that operates at steady state with the rate of reaction r’ per unit volume†.
Let 𝑛𝑖 be the convective molar flow rate for the constant volumetric flow rate 𝑞𝑖 of
component i, (𝑛𝑖 = q. 𝐶𝑖 ) and 𝐴𝑡 the cross sectional area of the reactor tube.
The steady state mass balance with axial dispersion gives:
𝑑𝑛𝑖 𝑑𝑁𝑖
+ 𝐴𝑡 = 𝜎𝑖 𝐴𝑡 r’
𝑑𝑙 𝑑𝑙
The differential equation can be put in dimensionless form by introducing one simple
assumption such as constant volumetric flow rate q, (𝑖. 𝑒. 𝑛𝑖 = q. 𝐶𝑖 ). Therefore:
𝑑𝑛𝑖 𝑑𝐶𝑖
=𝑞
𝑑𝑙 𝑑𝑙
Substituting, we can write for constant volumetric flow rate:
𝑑𝐶𝑖 𝑑𝑁𝑖
𝑞 + 𝐴𝑡 = 𝜎𝑖 𝐴𝑡 r’
𝑑𝑙 𝑑𝑙
If we further assume that the diffusion coefficient 𝐷𝑖 is constant and then differentiate
Fick’s law with respect to 𝑙 we obtain:
𝑑𝑁𝑖 𝑑 2 𝐶𝑖
= −𝐷𝑖
𝑑𝑙 𝑑𝑙 2
The mass balance design equation thus becomes:
𝑑𝐶𝑖 𝑑 2 𝐶𝑖
𝑞 − 𝐴𝑡 𝐷𝑖 = 𝜎𝑖 𝐴𝑡 r’
𝑑𝑙 𝑑𝑙 2
Dividing by 𝐴𝑡 we obtain:
𝑑𝐶𝑖 𝑑 2 𝐶𝑖
𝑣 − 𝐷𝑖 = 𝜎𝑖 r’
𝑑𝑙 𝑑𝑙 2
Where 𝑣 = q/𝐴𝑡 is the velocity of the flow. We introduce a dimensionless length
w = 𝑙 /L, where L denotes the total length pof the tubular reactor. This gives:
𝑣 𝑑𝐶𝑖 𝐷𝑖 𝑑 2 𝐶𝑖
− = 𝜎𝑖 r’
𝐿 𝑑𝑤 𝐿2 𝑑𝑙 2
By rearranging we obtain:
1 𝑑 2 𝐶𝑖 𝑑𝐶𝑖 𝐿
− + 𝜎𝑖 r’ = 0
𝑃𝑒𝑀 𝑑𝑙 2 𝑑𝑤 𝑣
Where 𝑃𝑒𝑀 = L. v/𝐷𝑖 is the Peclet number for mass, and 𝜎𝑖 is the component
density.
If we assume that r’ is the rate of a simple first-order irreversible reaction, namely:
𝐸

r’ = 𝑘0 𝑒 𝑅.𝑇 𝐶𝐴
then, applying the same procedure for the heat balance with axial dispersion (axial
conduction) of heat, we obtain:


The symbol r’ should not be confused with symbol r which is used elsewhere in this document
denoting the extent of reaction in material balances.

139

1 𝑑2 y 𝑑y (−∆𝐻)𝐶𝐴𝑓 −𝛾/𝑦 𝑄’
− + 𝐷𝑎 . 𝑒 . 𝑥𝑎 = -
𝑃𝑒𝐻 𝑑𝑤 2 𝑑𝑤 𝜌.𝐶𝑃𝑚𝑖𝑥 .𝑇𝑓 𝑇𝑓

Where 𝑃𝑒𝐻 is the Peclet number for heat transfer, y = 𝑇/𝑇𝑓 , 𝑥𝐴 = 𝐶𝐴 /𝐶𝐴𝑓 , 𝐻 =
enthalpy of the mixture (𝐻𝑖 = 𝜎𝑖 𝐻) , 𝛾 the dimensionless activation energy,
𝛾 = 𝐸/(𝑅. 𝑇𝑓 ), and 𝐷𝑎 is the Damköhler number, 𝐷𝑎 = 𝑘0 . L/v.
The complete steady state isothermal model equation for an nth order reaction taking
place in a homogeneous tubular reactor for the simple reaction:
A B
the mass balance design equation is:
1 𝑑2 x 𝑑x
− − 𝐷𝑎 . 𝑥 𝑛 = 0
𝑃𝑒 𝑑𝑤 2 𝑑𝑤
Where for a first-order reaction (with n = 1) we use 𝐷𝑎 = k.L/v and for a second-order
reaction (with n=2) we use 𝐷𝑎 = k. L. 𝐶𝐴𝑓 /v.
The boundary conditions are:
At the exit:

𝑑x
For w = 1 = 0
𝑑𝑤

At the entrance:
1 𝑑x
For w = 0 = x - 1
𝑃𝑒 𝑑𝑤

5.3 Diffusion with Simultaneous Reaction in Isthermal Catalyst


Particles [6]
This section addresses the problem of the determination of the effectiveness factor (η)
for porous catalyst particles with spherical geometry accompanied by chemical
reaction. The effectiveness factor is then used for calculation of the average reaction
rate within the particle. The effectiveness factor is defined as follows:
average reaction rate within the particle
η=
reaction rate at the concentrations of the particle surface
The general solution involves the following steps:
a. Derivation of the ordinary differential equations that describe the material
balance within the pores of the particle.
b. Application of Fick’s law of diffusion
The numerical solution for a spherical particle involves the material balance on a
differential volume within the catalyst sphere which yiels:

140
𝑑
(𝑁𝐴 𝑟 2 ) =−𝑘 ′′ 𝑎 𝐶𝐴 𝑟 2 (5.1)
𝑑𝑟

5.4 Solution Methods


The solution algorithms for the solution of linear and non-linear boundary-value
problems include three main types:
(a)The shooting methods
(b)The finite difference method
(c)The collocation method
5.3.1 The Shooting Methods
There is a family of shooting methods. The general algorithm of these methods is to
convert the boundary value problem to an initial-value problem to take advantage of
the powerful algorithms available for the integration of initial value problems.
The solution strategy in this method is to guess the unspecified initial conditions of the
system of differential equations then integrate the equations in the forward direction as
a set of simultaneous initial-value differential equations. At the end, the calculated
values are compared with the known end boundary conditions. The guessed initial
conditions are updated if necessary and repeated trials are made until the difference
between the calculated and given final conditions is within pre-set convergence
criterion. The shooting methods may vary in their choice of initial or final conditions
and in the integration of the equations in one direction or two directions.
The most widely used shooting method is the Newton technique.
5.3.1.1 Newton Technique for Solving Boundary Value Problems
If for a second-order differential equation, we know the value of y at the initial and
final values of the time span, then we have a two point boundary problem. This type
of problem is solved by the MATLAB function bvp4c. The bvp4c requires 3 inputs:
• A function handle to the system of ODEs to be solved.
• A function handle to a function that solves for the residual values of the function
• A set of guesses for the initial conditions.
The first function handle should contain the equations for the derivatives. The output
of the function must be a column vector as required by ODE solvers.
To solve the problem a guess is made for the initial value of all the derivatives. The
program then checks to see how it performed by comparing the calculated boundary
values with the actual values. For instance, if: at t = -1, y = 0 and at t = 1, y = 3
The program would solve the system of equations based upon an initial guess of each
of the variables defined in the ODEs (e.g. y and dy/dt), and would then check to see
how close the result is at t = +1 (i.e. it would check to see if y=3). This is accomplished
using a boundary condition function called bc. If the correct boundary condition is
calculated, the function values (the residuals) are zero. For instance:
function residual = bc(y_initial, y_final)
141
residual(1) = y_initial(1) + 0;
residual(2) = y_final(1) -3;
residual = residual';
end
If this function is executed for values of y_initial = 0 and y_final =3, the result will be a
column of zeros. Any other result means that the program has calculated the wrong
values for y_initial and y_final, and the guesses for the initial conditions must be
updated according to the function’s algorithm, which is a finite difference strategy.
The last input to the bvp4c function is a mesh of guesses for the problem solution,
which are used as the starting point in the solution. bvp4c is a built_in MATLAB
function which solves boundary value problems for ODEs by collocation.
MATLAB provides a helper function bvpinit, to help create this mesh, which is
stored as a structure array. It requires two inputs; an array of values corresponding to
the independent variable (in this case t) and initial guesses for each of the variables
defined in the ODE code of equations. In our case there are two equations, so we’ll
𝑑𝑦
need a guess for y and 𝑑𝑡 . The mesh need not be particularly fine, and the initial
guesses need not be very good. For instance; initial_guess = bvpinit (-1:0.5:1, [0, -1])
𝑑𝑦
specifies five t values from -1 to 1 (-1, -0.5, 0, 0.5, 1) and initial guesses of 𝑦 = 0 and
𝑑𝑡
= -1 at all values of t.
Once the function describing the system of ODEs, the function defining the residuals
and the initial guesses created with bvpinit have been created, the bvp4c function can
be executed:
bvp4c (@twoeq, @bc, initial_guess)
ans =
x: [1x9 double]
y: [2x9 double]
yp: [2x9 double]
solver: ‘bvp4c’
The result is structure array, where x is the value of the independent variable (denoted
as t in this problem) and where an array of 𝑦 values corresponds to the solutions to
𝑑𝑦
the system of ODEs. In this case, 𝑦 and .
𝑑𝑡
To access the array of x values simply use the structure syntax, ans.x. The values of
most interest are the 𝑦 values, which can also be accessed using structure syntax,
ans.𝑦.
To plot the results use the code: plot(ans.x, ans.y, ‘-o’).
Example 5.1: (Two-point Boundary Value Problem)
Plot the profile of the second-order differential equation:
𝑑 2 𝑦 𝑑𝑦
+ =𝑦+𝑡
𝑑𝑡 2 𝑑𝑡
The time span is from -1 to +1 and the given conditions are such that:

142
At t = -1, y = 0 and at t = +1, y = 3
Solution:
We will create a mesh of initial guesses at five t values of: -1, -0.5, 0, 0.5, 1. At each of
𝑑𝑦
these t values we introduce initial guesses of 𝑦 = 0 and 𝑑𝑡 = −1.
function dydt = twoeq(t,y)
dydt(1) = y(2); % dy/dt = z, y(2)= y
dydt(2) = y(1) + t - dydt(1);
%dz/dt = y + t - dy/dt, y(1) = z
dydt = dydt';
end

function residual = bc(y_initial, y_final)


residual(1) = y_initial(1) + 0;
residual(2) = y_final(1) - 3;)
residual = residual';
end

% Script file SOLVE.m


initial_guess = bvpinit(-1:0.5:1, [0, -1])
bvp4c(@twoeq, @bc, initial_guess)
plot(ans.x, ans.y, '-o')
legend('y','dy/dt','Location','Best')
xlabel('x-axis-the independent variable, usually
time or distance')
ylabel('y-axis, the dependent variables')
Save script file as SOLVE and type in command window:
>> SOLVE

143
Figure 4.11: Plot of boundary value problem
Summary (Classical ODE Problems IVP versus BVP)
Example 5.2: Initial value ODE problem
Find y(x) if:
𝑦′′ + 2𝑦′ − 8𝑦 = 0.0, 𝑦(0) = 1, 𝑦′(0) = 0

Example 5.3: BVP


Find y(x) if:
𝑦′′ + 2𝑦′ − 8𝑦 = 0.0, 𝑦(0) = 1, 𝑦(1) = 0
A two-point BVP (such as example 5.3 above) includes an ODE and the solution at
two different locations. The BVP can be of any order, as long it is at least two, because
first-order ODEs cannot satisfy two conditions (generally).
For second-order differential equations any of the following combinations can be used
for boundary conditions:
𝑦(𝑥_initial) = 𝑦0 𝑦(𝑥_final) = 𝑦1
𝑦′(𝑥_initial) = 𝑦0 𝑦′(𝑥_final) = 𝑦1
𝑦′(𝑥_initial) = 𝑦0 𝑦(𝑥_final) = 𝑦1
𝑦(𝑥_initial) = 𝑦0 𝑦′(𝑥_final) = 𝑦1

144
Exercises
5.1 Solve and plot the solution of the following nonlinear boundary-value problem:
𝑦 ′′ = 2𝑦 3 − 6𝑦 − 2𝑥 3 𝑦(1) = 2, y(2) = 2.5 1 ≤ 𝑥 ≤ 2

5.2 Solve and plot the solution of the following nonlinear boundary-value problem:
𝜋 𝜋
𝑦 ′′ = 𝑥(𝑦 ′ )2 𝑦(0) = , 𝑦(2) = 0 ≤ 𝑥 ≤ 2
2 4
5.3 A heated rod with a uniform heat source can be modelled with the Poisson
equation:
𝑑2T
= −𝑓(𝑥)
𝑑𝑥 2
Given a heat source 𝑓(𝑥) = 25 and the boundary conditions:
T(𝑥 = 0) =40
T(𝑥 = 10) =200
Write a MATLAB code to solve for the temperature distribution along the rod axis
using the shooting method.

5.4 Many porous catalyst systems involve reactions in which both diffusion and
effective heat transfer must be included in a complete description of the catalytic
reaction.

𝐷𝐴𝑆 Surface concentration


Bulk gas phase
𝐷𝐴𝐵 porous
𝐷𝐴𝑟 catalyst
pellet
External diffusion Internal diffusion

External Surface

Figure 5.1 Porous Catalyst Pellet (re-drawn)

Internal mass transfer resistance to either the products or reactants occurs between the
external pellet surface and the interior of the pellet. An effective diffusion coefficient
(De) is usually used to describe the average diffusion taking place at any position (r) in
the pellet.
The differential equation that describes the mass transfer in a spherical catalyst
particle for an irreversible first-order chemical reaction 𝐴 → 𝐵 is given by a material
balance on a differential balance within the sphere:

145
𝑑2 𝐶𝐴 2 𝑑 𝐶𝐴 𝑘
+ ( ) − =0
𝑑𝑟 2 𝑟 𝑑𝑟 𝐷𝑒
The boundary conditions are:
1. There is no flux at the particle center, therefore the concentration remains
finite at the center of the pellet:
𝐶𝐴 = 0 𝑎𝑡 𝑟 = 0
2. At the external surface of the catalyst pellet, the concentration is 𝐶𝐴𝑆 :
𝐶𝐴 = 𝐶𝐴𝑆 𝑎𝑡 𝑟 = 𝑅
Write a MATLAB code to compute the concentration profile of species A in the
radial direction inside the catalyst pellet for the following data:
𝐷𝑒 = Effective diffusivity = 1.82𝑥10−3 𝑚2/s
R = Pellet radius = 3𝑥10−3 m
𝐶𝐴𝑆 = Concentration of species A at the catalyst surface = 2 gm/𝑚3
k = the rate constant, 4.42x10−10 𝑚3 /𝑚2 .𝑠

5.5 The diffusion and simultaneous first-order irreversible chemical reaction in a


single phase containing only reactant A and B results in a second-order ODE
given by [3]:

𝑑2 𝐶𝐴 𝑘
= 𝐶
𝑑𝑧 2 𝐷𝐴𝐵 𝐴

Where 𝐶𝐴 is the concentration of reactant A (kg-mol/𝑚3 ), z is the distance variable


d(m), k is the homogeneous reaction rate constant (𝑠 −1 ), and 𝐷𝐴𝐵 is the binary
diffusion coefficient (𝑚2 /s).
A typical geometry for above equation is that of a one-dimensional layer that has its
surface exposed to a known concentration and allows no diffusion across it bottom
surface.
Thus the initial and boundary conditions are:
𝐶𝐴 = 𝐶𝐴0 for z = 0
𝑑 𝐶𝐴
=0 for z = L
𝑑𝑍
Where 𝐶𝐴0 is the constant concentration at the surface (z = 0) and there is no
transport across the bottom surface (z = L), so the derivative is zero.
Solve the above boundary value differential equation for the case where 𝐶𝐴0 = 0.2 kg-
mol/𝑚3 , k = 10−3 𝑠 −1 , 𝐷𝐴𝐵 = 1.2 10−9 /𝑚2 /s , and L = 10−3 m.

5.6

146
CHAPTER

6
6.1 Prelude
Regression and Correlation
of Data (Curve Fitting)

MATLAB has built-in curve-fitting functions that allow us to model data empirically.
Empirical equations are not related to theory or physics of why a behaviour occurs;
they just predict how a parameter changes in relation to another parameter. These
models are good only in the region where we have collected data. Modelling of data
should be based not only on the data collected but also on a physical understanding of
the process. Regression analyst can be divided into two main fields [15]:
1. Linear Regression
2. Non-linear (or Polynomial) Regression
6.2 Linear Regression
Linear regression is modelling a set of data as a straight line. Consider the program
which plots the given x y data:
x = 0:5;
y = [15, 10, 9, 6, 2, 0];
Plot(x,y,'o')

Figure 6.1: Eye-ball curve fitting


The line drawn by ‘eyeballing’ seems to be a good fit. We can find the equation of this
line by noticing that the slope of this line (from co-ordinates of first and last points) is
𝑦2 − 𝑦1 0 − 15
= = = −3
𝑥2 − 𝑥1 5 −0
The line intercepts the x-axis at 15, therefore the equation of the line is:

147
𝑦 = −3𝑥 + 15
The differences between the actual values and the calculated values are listed below:
Table 5.1: Actual and calculated values
x y(actual) y_calc (calculated) Difference= y-y_calc
0 15 15 0
1 10 12 -2
2 9 9 0
3 6 6 0
4 2 3 -1
5 0 0 0

The linear technique uses an approach called least squares fit to compare how well
different equations model the behaviour of the data.
The differences between the actual and the calculated values are squared and added
together.
This has the advantage that positive and negative deviations don’t cancel each other
out.
We could use MATLAB to calculate this parameter for our data:
Sum_of_the_squares = sum((y-y_calc).^2)
sum_of_the_squares = sum((y - (-3*x+15)).^2)
sum_of_the_squares = 5
The linear regression technique compares different models and chooses the
appropriate one in which the sum of the squares is the smallest.
6.3 Polyfit Function
Linear regression is accomplished in MATLAB with the polyfit function.
Three fields are required by polyfit:
A vector of x-values, a vector of y_values, and an integer indicating what order
polynomial should be used to fit the data (an integer 1 for a straight line fit for
example).
For the above set of data:
polyfit (x,y,1)
ans = -2.9143 14.2857
The results are the coefficients of the best-fit equation:
𝑦 = −2.9143𝑥 + 14.2857
We can calculate the sum of squares to find out if this is a better fit than the ‘eyeball’
model:
best_y = -2.9143*x + 14.2857;

148
Sum_of_the_squares = sum((y-best_y).^2)
Sum_of_the_squares = 3.3714
We can conclude that MATLAB has found a better fit to the data.
We can plot the new fit:
axis ([-1 6 -1 16]);
hold on
plot(x,y,'o',x,best_y)
16

14

12

10

-1 0 1 2 3 4 5 6

Figure 6.2: Curve fitting using polyfit


6.4 Polynomial (Nonlinear Regression)
To fit the data with higher-order polynomial of the form:
𝑦 = 𝑎1 𝑥 𝑛 + 𝑎2 𝑥 𝑛−1 + 𝑎3 𝑥 𝑛−2 + … + 𝑎𝑛 𝑥 + 𝑎𝑛+1
For our data to a third order equation:
a=polyfit(x,y,3)
a=
-0.0648 0.5397 -4.0701 14.6587
which corresponds to the equation:
𝑦 = −0.0648𝑥 3 + 0.5397𝑥 2 − 4.0701𝑥 + 14.6587
We can find the sum of squares to see if this polynomial fits the data better:
y3=-0.0648*x.^3 + 0.5397*x.^2 - 4.0701*x +14.6587;
sum((y3-y).^2)
ans = 2.9921
If we want a smooth curve, we will need more points.
We can get more points and plot the curves with the following code:
smooth_x = 0:0.2:5;
smooth_y3 = -0.0648*smooth_x.^3 + 0.5397*smooth_x.^2
- 4.0701*smooth_x +14.6587;
plot(x,y,’o’,smooth_x,smooth_y3)
Although mathematically the polynomial model fitted the data better than the straight
line model, it may not be as good a representation of reality as the straight line.

149
16

14

12

10

-1 0 1 2 3 4 5 6

Figure 6.3: Curve fitting using third order equation


6.5 The Polyval Function
The polyfit funtction returns the coefficients of a polynomial that best fits the data.
We enter these coefficients into a MATLAB expression for the corresponding
polynomial and use it to calculate new values of y.
The polyval can perform the same job without the need to renter the coefficients.
The polyval function requires 2 inputs:
A coefficient array, such as that created by polyfit. The second is an array of x-values
for which we would like to calculate new y-values:
coef = polyfit(x,y,1)
y_first_order_fit = polyval (coef, x)
These two lines of code could be shortened to one line by nesting functions:
y_first_order_fit = polyval(polyfit (x,y,1), x)
The following program creates 4 plots using polyval function:
% Program using polyval function for curve fitting
x = [0:5];
y = [15 10 9 6 2 0];
smooth_x = 0:0.2:5;
y2 = polyval(polyfit(x,y,2),smooth_x);
y3 = polyval(polyfit(x,y,3),smooth_x);
y4 = polyval(polyfit(x,y,4),smooth_x);
y5 = polyval(polyfit(x,y,5),smooth_x);
subplot(2,2,1)
plot(x,y,'O',smooth_x,y2)
150
title('Second-Order-Model')
axis([-1,6,-5,16])
subplot(2,2,2)
plot(x,y,'O',smooth_x,y3)
title('Third-Order-Model')
axis([-1,6,-5,16])
subplot(2,2,3)
plot(x,y,'O',smooth_x,y4)
title('Fourth-Order-Model'); axis([-1,6,-5,16])
subplot(2,2,4)
plot(x,y,'O',smooth_x,y5); title('Fifth-Order-
Model'); axis([-1,6,-5,16])

The following program creates the same 4 plots by using for loop that makes use of
subplots and the sprintf function:
Second-Order-Model Third-Order-Model
15 15

10 10

5 5

0 0

-5 -5
0 2 4 6 0 2 4 6

Fourth-Order-Model Fifth-Order-Model
15 15

10 10

5 5

0 0

-5 -5
0 2 4 6 0 2 4 6

Figure 6.4: Curve fitting using second, third, fourth, and fifth order equations

%The following program (poly_4plots)creates the same


4 %plots by %using for loop that makes use of
subplots %and the sprintf function.
x = 0:5;
y = [15, 10, 9, 6, 2, 0];

151
smooth_x = 0:0.2:5;
for k = 1:4
subplot(2,2,k)
plot(x,y,'O',smooth_x,polyval(polyfit(x,y,k+1)...
,smooth_x))
axis([-1, 6, -5,16])
a = sprintf('Polynomial plot of order %d \n',k+1)
title(a);
end
Example 6.1: heat capacity of a gas (using polyval to fit data for carbon dioxide).
The laboratory heat capacity data for carbon dioxide is given as: Solution:
MATLAB Solution using polyval function:
Table 5.2: Temperature versus heat capacity

%Define the measured data


T=[250:50:800,900,1000,1500];

152
Cp=[0.791,0.846,0.895,0.939,0.978,1.014,1.046,1.075
1.102,1.126,1.148,1.169,1.204,1.234,1.328];
%Define a finer array of temperature
new_T = 250:10:1500;
%calculate new heat capacity values, using four
different polynomial models
Cp1 =polyval(polyfit(T,Cp,1),new_T);
Cp2 =polyval(polyfit(T,Cp,2),new_T);
Cp3 =polyval(polyfit(T,Cp,3),new_T);
Cp4 =polyval(polyfit(T,Cp,4),new_T);
%Plot the results
subplot(2,2,1)
plot(T, Cp, 'O', new_T, Cp1)
axis([0,1700,0.6,1.6])
title('First-Order-Model')
subplot(2,2,2)
plot(T, Cp, 'O', new_T, Cp2)
axis([0,1700,0.6,1.6])
title('Second-Order-Model')
subplot(2,2,3)
plot(T, Cp, 'O', new_T, Cp3)
axis([0,1700,0.6,1.6])
title('Third-Order-Model')
subplot(2,2,4)
plot(T, Cp, 'O', new_T, Cp4)
axis([0,1700,0.6,1.6])
title('Fourth-Order-Model')

In examining the 4 graphs in the last slide, we can see that a second- or third-order
model adequately describes the behaviour in this temperature range.
If we decide to use a third_order polynomial model, we can find the coefficients with
polyfit:
plyfit(T,Cp,3)
2.737211e-10 -1.063111e-06 1.552115e-03 4.683678e-01
The results correspond to the equation
𝐶𝑝 = 2.737211𝑒 −10 𝑇 3 − 1.063111𝑒 −6 𝑇 2 + 1.552115𝑒 −3 + 4.683678𝑒 −1

153
First-Order-Model Second-Order-Model

Heat Capacity, kJ/kg K


1.4 1.4

1.2 1.2

1 1

0.8 0.8

0.6 0.6
0 500 1000 1500 0 500 1000 1500

Third-Order-Model Fourth-Order-Model
Heat Capacity, kJ/kg K

1.4 1.4

1.2 1.2

1 1

0.8 0.8

0.6 0.6
0 500 1000 1500 0 500 1000 1500
Temperature, K Temperature, K

Figure 6.5: Curve fitting using second, third, fourth, and fifth order equations

154
Exercises
6.1 Write a general MATLAB code for fitting the following laboratory data (time
versus concentration) on the basis of linear and non-linear regression as required:
𝑡 = [1 2 3 4 5 6]
𝐶𝐴 = [0 0.5 1.3 2.1 3.5 6.0]

6.2 Write a general MATLAB code for plotting the best fit to the following
experimental data (temperature versus viscosity) on the basis of:
1. linear regression
2.non-linear regression of second, third and fourth order

Table 5.3: Temperature versus viscosity


Temperature Viscosity
100 10.1
105 9.5
110 8.5
120 7.5
153 6.3
160 4.0

6.3 Construct a MATLAB program to plot a fourth degree polynomial to best fit
the following graphical data for the variation of overall heat transfer coefficient
(U) with tube-side flow rate (W).

Figure 6.6: variation of overall heat transfer coefficient with tube-side flow rate

Can you estimate the overall heat transfer coefficient at a tube-side flow rate of 84.5 to
an accuracy of two decimal points?

155
156
CHAPTER

7 Optimization

7.1 Examples of Optimization Applications


Optimization can be applied in numerous ways to chemical processes and plants.
Typical projects where optimization has been used include [17]:
1.Determination of best sites for plant location
2.Routing of tankers for the distribution of crude and refined products
3.Pipeline sizing and layout
4.Equipment and entire plant design
5.Maintenance and equipment replacement
6.Operation of equipment such as tubular reactors, columns, absorbers, etc.
7.Evaluation of plant data to construct a model of a process
8.Minimization of inventory charges
9.Allocation of resources or services among several processes
10.Heat and mass integration in chemical processes
11.Planning and scheduling of construction
7.2 Single-variable bounded nonlinear function minimization
x = fminbnd(FUN,x1,x2) attempts to find a local minimizer x of the function: FUN
in the interval x1 < x< x2. FUN is a function handle. FUN accepts scalar input x and
returns a scalar function value F evaluated at x.
x = fminbnd(FUN,x1,x2,OPTIONS) minimizes with the default optimization
parameters replaced by values in the structure OPTIONS, created with the
OPTIMSET function. fminbnd uses these options: Display, TolX, MaxFunEval,
MaxIter, FunValCheck, PlotFcns, and OutputFcn.
[X,FVAL] = fminbnd(...) also returns the value of the objective function, FVAL,
computed in FUN, at x.
[X,FVAL,EXITFLAG] = fminbnd(...) also returns an EXITFLAG that describes the
exit condition of fminbnd. Possible values of EXITFLAG and the corresponding exit
conditions are:
1 fminbnd converged with a solution X based on OPTIONS.TolX.
0 Maximum number of function evaluations or iterations reached.
-1 Algorithm terminated by the output function.
-2 Bounds are inconsistent (that is, ax > bx).
FUN can be an anonymous function ((x) sin(x) +3):

157
𝑥 = fminbnd(@(𝑥) 𝑠𝑖𝑛(𝑥) + 3,2,5)
FUN can be a parameterized function. Use an anonymous function to capture the
problem-dependent parameters:
f = @(x,c) (x-c).^2; % The parameterized function.
c = 1.5; % The parameter.
x = fminbnd(@(x) f(x,c),0,1)
Example 8.1
Use the MATLAB fminbnd function to find the maximum of:
𝑥2
𝑓(𝑥) = 2 sin 𝑥 −
10
within the interval 0,4.
Solution:
function f = fx ( x )
f = -(2*sin(x) - x^2/10);
%Because we are interested in maximization, we
%entered the negative of the function
>>[x,FVAL] = fminbnd ('fx',0,4)
Results:
x = 1.4275
FVAL = -1.7757
Additional arguments can be included such as tolerance or maximum iterations. This
is done with the optimset . For instance, if you wanted to set the tolerance at 1x10−2,
optimset (‘TolX’, 1x𝑒 −2 ) then solving the problem to a tolerance of 1x10−2 can be
generated with:
[x,FVAL] = fminbnd('fx',0,4,optimset('TolX',1e-2))
x =1.4270
FVAL =-1.7757
Example 7.1 (Process Economics:Optimization of Cycle time in a Batch Operation)
An organic chemical is being produced by a batch operation in which no product is
obtained until the batch is finished. Each cycle consists of the operating time (reaction
time) necessary to complete the reaction plus a total time of 1.4 hours for discharging
and charging (shutdown time)
The operating time per cycle is equal to 1.5 𝑃0.25 hours, where (P) is the kilograms of
product produced per batch. The operating costs during the operating period are $20
per hour, and the costs during the discharge-charge period are $15. The annual fixed
costs for the equipment vary with the size of the batch as follows:
C_Fixed = 340 𝑃0.8 $/batch
If necessary the plant can operate for 24 hours per day for 300 days per year. The
annual production is one million kg of product. At this capacity, raw material and
miscellaneous costs, other than those already mentioned, amount to $260,000 per
year.

158
(a)Determine the optimum production per batch for conditions of minimum total
cost per year
(b)Determine the cycle time for conditions of minimum total cost per year
Solution:
(a)Express total annual cost as a function of production per batch (P):
Number of cycles per year = annual production/(production per cycle) = 1,000,000/P
Cycle time = operating time + shut down time
= 1.5 𝑃0.25 + 1.4 hours
(Operating + shutdown) costs/cycle = (20)(1.5 𝑃0.25 ) + (15)(1.4)
= 30 𝑃0.25 + 21
Annual fixed costs = 340 𝑃0.8 + 260,000
Total annual costs = (cost per cycle)(Number of cycles per year)+ Annual fixed costs
Total annual costs = (30 𝑃0.25 + 21)(1,000,000/P) + 340 𝑃0.8 + 260,000
We prepare a MATLAB for minimization of total annual costs:

function f = min_cost (x)


f=(30*x^0.25+21)*(1000000/x) + 340*x^0.8 + 260,000;
end
In command window type:
>>[x,FVAL] = fminbnd('min_cost',10,2000)
Ans = 1.6258e+03 kg/batch
7.3 Multidimensional Unconstrained Nonlinear Minimization
X = fminsearch(FUN,X0) starts at X0 and attempts to find a local minimizer X of the
function FUN. FUN is a function handle. FUN accepts input X and returns a scalar
function value F evaluated at X. X0 can be a scalar, vector or matrix.
X = fminsearch (FUN,X0,OPTIONS) minimizes with the default optimization
parameters replaced by values in the structure OPTIONS, created with the
OPTIMSET function. See OPTIMSET for details. fminsearch uses these options:
Display, TolX, TolFun, MaxFunEvals, MaxIter, FunValCheck,PlotFcns, and
OutputFcn.
[X,FVAL]= fminsearch(...) returns the value of the objective function, described in
FUN, at X.
[X,FVAL,EXITFLAG] = fminsearch(...) returns an EXITFLAG that describes the
exit condition of fminsearch. Possible values of EXITFLAG and the corresponding
exit conditions are:
1 Maximum coordinate difference between current best point and other points
in simplex is less than or equal to TolX, and corresponding difference in function
values is less than or equal to TolFun.
0 Maximum number of function evaluations or iterations reached.
-1 Algorithm terminated by the output function.
FUN can be specified using @:

159
x = fminsearch(@sin,3)finds a minimum of the SIN function near 3.In this case, SIN
is a function that returns a scalar function value SIN evaluated at X.
FUN can be an anonymous function.
FUN can be a parameterized function. Use an anonymous function tocapture the
problem-dependent parameters:
f =@(x,c)x(1).^2+c.*x(2).^2;
%The parameterized function
c = 1.5; %The parameter.
x = fminsearch(@(x) f(x,c),[0.3;1])
Example 7.2
Use the MATLAB fminsearch function to find the maximum of:
𝑓(𝑥) = 2𝑥𝑦 + 2𝑥 − 𝑥 2 − 2𝑦 2
Employ initial guesses of x = -1, and y =1
Solution:
First create an M-file to hold the function:
function f = fxy(x)
f = -(2*x(1)*x(2) + 2*x(1) - x(1)^2 - 2*x(2)^2);
end
[x,FVAL] = fminsearch('fxy',[-1 1])
Results:
x = 1.9999 1.0000
FVAL = -2.0000
To limit the number of iterations to 2 iterations:
x = fminsearch('fxy',[-1 1],optimset (‘MaxIter’,2), maximum)
7.4 Linear Programming
Linear programming is an optimization technique widely used for optimizing systems
where the objective function as well as the inequality and equality constrains are all
linear functions of the system variables.
7.4.1 MATLAB Function linprog
X = linprog(f,A,b) attempts to solve the linear programming problem:
min f'*x subject to: A*x <= b
x
X = linprog(f,A,b,Aeq,beq) solves the problem above while additionally
satisfying the equality constraints Aeq*x = beq.
X = linprog(f,A,b,Aeq,beq,LB,UB) defines a set of lower and upper bounds on the
design variables, X, so that the solution is in the range LB <= X <= UB. Use empty
matrices for LB and UB if no bounds exist. Set LB(i) = -Inf if X(i) is unbounded
below; set UB(i) = Inf if X(i) is unbounded above.
X = linprog(f,A,b,Aeq,beq,LB,UB,X0) sets the starting point to X0.
[X,FVAL] = linprog(f,A,b) returns the value of the objective function at X:
FVAL = f'*X.

160
[X,FVAL,EXITFLAG] = linprog(f,A,b) returns an EXITFLAG that describes the
exit condition of linprog, possible values of EXITFLAG and the corresponding
exit conditions are:
1 linprog converged to a solution X.
0 Maximum number of iterations reached.
-2 No feasible point found.
-3 Problem is unbounded.
-4 NaN value encountered during execution of algorithm.
-5 Both primal and dual problems are infeasible.
-7 Magnitude of search direction became too small; no further progress can be
made. The problem is ill-posed or badly conditioned.
Example 7.3
Minimize Z = 3.8*x1 + 3.2*x2
Subject to the constraints;
117*x1 + 129*x2 >= 119.5
2100*x1 + 9500*x2 <= 65.4
x1 + x2 = 1
Solution:
X = linprog(f,A,b,Aeq,beq) solves the problem above while additionally satisfying the
equality constraints Aeq*x = beq.
Set inequality constraints (as less than) constraints by multiplying by (-):
-117*x1 - 129*x2 <= -119.5
2100*x1 + 9500*x2 <= 65.4
Therefore inequality matrixes coefficients are:
A = [-117 -129; 2100 9500]
b = [-119.5 ; 65.4]
Equality matrixes coefficients are:
Aeq = [1 1]
beq = 1
The MATLAB program is as follows:
A = [-117 -129
2100 9500];
b = [-119.5 ; 65.4];
Aeq = [1 1];
beq = 1;
f = [3.80 3.20];
[X,FVAL] = linprog(f,A,b,Aeq,beq)
Result:
X=
0.4000
0.6000
FVAL = 3.4400

161
Example 7.4
Solve example 7.3 above taking into account the non-negativity constraints:
x1 >= 0.0 x2 >= 0.0
Solution:
A = [-117000 -129000
2100 9500];
b = [-119500 ; 6540];
Aeq = [1 1];
beq = 1;
LB(1) = 0.0; UB(1) = Inf;
LB(2) = 0.0; UB(2) = Inf;
f = [3.80 3.20];
LB(1) = 0.0; UB(1) = 1;
LB(2) = 0.0; UB(2) = 1;
[X,FVAL] = linprog(f,A,b,Aeq,beq,LB,UB)
Result:
X=
0.4000
0.6000
FVAL = 3.4400
Example 7.5 (Linear Programming)
A tank containing 1500 𝑚3 of naphtha is to be blended with two other hydrocarbon
streams to meet the specifications for gasoline. The final product must have:
A minimum research octane number (RON) of 95
A maximum Reid Vapor Pressure (RVP) of 0.6 bar
A maximum benzene content of 2%
A maximum total aromatics of 25%
The properties and costs of the three streams are given below:

Table 7.1: The properties and costs of the three streams


RON RVP(bar) Benzene Total Aromatics (% vol) Cost
(% vol) $/ m3
Naphtha 92 0.80 1.5 15 275
Reformate 98 0.15 50 50 270
Alkylate 97.5 0.30 0 0 350

Assuming that the properties of the mixture blend are in proportion to the volume of
the stream used, how much reformate and alkylate should be blended to minimize
cost ?

162
Solution:
Let x(1) and x(2) be the required amounts of reformate and alkylate in the blend.
The objective function is:
Cost = 1500*275 + 270*x(1) + 350*x(2)
Constraint RON:
1500*92 + 98*x(1) + 97.5*x(2) >= 95*(1500 + x(1) + x(2))
The above constraint should be set in the form (<=) by multiplying both sides of the
inequality by (-1):
-1500*92 - 98*x(1) - 97.5*x(2) <= -95*(1500 + x(1) + x(2))
Constraint RVP:
1500*0.8 + 0.15*x(1) + 0.3*x(2) <= 0.6*(1500 + x(1) + x(2))
Constraint Benzene:
1500*0.015 + 0.5*x(1) <= 0.02*(1500 + x(1) + x(2))
Constraint Total Aromatics:
1500*0.15 + 0.5*x(1) <= 0.25*(1500 + x(1) + x(2))
The relevant MATLAB Linear program is as follows:
A = [-3 -0.25;-0.45 -0.3;0.48 -0.02;-0.1
-0.25];
b = 1500*[-3 -0.2 0.005 0.1];
% make LB and UB vectors:
LB = [0.0 ; 0.0]; UB = [Inf ; Inf];
f = [270 350];
[X,FVAL] = linprog(f,A,b,[],[],LB,UB)
Results:
X=
1.0e+04 *
0.0510
1.1875
FVAL = 4.2941e+06
The amount of reformate = 510 𝑚3
The amount of alkylate = 11875 𝑚3
The minimum cost = 275*1500 + 270*510 + 350*11875
= $ 4,706,450
Example 7.6 (Linear Programming)
Two types of crude oil (Crude A and Crude B) are to be processed in a refinery. The
product distribution from the refinery is quite different for the two crudes as shown
below.
The limitations on the market demand for the various products in terms of the
maximum allowed daily production is shown below. In addition, processing cost are
also given in the table below.

163
Figure 7.1: Refinery configuration

(a) Formulate an objective function for the refinery management


(b) Formulate the constraints for the refinery operation
(c) Solve the problem to find the optimum production rate of each product

Table 7.2: Crude oil data


Volume percent Maximum allowable production
yield bbl/day
Crude Crude
A B
Gasoline 80 44 24,000
Kerosine 5 10 2,000
Fuel Oil 10 36 6,000
Residual 5 10 -
Processing cost 0.50 1.00 -
($/bbl)

Solution:
Let the barrels of crudes A and B be 𝑥𝐴 , and 𝑥𝐵 respectively.
Profit = Sales – (Raw material cost + Processing cost)
= 24*𝑥𝐴 + 15*𝑥𝐵 + 0.5*𝑥𝐴 + 𝑥𝐵
Gasoline production = 0.80*𝑥𝐴 + 0.44* 𝑥𝐵
Kerosine production = 0.05*𝑥𝐴 + 0.10* 𝑥𝐵
Fuel oil production = 0.10*𝑥𝐴 + 0.36* 𝑥𝐵
Residual production = 0.05*𝑥𝐴 + 0.10* 𝑥𝐵
Sales = 36*( 0.80*𝑥𝐴 + 0.44* 𝑥𝐵 ) + 24*(0.05*𝑥𝐴 + 0.10* 𝑥𝐵 ) +
21*(0.10*𝑥𝐴 + 0.36* 𝑥𝐵 ) + 10*(0.05*𝑥𝐴 + 0.10* 𝑥𝐵 )
Raw material cost = 24*𝑥𝐴 + 15*𝑥𝐵
Processing cost = 0.5*𝑥𝐴 + 𝑥𝐵
Therefore:
Profit = 8.1*𝑥𝐴 + 10.8*𝑥𝐵

164
Constraint on gasoline production:
0.80*𝑥𝐴 + 0.44* 𝑥𝐵 <= 24000
Constraint on kerosene production:
0.05*𝑥𝐴 + 0.10* 𝑥𝐵 <= 2000
Constraint fuel oil production:
0.10*𝑥𝐴 + 0.36* 𝑥𝐵 <= 6000
The MATLAB program is:

A = [0.80 0.44
0.05 0.10
0.10 0.36];
b = [24000 2000 6000];
LB = [0.0 ; 0.0]; UB = [Inf ; Inf];
% make LB and UB vectors.
%To find the maximum of the objective function you
%should multiply (f) by -1.This is because the
%function linprog attempts to find the minimum.
f = -[8.1 10.8];
[X,FVAL] = linprog(f,A,b,[],[],LB,UB)
Results:
X=
1.0e+04 *
2.6207
0.6897
7.5 Heat Integration
Process integration involves three major disciplines: Heat integration, mass
integration, and property integration [7]. To satisfy the heating, cooling, and power
requirements of a chemical process, several quantitative approaches have been
developed. These algorithms involve graphical, algebraic and computerized
optimization methods. The main objective of heat integration is to set a target of
minimizing the usage of external heating and cooling facilities and optimize stream
matching of the heat network streams which meets the set target. The stream matching
aims at minimizing the number of heat exchangers.
Commercial software is available for the design of Heat exchange networks (HENs).
Of special note are the following:
1. LINGO by LINDO Systems Inc.
2. Aspen HYSYS by AspenTech
3. ADVENT by Aspen Tech.
4. HexTRAN by Simulation Sciences Inc.
5. TARGET by Linnhoff-March Corp.

165
6. General Algebraic Modeling System (GAMS).
7.5.1 An Introductory Overview
There are three main approaches for the synthesis of HEAT exchange networks
(HENs):
1. A graphical approach which is a visualization technique for determining
minimum heating and cooling requirements. Thermal pinch point diagrams
are used in this method.
2. An algebraic approach which uses cascade diagrams to target minimum utility
requirements.
3. A mathematical (programming) approach which can :
(a) Determine minimum utility requirements
(b) Select optimum utility facilities
(c) Synthesize a network of heat exchangers that can meet the minimum utility
requirements.
A mathematical approach for the synthesis of heat exchange networks (HENs) will be
presented in the following sections using MATLAB software.
In solving heat network design problems we often need to make use of optimization
algorithms such as linear programming (LP) and its variants. Chapter seven in this
book (on Optimization) presents the topic of LP with solved examples.
7.5.2 HEN Synthesis Problem Statement
Consider a process with 𝑁𝐻 process hot streams, 𝑁𝐶 process cold streams, 𝑁𝐻𝑈
heating utilities, and 𝑁𝐶𝑈 cooling utilities. The index u is used for process hot streams
and heating utilities, while the index v is used for process cold streams and cooling
utilities. The index z is used to indicate temperature intervals [7].
The diagram below shows the heat balance components round an interval z.

Figure 7.2: Temperature interval number z [7]

166
7.5.2.1 Temperature Interval Diagram (TID)
Two corresponding temperature scales are generated: hot (T) and cold (t) separated
by a minimum temperature driving force (∆𝑇𝑚𝑖𝑛 ):
T = t + ∆𝑇𝑚𝑖𝑛
Process streams are represented by vertical arrows extending between supply and
target temperatures. Horizontal lines are drawn at the heads and tails of the arrows,
defining a series of temperature intervals z = 1, 2,..., 𝑛𝑖𝑛𝑡 . On the basis of the second
law of thermodynamics, heat can be transferred from hot streams to cold streams
within any interval or passed downward to cold streams in lower ranking intervals.
7.5.2.2 Table of Exchangeable Heat Loads (TEHL)
In this table the exchangeable heat loads of the process streams in each temperature
interval [7].
The exchangeable load of the uth hot stream (which a heat lost from a hot stream)
which passes through interval z is:
𝐻𝐻𝑈,𝑍 = 𝐹𝑈 𝐶𝑃,𝑈 (𝑇𝑍−1 − 𝑇𝑍 ) 7.1
Where 𝐹𝑈 is flow rate of hot stream u, and 𝑇𝑍−1 and 𝑇𝑍 are the hot scale
temperatures at the top and bottom lines defining interval z.
Similarly, the exchangeable capacity of the vth cold stream (representing a heat gain by
the cold stream) which passes through interval z is:
𝐻𝐶𝑉,𝑍 = 𝑓𝑉 𝐶𝑃,𝑉 (𝑡𝑍−1 − 𝑡𝑍 ) 7.2
Where 𝑓𝑉 is flow rate of cold stream v, and 𝑡𝑍−1 and 𝑡𝑍 are the cold scale
temperatures at the top and bottom lines defining interval z.
The reader should take note of the use of the expressions heat load and cooling
capacity as used in the context above.
We sum up the heating loads and cooling capacities within interval z we obtain:
𝐻𝐻𝑍𝑇𝑜𝑡𝑎𝑙 = ∑𝑈 𝑃𝑎𝑠𝑠𝑒𝑠 𝐻𝐻𝑈,𝑍 7.3
𝐻𝐶𝑍𝑇𝑜𝑡𝑎𝑙 = ∑ H𝐶𝑉,𝑍 7.4
𝑉 𝑃𝑎𝑠𝑠𝑒𝑠
Heating and cooling capacities are incorporated in the model equations. For interval z
the heat load of heating utility number u is expressed as follows:
𝐻𝐻𝑈𝑈,𝑍 = 𝐹𝑈𝑈 𝐶𝑃,𝑈 (𝑇𝑍−1 − 𝑇𝑍 ) 7.5
Where u = 𝑁𝐻 +1, 𝑁𝐻 + 2,..., 𝑁𝐻 + 𝑁𝐻𝑈
𝐹𝑈𝑈 is the flow rate of hot utility number u.
The sum of all heating utilities in interval z :
𝐻𝐻𝑈𝑍𝑇𝑜𝑡𝑎𝑙 = ∑ 𝐻𝐻𝑈,𝑍 7.6
𝑈 𝑃𝑎𝑠𝑠𝑒𝑠
The total heating load of the uth utility in the HEN may be evaluated by summing up
the individual heat loads over all the intervals:
𝑄𝐻𝑈 = ∑ 𝐻𝐻𝑈,𝑍 7.7
𝑍

167
Similarly the cooling capacities of the vth cooling utility in the zth interval is:
𝐻𝐶𝑈𝑉,𝑍 = 𝑓𝑈𝑉 𝐶𝑃,𝑉 (𝑇𝑍−1 − 𝑇𝑍 ) 7.8
Where v = 𝑁𝐶 +1, 𝑁C + 2,..., 𝑁𝐶 + 𝑁𝐶𝑈
𝑓𝑈V is the flow rate of cooling utility number v.
The sum of all heating utilities in interval z :
𝐻𝐻𝑈𝑍𝑇𝑜𝑡𝑎𝑙 = ∑ 𝐻𝐻𝑈,𝑍 7.9
𝑈 𝑃𝑎𝑠𝑠𝑒𝑠
The total cooling capacity of the vth utility in the HEN may be evaluated by summing
up the individual heat loads over all the intervals:
𝑄𝐶𝑈 = ∑ 𝐻𝐶𝑈,𝑍 7.10
𝑍
WE can make the following heat balance round interval z:
𝐻𝐻𝑍𝑇𝑜𝑡𝑎𝑙 − 𝐻𝐶𝑍𝑇𝑜𝑡𝑎𝑙 = 𝐻𝐻𝑈𝑍𝑇𝑜𝑡𝑎𝑙 − 𝐻𝐻𝐶𝑍𝑇𝑜𝑡𝑎𝑙 + 𝑟𝑍−1 − 𝑟𝑍 7.1
z = 1,2,..., 𝑛𝑖𝑛𝑡
Where 𝑟0 = 𝑟𝑛𝑖𝑛𝑡
𝑟𝑍 > = 0 z = 1,2,..., 𝑛𝑖𝑛𝑡 – 1
7.6 Targeting for Minimum Heating and Cooling Utilities
The objective is to minimize the cost of heating and cooling utilities.
Let 𝐶𝐻𝑈 the cost of the uth heating utility, and 𝐶𝐶𝑉 be the cost of the vth cooling
utility. If the cost is given in terms of ($/unit flow rate), then the objective function can
be written as:
𝑁𝐻 + 𝑁𝐻𝑈
Minimize ∑𝑈=𝑁 (𝐶𝐻𝑈 ∗ FUH ) +
𝐻 +1
𝑁𝐶 + 𝑁𝐶𝑈
∑𝑉=𝑁 𝐶 +1
(𝐶𝐶𝑉 ∗ fUV ) 7.12
If the cost is given in terms of ($/unit heat added or removed), then the objective
function can be written as follows:
𝑁𝐻 + 𝑁𝐻𝑈
Minimize ∑𝑈=𝑁 (𝐶𝐻𝑈 ∗ QHU ) +
𝐻 +1
𝑁𝐶 + 𝑁𝐶𝑈
∑𝑉=𝑁 𝐶 +1
(𝐶𝐶𝑉 ∗ 𝑄𝐶𝑉 ) 7.13
Example 7.7 (Linear Programming)
The diagram below depicts a pharmaceutical facility [7].
The cost of the heating and cooling utilities ($/106 kJ) are 6 and 8 respectively. Table
7.3 gives stream data.
In the current operation, the heat exchange duties of the hot and cold streams are
fulfilled using the heating and cooling facilities. The current annual operating cost of
utilities is:
[(4750+120)kWx6x10−6 $/kJ + (1900+400)kWx8x10−6 $/kJ ]x3600x8760 $/yr
= $1,501,744 /yr

168
Use linear programming to determine the minimum operating cost. A value of
∆𝑇𝑚𝑖𝑛 = 10 K is used.

Table 7.3: Stream data for example 7.7


Stream Flow Rate x Specific Supply Target Enthalpy
Heat, kW/K Temp. K Temp. K Change, kW
𝐻1 10 520 330 -1900
𝐻2 5 380 300 -400
𝐻𝑈1 ? 560 520 ?
𝐶1 19 300 550 4750
𝐶2 2 320 380 120
𝐶𝑈1 ? 290 300 ?

Figure 7.3 : pharmaceutical facility [7]


Solution:
The TID diagram is shown below:

169
Figure 7.4: The TID diagram

The TEHL for the process hot streams is shown in table 7.4 below:

Table 7.4: The table of exchangeable heat loads (TEHL) for the hot streams
Interval Load of Load of Total Load (kW)
𝐻1 (kW) 𝐻2 (kW)
1 - - -
2 1300 - 1300
3 100 - 100
4 500 250 750
5 - 100 100
6 - 50 50

The TEHL for the process cold streams is shown in table 7.5 below:
Table 7.5: The table of exchangeable heat loads (TEHL) for the cold streams
Interval Load of Load of Total Load (kW)
𝐶1 (kW) 𝐶2 (kW)
1 760 - 760
2 2470 - 2470
3 190 20 210
4 950 100 1050
5 380 - 380
6 - - -

The relevant MATLAB program is as follows:


% r1 0 0 0 0 -Qhmin 0 = -760;
%-r1 r2 0 0 0 0 0 = -1170;
% 0 -r2 r3 0 0 0 0 = -110;
% 0 0 -r3 r4 0 0 0 = -300;

170
% 0 0 0 -r4 r5 0 0 = -280;
% 0 0 0 0 -r5 0 Qcmin = 50;
Aeq = [1 0 0 0 0 -1 0
-1 1 0 0 0 0 0
0 -1 1 0 0 0 0
0 0 -1 1 0 0 0
0 0 0 -1 1 0 0
0 0 0 0 -1 0 1];
beq = [-760 -1170 -110 -300 -280 50];
LB = zeros(6,1); UB = [Inf;Inf;Inf;Inf;Inf;Inf;Inf];
% make LB and UB vectors.
%To find the maximum of the objective function you
should multiply (f) by -1.
%This is because the function linprog attempts to
find the minimum.
f = [0 0 0 0 0 189.216 252.288];
[X,FVAL] = linprog(f,[],[],Aeq,beq,LB,UB)
Results:
X=
1.0e+03 *
1.8600
0.6900
0.5800
0.2800
0.0000
2.6200
0.0500
FVAL = 5.0836e+05
Objective function = 508360
Qhmin = 2620 , Qcmin = 50
7.7 Integer and Mixed Integer Programming
Many problems in plant operation, design, location, and scheduling involve variables
that are not continuous but instead have integer values. Decision variables for which
the levels are a dichotomy are termed binary variables. In the heat integration topic,
decisions have to be taken regarding installation of a heat exchanger or not.
The following is a brief outline of typical integer programming problems in chemical
engineering and related areas:
(a) The travelling salesman problem
The classical travelling salesman problem is a special case of the transportation
problem where we assign values of 0 or 1 to variables 𝑥𝑖𝑗 , where 𝑥𝑖𝑗 is 1 if the

171
salesman travels from city i to city j and 0 otherwise. The constraints are that the
salesman must start at a particular city, visit each of the other cities only once, and
return to the original city. The objective function is to minimize the total cost of the
trips.
(b) The knapsack problem
In this type of problem we have n articles each designated by 𝑥𝑖 ; the weight of the ith
article is 𝑤𝑖 and its value is 𝑠𝑖 .The objective is to select the articles such that their
total weight does not exceed W and their total value is a minimum:
Minimize f(x) = ∑𝑛 𝑖=1 𝑠𝑖 𝑥𝑖
𝑛
Subject to ∑𝑖=1 𝑤𝑖 𝑥𝑖 ≤ W 𝑥𝑖 = 0,1 i = 1,2,...,n
In the constraint 𝑥𝑖 = 0,1, the binary variable imposes the condition that an article 𝑥𝑖
is selected (𝑥𝑖 = 1) or is not selected ((𝑥𝑖 = 0).
(c) The scheduling problem
The problem here is to schedule the jobs on each machine so that the total time for
the completion of all jobs is minimized. If 𝑥𝑖𝑗 is the starting time of job i on machine
j, j=1,2,...,n and the time 𝑡𝑖𝑗 is the time required to complete the job i on machine j ,
the problem is to optimally schedule the jobs on each machine. Because ( 𝑥𝑖𝑛 + 𝑡𝑖𝑛 )
is the time at which job i is completed on machine n, the maximum of these numbers
is the time at which the latest job is completed. It is that time which is to be
minimized:
Minimize f(x) = max ((𝑥𝑖𝑛 + 𝑡𝑖𝑛 )
i
The constraints on the problem is that a job cannot be processed on machine n
before it has been completed on machine (n-1), and it cannot be processed on
machine (n-1) before it has been completed on machine (n-2) and so forth. Such
constraints are called procedure constraints.
(d) Plant location problem (e.g. Location of oil wells)
It is assumed that a specific production-demand versus time relation exists for a crude
oil reservoir. Several sites for new wells are available. The optimization problem is
how to best select from among the well sites the number of wells to be drilled, their
locations, and the production-demand curve and flow curve actually obtained is
minimized. The integer variables are 0 = not drilled and 1= drilled.
(e) Blending problem
The problem here is that we are given the possible ingredients from a list containing
the weight and analysis of each ingredient. The aim to select from the list of items and
their weights so as to meet a certain weight target at minimum cost for a blend. Here
the quantity of ingredient available in continuous amounts 𝑥𝑗 and 𝑦𝑘 represents
ingredients available in discrete quantities (𝑦𝑘 = 1 if used and 𝑦𝑘 = 0 if not used).

172
7.8 Stream Matching and HEN Synthesis
After finishing the targeting stage of determining the minimum utility requirements,
the next task is to match the hot and cold streams which will meet the set targets.
Stream matching involves the use of integer and mixed integer programming. In the
following section an introductory over view of this type of programming is presented.
When a pinch point exists, the HEN synthesis problem can be decomposed into two
sub-networks; one above and one below the pinch. The sub-network above the pinch
will be denoted by 𝑆𝑁1 and the other by 𝑆𝑁2 . We define 𝐻𝑚,𝑧 and 𝐶𝑚,𝑧 as the set of
hot streams and set of cold streams existing in interval z in 𝑆𝑁𝑚 .
For hot stream, u, the heat balance around temperature interval z is:

𝑟𝑈,𝑍 − 𝑟𝑈,𝑧−1 + ∑ 𝑄𝑈,𝑉,𝑍 = 𝑄 𝐻


𝑈,𝑍 7.14
𝑉
𝑄𝑈,𝑉,𝑍 is the heat exchanged from hot stream u to cold stream v in interval z.
𝑄𝐻𝑈,𝑍 is the heat exchanged from hot stream u in interval z.
Within any sub-network, the heat exchanged between any two streams is bounded by
the smaller of the two heat loads. Therefore, the upper bound on the exchangeable
neat between streams u and v in 𝑆𝑁𝑚 (designated by 𝑈𝑈,𝑉,𝑚 ) is:
𝐶
𝑈𝑈,𝑉,𝑚 = 𝑚𝑖𝑛 (∑ 𝑄 𝐻
𝑈,𝑍 , ∑ 𝑄 𝑉,𝑍 ) 7.15
𝑍 𝑍
𝑄 𝐶𝑈,𝑍 is the heat exchanged from cold stream v in interval z.
The next step is the optimization stage. We define the binary variable 𝐸𝑈,𝑉,𝑚 which
takes the values of 0 when there is no match between streams u and v in 𝑆𝑁𝑚 and
takes the value of 1 when there is a match (and hence the existence of a heat
exchanger).
On the basis of equation 7.15, we can write:
∑𝑧 𝑄𝑈,𝑉,𝑍 ≤ 𝑈𝑈,𝑉,𝑚 𝐸𝑈,𝑉,𝑚 7.16
u ∊ 𝐻𝑚 , v ∊ 𝐶𝑚 , m = 1,2
Where denotes the heat exchanged between the uth hot stream and the vth cold
stream n the zth interval. Therefore the problem of minimizing the number of
pairings between streams (i.e. the number of heat exchangers) can be formulated as a
mixed-integer linear program (MILP) (17):
Minimize ∑𝑚=1,2 ∑𝑢∊𝐻𝑚 ∑𝑣∊𝐶𝑚 𝐸𝑈,𝑉,𝑚 7.17
Subject to the following constraints:
Heat balance for each hot stream around each temperature interval:

173
𝑟𝑈,𝑍 − 𝑟𝑈,𝑧−1 + ∑ 𝑄𝑈,𝑉,𝑍 = 𝑄 𝐻
𝑈,𝑍 7.14
𝑉
Heat balance for each cold stream around each temperature interval:

∑ 𝑄𝑈,𝑉,𝑍 = 𝑄 𝐶𝑈,𝑍 7.18


𝑢
The absence of residual terms 𝑟𝑈,𝑍 𝑎𝑛𝑑 𝑟𝑈,𝑧−1 in equation 7.18 is because the cold
streams have capacities for receiving and not disseminating heat.
Example 7.8 (Network Synthesis of the pharmaceutical facility, example 7.7)
The objective is to determine the minimum number of exchangers satisfying the
minimum utility targets. The solution strategy is as follows [7]:
1. Construct table of exchangeable loads (TEL) for the hot and cold streams over all
temperature intervals.

Table 7.6: Table of exchangeable loads (TEL)


Load of Hot Streams (kW) Load of Cold Streams (kW)
𝐻1 𝐻2 HU(𝐻3 ) 𝐶1 𝐶2 HU(𝐶3 )
Interval
1 0 0 2620 760 0 0
2 1300 0 0 2470 0 0
3 100 0 0 190 20 0
4 500 250 0 950 100 0
5 0 100 0 380 0 0
Pinch
6 0 50 0 0 0 50

2. Construct a table showing the exchangeable loads above and below the pinch.
This done by summing up the loads over the intervals above and below the pinch.

Table 7.7: Exchangeable loads above and below the pinch


Exchangeable Loads above he pinch Exchangeable Loads below he pinch
Stream Load (kW) Stream Load (kW)
𝐻1 1900 𝐻1 0
𝐻2 350 𝐻2 50
HU(𝐻3 ) 2620 HU(𝐻3 ) 0
𝐶1 4750 𝐶1 0
𝐶2 120 𝐶2 0
HU(𝐶3 ) 0 HU(𝐶3 ) 50

174
3. Using the symbol 𝐸𝑈,𝑉,𝑚 establish all the possible matches between the hot and
cold streams for each of the two sub-networks. These possibilities may be
conveniently determined from the CID diagram shown earlier in example 7.7.
Thus we have the following six possible matches above the pinch:
𝐸1,1,1 , 𝐸1,2,1 , 𝐸2,1,1 , 𝐸2,2,1 , 𝐸3,1,1 𝐸3,2,1
Below the pinch we have only one possibility: 𝐸2,3,2
The relevant MATLAB program should into account the fact that the binary
variables: 𝐸1,1,1 , 𝐸1,2,1 , 𝐸2,1,1 , 𝐸2,2,1 , 𝐸3,1,1 𝐸3,2,1 , 𝐸2,3,2 are integer binary variables
which take the value 1 when there is a linkage between a hot and a cold stream, and
takes the value of 0 otherwise.

Figure 7.4: The TID diagram (re-drawn)


4. Write the MATLAB code using the mixed-integer linear optimization
function to minimize the number of stream matches i.e. to minimize the
sum: 𝐸1,1,1 + 𝐸1,2,1 + 𝐸2,1,1 + 𝐸2,2,1 +, 𝐸3,1,1 + 𝐸3,2,1 + 𝐸2,3,2
The energy balances are as follows:
Heat Balance for hot stream H1:
r12 + Q112 = 1300
r13 – r12 + Q113 + Q123 = 100
r14 – r13 + Q114 + Q 124 = 500
r15 – r14 + Q115 = 0
r15 + Q116 + Q 136 = 0
Heat Balance for hot stream H2:
r24 + Q214 + Q 224 = 250
r25 – r24 + Q215 = 100
r25 + Q216 + Q 236 = 50
Heat Balance for heating utility HU1 (Considered as H3):
r31 + Q311 = 2620
r32 – r31 + Q312 = 0
r33 – r32 + Q313 + Q 323 = 0
r34 – r33 + Q314 + Q 324 = 0
r35 – r34 + Q315 = 0

175
r35 = 0
Heat Balance for cold stream C1:
Q311 = 760
Q112 + Q 312 = 2470
Q113 + Q 313 = 190
Q114 + Q 214 + Q 314 = 950
Q115 + Q 215 + Q 315 = 380
Heat Balance for cold stream C2:
Q123 + Q 323 = 20
Q124 + Q 224 + Q324 = 100
Heat Balance for cooling utility CU1 (Considered as C3):
Q236 = 50
Matching of loads:
Q112 + Q113 + Q114 + Q115 <= 1900*E111
Q214 + Q215 <= 350*E211
Q224 <= 120*E221
Q311 + Q312 + Q313 + Q314 + Q315<= 2620*E311
Q323 + Q324 <= 120*E111
Q112 + Q113 + Q114 + Q115 <= 1900*E321
Q236 <= 50*E232
Thus problem at hand contains 38 variables of which 7 are the integer binary variables
referred to above. There are 7 inequality constraints (the matching possibilities) and
22 equality constraints (the energy balances round the intervals).
The programming technique for declaring the integer binary variables (which are the
variables from element 32 to element 38 in the coefficient matrices) is as follows:
First declare variables 32 to 38 as integers:
intcon = 32:38;
Then set a lower bound of 0 and an upper bound of 1 for these binary variables:
lb(32:38)= 0;
ub(32:38) = 1;
For the other variables set the limits as follows:
lb(1:31)= -Inf;
ub(1:31)= Inf;
Example 7.9 Using MATLAB mixed integer linear code (intlinprog function)
The use of [x,fval,exitflag,output] = intlinprog(___), for any input arguments described
above, returns fval = f'*x, a value exitflag describing the exit condition, and a
structure output containing information about the optimization process.
Solve the following problem:
Minimum (−3x1−2x2−x3)
subject to:
x3 binary

176
x1, x2 ≥ 0
x1+x2+x3 ≤ 7
4x1+2x2+x3=12
Write the objective function vector and vector of integer variables.
f = [-3;-2;-1];
intcon = 3;
Write the linear inequality constraints.
A = [1,1,1];
b = 7;
Write the linear equality constraints.
Aeq = [4,2,1];
beq = 12;
Write the bound constraints.
lb = zeros(3,1);
ub = [Inf;Inf;1]; % Enforces x(3) is binary
Call intlinprog.
x = intlinprog(f,intcon,A,b,Aeq,beq,lb,ub)

Solution output from MATLAB:


LP: Optimal objective value is -12.000000.
Optimal solution found.
Intlinprog stopped at the root node because the objective value is within a gap
tolerance of the optimal value;
options.TolGapAbs = 0 (the default value). The intcon variables are integer within
tolerance,
options.TolInteger = 1e-05 (the default value).
x=
0
5.5000
1.0000
7.8.1 Stream Matching Using MATLAB Code
The script MATLAB file containing the program is:
[X,FVAL] = intlinprog(f,intcon,A,b,Aeq,beq,lb,ub)
The following is the complete MATLAB program:
% Mixed-Integer linear program for solving the
%stream matching n the pharmaceutical facility
A = zeros(7,38); % to clear the computer memory
A(1,12)=1;A(1,13)=1;A(1,15)=1;A(1,17)=1;
A(1,32)=-1900;
A(2,20)=1;A(2,22)=1;A(2,33)=-350;

177
A(3,14)=1;A(3,16)=1;A(3,34)=-120;
A(4,21)=1;A(4,35)=-120;
A(5,31)=1;A(5,25)=1;A(5,26)=1;A(5,28)=1;A(5,30)=1;
A(5,36)=-2620;
A(6,27)=1;A(6,29)=1;A(6,37)=-120;
A(7,24)=1;A(7,38)=-50;
b = zeros(7,1);
Aeq=zeros(22,38);
Aeq(1,1)=1;Aeq(1,1)=1;
Aeq(2,2)=1;Aeq(2,1)=-1;Aeq(2,13)=1;Aeq(2,16)=1;
Aeq(3,4)=1;Aeq(3,3)=-1;Aeq(3,17)=1;
Aeq(4,4)=1;Aeq(4,3)=-1;Aeq(4,19)=1;
Aeq(5,4)=1;Aeq(5,18)=1;Aeq(5,19)=1;
Aeq(6,5)=1;Aeq(6,20)=1;Aeq(6,21)=1;
Aeq(7,6)=1;Aeq(7,5)=-1;Aeq(7,22)=1;
Aeq(8,6)=1;Aeq(8,23)=1;Aeq(8,24)=1;
Aeq(9,7)=1;Aeq(9,31)=1;
Aeq(10,8)=1;Aeq(10,7)=-1;Aeq(10,25)=1;
Aeq(11,9)=1;Aeq(11,8)=-1;Aeq(11,26)=1;Aeq(11,27)=1;
Aeq(12,10)=1;Aeq(12,9)=-1;Aeq(12,28)=1;Aeq(12,29)=1;
Aeq(13,11)=1;Aeq(13,10)=-1;Aeq(13,22)=1;
Aeq(14,11)=1;
Aeq(15,31)=1;
Aeq(16,12)=1;Aeq(16,25)=1;
Aeq(17,13)=1;Aeq(17,26)=1;
Aeq(18,15)=1;Aeq(18,20)=1;Aeq(18,28)=1;
Aeq(19,17)=1;Aeq(19,22)=1;Aeq(19,30)=1;
Aeq(20,14)=1;Aeq(20,27)=1;
Aeq(21,16)=1;Aeq(21,21)=1;Aeq(21,29)=1;
Aeq(22,24)=1;
beq =
[1300,100,500,0.0,0.0,250,100,50,2620,0.0,0.0,0.0,0.
0,0.0,760,2470,190,950,380,20,100,50];
%To find the maximum of the objective function you
%should multiply the objective function (f) by -1.
f = [zeros(1,31) ones(1,7)];
% The number of 𝑬𝒊,𝒋,𝒎 variables is 7
%This is a mixed-integer linear programming problem

178
% The variables from 32 to 38 (i.e. the 𝑬𝒊,𝒋,𝒎
%variables)are binary variables which can be either
%0 or 1.
intcon = 32:38;
lb(32:38)= 0;
% When E111 = 0 the the exchaner does not exist
ub(32:38) = 1; % An Exchaner exists when E111 = 1
lb(1:31)= -Inf;
% no lower bound for variables from (1) to (31).
ub(1:31)= Inf;
% no upper bound for variables from (1) to (31).
[X,FVAL] = intlinprog(f,intcon,A,b,Aeq,beq,lb,ub);
X(32:38) % Wrigting the binary-value variables 𝑬𝒊,𝒋,𝒎
Results:
FVAL = 5
ans =
1.0000
1.0000
1.0000
0
1.0000
0
1.0000
Thus the optimum number of exchangers is five.
The five exchangers are: 𝐸1,1,1 , 𝐸1,2,1 , 𝐸2,1,1 , 𝐸3,1,1 , 𝐸2,3,2
The new flow sheet is shown IN Fig 7.6 below.
7.8.2 Stream Matching Using LINGO Software
It is worth noting that there are some specialized software programs that can execute
linear programming problems perhaps more conveniently than the rather laborious
MATLAB code above.
The LINGO code involves writing all the equality and inequality equations as is in the
program. This arrangement is in contrast to the MATLAB code which requires the
provision of the matrix coefficients as shown above. However, The MATLAB code is
concise in setting the upper and lower bounds (ub and lb) but the lingo code is rather
lengthy in this respect and the upper and lower limits of each variable has to be
declared individually. The same observation applies to the declaration of binary
integer variables in the two codes.

179
Figure 7.5: New flow diagram after heat integration

The LINGO program for the pharmaceutical facility is presented below [7]:

Min = E11+E211+E121+E221+E311+E321+E232
! Heat Balance for hot stream H1:
r12 + Q112 = 1300;
r13 – r12 + Q113 + Q123 = 100;
r14 – r13 + Q114 + Q 124 = 500;
r15 – r14 + Q115 = 0;
r15 + Q116 + Q 136 = 0;
! Heat Balance for hot stream H2:
r24 + Q214 + Q 224 = 250;

180
r25 – r24 + Q215 = 100;
r25 + Q216 + Q 236 = 50;
! Heat Balance for heating utility HU1 (Considered as H3):
r31 + Q311 = 2620;
r32 – r31 + Q312 = 0;
r33 – r32 + Q313 + Q 323 = 0;
r34 – r33 + Q314 + Q 324 = 0;
r35 – r34 + Q315 = 0;
r35 = 0;
! Heat Balance for cold stream C1:
Q311 = 760;
Q112 + Q 312 = 2470;
Q113 + Q 313 = 190;
Q114 + Q 214 + Q 314 = 950;
Q115 + Q 215 + Q 315 = 380;
! Heat Balance for cold stream C2:
Q123 + Q 323 = 20;
Q124 + Q 224 + Q324 = 100;
! Heat Balance for cooling utility CU1 (Considered as C3):
Q236 = 50;
! Matching of loads:
Q112 + Q113 + Q114 + Q115 <= 1900*E111;
Q214 + Q215 <= 350*E211;
Q224 <= 120*E221;
Q311 + Q312 + Q313 + Q314 + Q315<= 2620*E311;
Q323 + Q324 <= 120*E111;
Q112 + Q113 + Q114 + Q115 <= 1900*E321;
Q236 <= 50*E232;
! Next all the non-negativities are included in the code:
r12 >=0.0;
r13 >=0.0;
.
.
.
! The binary variables are next declared:
@bin (E111);
@bin (E211);
.
.
.

181
7.9 The Assignment Problem
A special type of optimization problems is the assignment problem. These types of
problems, which are discrete in nature, come under the umbrella of integer
programming problems. Such problems involve the assignment of n people (or
machines or streams...etc) to m jobs (or spaces or units... etc).Each job must be done
by exactly one person; also, each person can do at most one job. The cost of person
(i) doing job (j) is 𝐶𝑖𝑗 .The problem is to assign the people to the jobs at minimum
overall cost.
The decision variables in such problems are binary integer variables. Such variables
are termed “0 – 1” variables and the decision involves, for example, to install or not
install a new piece of equipment. When the binary integer variable is assigned a value
of (1), that means the event or option regarding that variable is true (for a (0) value,
the assignment is false).
If in a selection process a binary integer variable (𝑋𝑖 ) is defined to take the value of 1
when the option is selected and zero when it is not, then the constraints may include
the following constraints [6]:
First constraint:
Selection of exactly one option from a set of N options (i.e. the selection is exclusive).
The arrangement can be expressed mathematically as follows:
𝑁

∑ 𝑋𝑖 = 1
𝑖=1
Second constraint:
Selection of at least one option from the set of available options.
The arrangement can be expressed mathematically as follows:
𝑁

∑ 𝑋𝑖 ≥ 1
𝑖=1
Third constraint:
Selection of option V if option U is chosen (i.e. an implication case):
𝑋𝑉 ≥ 𝑋𝑈
Fourth constraint:
Selection of option U if and only if option V is chosen (i.e. an equivalence case):
𝑋𝑉 = 𝑋𝑈
Example 7.10 (An illustrative case of the assignment problem [17])
The following matrix shows the task of assigning streams to heat exchangers and the
cost (in some measure) of doing so.
Each element in the matrix represents the cost of matching stream i with exchanger j.
The task is to minimize the total cost of assignments if each stream goes to only one
exchanger.

182
Table 7.8: Stream and exchanger data for example 7.10
Exchanger Number
1 2 3 4
A 94 1 54 68
Stream B 74 10 88 82
C 73 88 8 76
D 11 74 81 21

The mathematical formulation of the problem is as follows:


Let n represent the total number of streams i.e. n = 4.
Let 𝐶𝑖𝑗 be an element of the cost matrix which is the cost of assigning stream i to
exchanger j.
Let 𝑥𝑖𝑗 be the event of the assignment of stream i to exchanger j. 𝑥𝑖𝑗 = 1 when this is
true and 𝑥𝑖𝑗 = zero if not. Let total number of streams and exchangers be n and m
respectively.
Then we have the following integer programming problem:
𝑛 𝑚
Minimize f(x) = ∑𝑖=1 ∑𝑗=1 𝐶𝑖𝑗 𝑥𝑖𝑗
The constraints are:
Each exchanger (𝑗) can take only one stream:
∑𝑛𝑖=1 𝑥𝑖𝑗 = 1 j = 1,...,m
Each stream (𝑖 ) can go to only one exchanger:
∑𝑚 𝑗=1 𝑥𝑖𝑗 = 1 i = 1,...,n
𝑥𝑖𝑗 = 0,1 i,j = 1,...,n!
For the above problem 4! = 24 possible assignments exist.
Solution:
The optimization objective function (f) is the total cost of all assignments:
𝑛 𝑚
Minimize f(x) = ∑𝑖=1 ∑𝑗=1 𝐶𝑖𝑗 𝑥𝑖𝑗
f=[94;1;54;68;74;10;88;82;73;88;8;76;11;74;81;21];
%Write the coefficients of the linear equality
%constraints:
Aeq =[1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0
0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0
0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0
0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1
1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0
0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0

183
0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0
0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1];
beq = [1,1,1,1,1,1,1,1]';
intcon = 1:16; % All the 16 decision variables are
% declared as integers
lb(1:16)= 0;
% The lower bound (lb) of each of the 16 decision
% variables is declared as zero
ub(1:16) = 1;
% The upper bound (ub) of each of the 16 decision
%variables is declared as equal to one
% The above declarations ensure that each of the 16
%decision variables is binary
%Call function intlinprog
[X,FVAL] = intlinprog(f,intcon,[],[],Aeq,beq,lb,ub)

Ans:
LP: Optimal objective value is 30.000000.
Optimal solution found.
Intlinprog stopped at the root node because the objective value is within a gap
tolerance of the optimal value, options. TolGapAbs = 0 (the default value).
The intcon variables are integer within tolerance options.
TolInteger = 1e-05 (the default value).
X=
0
1
0
0
0
1
0
0
0
0
1
0
1
0
0
0
FVAL = 30

184
Example 7.11 (Reactor assignment to places in a plant)
Four new reactors (R1, R2, R3, R4) are to be installed in a plant. There are four
vacant spaces. The following table shows the cost of assigning reactor i to space j.
Assign the reactots to spaces so as to minimize total cost.
Table 7.9: Cost data for example 7.11
Assignment Costs ($MM)
Space 1 Space 2 Space 3 Space 4
R1 15 11 13 15
Reactor R2 13 9 12 17
R3 14 15 10 14
R4 17 13 11 16
Solution:
Let binary variable 𝑥𝑖𝑗 refer to the event of assigning reactor 𝑖 to space 𝑗.
Let 𝐶𝑖𝑗 be the cost of assigning reactor 𝑖 to space 𝑗.
𝑛 𝑚
Minimize total assignment cost = ∑𝑖=1 ∑𝑗=1 𝐶𝑖𝑗 𝑥𝑖𝑗
Regarding reactors; the job of the placement of each reactor must be done, therefore
we have the following constraint:
∑𝑚𝑗=1 𝑥𝑖𝑗 = 1 for all reactors j=1,...,m
Regarding available spaces; because each space cannot take more than one reactor, we
have the following constraint:
∑𝑛𝑖=1 𝑥𝑖𝑗 = 1 for all spaces i=1,...,n
In such cases when the number of available spaces exceeds the number of reactors,
and therefore not all spaces will be used, then the constraint on spaces should include
the relative mathematical operator ≤ as follows:
∑𝑛𝑖=1 𝑥𝑖𝑗 ≤ 1 for all spaces i=1,...,n
The solution of example 7.11 is left to the student as part of the exercises at the end of
this chapter.
7.10 The Transportation Problem
In the general transportation-type problem, the objective is to minimize the total cost
of transporting commodities from sources (e.g. manufacturers) to destinations (e.g.
consumers). It is thus a problem of optimal allocation of the transportation of a
commodity between suppliers and consumers while meeting the requirements of the
consumers.
Example 7.12 (Allocation of commodities from sources to destinations)
Three bio-refineries are located in towns A, B, and C. Hexane can be supplied to the
refineries from four different production facilities located at locations 1,2,3, and 4.
The tables below show the daily hexane requirements of the bio-refineries, the
production capacities of the hexane suppliers, and the transportation costs.

185
Table 7.10: Daily Hexane Requirements of the Refineries
Bio-refinery Daily Hexane Requirements (ton)
A 6
B 1
C 10
Table 7.11: Daily Production Capacities of the Hexane Suppliers
Production Facilities Daily Production (ton)
1 7
2 5
3 3
4 6
Table 7.12: Transportation Costs ($/ton)
Supplier Consuming Consuming Consuming
Refinery A Refinery B Refinery C
1 20 10 50
2 30 0 80
3 110 60 150
4 70 10 90

Figure 7.6: The supplier-consumer network

The terms referring to quantities transported from from each supplier to each bio-
refinery is shown in the table below.

186
Table 7.13: Terms used for transported quantities
Supplier Consuming Consuming Consuming
Refinery A Refinery B Refinery C
1 X1A X1B X1C
2 X2A X2B X2C
3 X3A X3B X3C
4 X4A X4B X4C

Thus there are twelve decision variables.


Objective function is the minimization of total transportation costs:
Minimize = 20*X1A+10*X1B+50*X1C+30*X2A+ 0*X2B+80*X2C+110*X3A+
60*X3B+150*X3C+70*X4A+10*X4B+90*X4C
The constraints are:
Hexane demand constraints from bio-refineries:
X1A + X2A + X3A + X4A = 6
X1B + X2B + X3B + X4B = 1
X1C + X2C + X3C + X4C = 10
Hexane production limitations from suppliers:
X1A + X1B + X1C <= 7
X2A + X2B + X2C <= 5
X3A + X3B + X3C <= 3
X4A + X4B + X4C <= 6
The relavant MATLAB program is:
f = [20;10;50;30;0;80;110;60;150;70;10;90];
%Write the linear in-equality constraints.
A = [1,1,1,0,0,0,0,0,0,0,0,0
0,0,0,1,1,1,0,0,0,0,0,0
0,0,0,0,0,0,1,1,1,0,0,0
0,0,0,0,0,0,0,0,0,1,1,1];
b = [7,5,3,6]';
%Write the linear equality constraints.
Aeq = [1,0,0,1,0,0,1,0,0,1,0,0
0,1,0,0,0,0,0,1,0,0,1,0
0,0,1,0,0,1,0,0,1,0,0,1];
beq = [6,1,10]';
lb(1:12)= 0;
ub(1:12) = inf;
%Call linprog
[X,FVAL] = linprog(f,A,b,Aeq,beq,lb,ub)
Results:
X=

187
1.0000
0.0000
6.0000
5.0000
0.0000
0.0000
0.0000
0.0000
0.0000
0.0000
1.0000
4.0000
FVAL =
840.0000
7.10.1 The Transportation formulation using LINGO software
The LINGO software formulation is as follows [7]:
Min = 20*X1A+10*X1B+50*X1C+30*X2A+ 0*X2B+80*X2C+110*X3A+
60*X3B+150*X3C+70*X4A+10*X4B+90*X4C;
! Hexane demand constraints from bio-refineries:
X1A + X2A + X3A + X4A = 6;
X1B + X2B + X3B + X4B = 1;
X1C + X2C + X3C + X4C = 10;
! Hexane production limitations from suppliers:
X1A + X1B + X1C <= 7;
X2A + X2B + X2C <= 5;
X3A + X3B + X3C <= 3;
X4A + X4B + X4C <= 6;
! Non-negativity constraints:
X1A >= 0;
X1B >= 0;
X1C >= 0;
X2A >= 0;
X2B >= 0;
X2C >= 0;
X3A >= 0;
X3B >= 0;
X3C >= 0;
X4A >= 0;
X4B >= 0;
X4C >= 0;

188
Exerccises
7.1 The total annual cost of operating a pump and motor (C) in a particular piece of
equipment is a function of x (the size (i.e. horsepower) of the motor), as follows:
𝐶 = $500 + $0.9𝑥 + $(0.03/𝑥)(150000)
Find the motor horsepower that minimizes the total annual cost.
A laboratory filtration study showed that filtration time can be expressed as a function
of the following parameters [17]):
𝛥𝑃𝐴2
𝑇 =𝛽 𝑥𝑒𝑥𝑝(−𝑎𝑥 + 𝑏)
𝜇𝑀2 𝐶
Where:
𝑇 = filtration time (i.e. time to build up the filter cake)
𝛥𝑃 = pressure drop across cake, psig (20)
𝐴 = filtration area, ft 2(250)
𝜇 = filtrate viscosity, centipoises (20)
𝑀 = mass flow of filtrate lab/min (75)
𝐶 = solids concentration in feed to filter, lab/lab filtrate (0.01)
𝑥 = mass fraction of solids in dry cake
𝑎 = constant relating cake resistance to solids fraction (3.643)
𝑏 = constant relating cake resistance to solids fraction (2.680)
𝛽 = 3.2*10-8 (lab/ft) 2
Obtain the maximum time for filtration time as a function of x.

7.2 For the above filtration problem, plot the variation of maximum time (T) against
pressure drop over the range:
5 =< 𝛥𝑃 <= 30

7.3 (Heat Transfer: Optimizing recovery of waste heat, [17])


A variety of sources of heat at elevated temperatures exist in a typical chemical plant
that may be economically recoverable for production of power using steam or other
working fluids such as Freon or light hydrocarbons. The system power output can be
increased by using larger heat exchanger areas for both the boiler and the condenser.
However there will be a trade-off between power recovery and the capital cost of the
exchangers.
If Q is expressed in Btu/h, and the operating cost is C, then the value of the available
power is:
𝑇2 𝑇2
𝐶 = 𝐶𝐻 𝜂𝑦𝑄 ( − )
𝑇𝐻 𝑇𝑆
Where
η = Overall system efficiency (0.7 is typical)
y = Number of hours of per year of operation
CH = Value of the power in $/kWh

189
T2 = Condenser temperature
TH = Working fluid temperature
TS = Hot fluid temperature
It is clear from above equation that the operating cost (C) is minimized by setting
𝑇𝐻 = 𝑇𝑆 (i.e. infinitesimal boiler𝛥𝑇 = (𝑇𝑆 − 𝑇𝐻 ). However, this outcome would
increase the required boiler heat transfer area to an infinite area as can be noted from
the calculation for the area
𝑄
𝐴=
𝑈(𝑇𝑆 − 𝑇𝐻 )
Where U is the Overall heat transfer coefficient (assumed constant).
Let cost per unit area of the exchanger be 𝐶𝐴 and the annualized factor for the capital
investment be (r). Then the annualized capital cost for the boiler is (depreciation):
𝐶𝐴 𝑄𝑟
dep =
𝑈(𝑇𝑆 − 𝑇𝐻 )
The objective function to be minimized (with respect to the working fluid temperature
𝑇𝐻 is total operating cost i.e. the sum of the operating cost (C) and the depreciation
cost (dep):
𝑇2 𝑇2 𝐶𝐴 𝑄𝑟
Ф = 𝐶𝐻 𝜂𝑦𝑄 ( − ) +
𝑇𝐻 𝑇𝑆 𝑈(𝑇𝑆 − 𝑇𝐻 )
Show that the optimum value of fluid temperature is 760.7 OR , giving a boiler
𝛥𝑇(𝑇𝑆 − 𝑇𝐻 ) of 29.3OR.
The system has the following parameters: 𝐶𝐴 = $25/ft2, Power cost = $0.06/kWh
(𝐶𝐻 = 1.76 ∗ 10−5 ), U = 95 Btu/(h)(OF)(ft2), 𝑦 = 8760 h/year, r = 0.365, 𝜂 = 0.7, 𝑇2 =
600OF, and 𝑇𝑆 = 600OF.

7.4 For above system plot total operating cost versus boiler ΔT as 𝑇𝑆 is varied from
500OF to 700OF.

7.5 A sieve-plate distillation column is being designed to handle 318 kg mol of feed
per hour.
The annual variable costs are those due to the column, condenser, reboiler, cooling
water, and steam.
The following data gives the variable costs of the column, condenser, and reboiler (in
$/year) as a function of reflux ratio (R):
Column variable cost = (0.35 – 1.24*R+ 1.23*𝐑2 )*105
Condenser variable cost = (-0.086 +1.68*R + 3.82*𝐑2 )*103
Reboiler variable cost = (-0.4 4.16*R+ 7.68*𝐑2 )*103
The cooling water and steam variable costs (in $/year) are known in tabular form as
follows:

190
Table 7.14: Cooling water and steam costs
Reflux ratio(R) Cooling water cost Steam cost
1.2 17,820 136,500
1.3 18,600 142,500
1.4 19,410 148,800
1.5 20,220 155,100
1.7 21,870 167,100
2.0 24,300 185,400

It is desired to estimate the optimum reflux ratio (as moles liquid returned to tower
per mole of distillate product withdrawn).
Hint: There are two strategies for tackling above problem: Either convert the three
correlations into tabular form or develop two correlations from the tabular data using
polyfit function.

7.6 A tank containing 1500 m3 of naphtha is to be blended with two other


hydrocarbon streams to meet the specifications for gasoline. The final product must
have:
A minimum research octane number (RON) of 95
A maximum Reid Vapor Pressure (RVP) of 0.6 bar
A maximum benzene content of 2%
A maximum total aromatics of 25%
The properties and costs of the three streams are given in table 7.15:
Assuming that the properties of the mixture blend are in proportion to the volume of
the stream used, how much reformate and alkylate should be blended to minimize
cost?
Table 7.15: Blend ingredients data
RON RVP(bar) Benzene Total Aromatics Cost
(% vol) (% vol) $/ m3
Naphtha 92 0.80 1.5 15 275
Reformate 98 0.15 50 50 270
Alkylate 97.5 0.30 0 0 350

7.7 A refinery has available two types of crude oil that have the yields shown in the
following table. Because of seasonal limitations on market demand, production of
gasoline, kerosene, and fuel oil must be limited as shown. There no production
limitations on gas oils.
Determine the optimum daily amount of each crude type to be processed.

191
Table 7.16: Refinery data
Volume percent Maximum allowable production
yield bbl/day
Crude Crude
A B
Gasoline 70 30 6,000
Kerosine 6 10 2,400
Fuel Oil 24 66 15,000
Profit on processing 1.00 0.70 -
($/bbl)

7.8 A fertilizer company mixes three different types of chemicals in their Premium
blend which sells for $1.00 per kilogram. The regular blend sells for $0.80 per
kilogram. The mixing formulae for both blends is shown below.

Table 7.17: The mixing formulae for the blends


Chemicals
Blends Type A Type B Type C
Premium 10% 5% 5%
Regular 0% 15% 5%
Amount available, kg 400 300 500

The remainder of each blend is inert filler material which costs $0.10. An unlimited
supply of filler is available.
The cost per kilogram of type A, type B, and type C chemicals is $0.30, $0.25, $0.20
respectively. Determine the optimal amounts of each blend that should be prepared
when:
(a) Leftover chemicals can be used again.
(b) Leftover chemicals cannot be used again.
7.9 A company intends to mix biodiesel and petro-diesel to produce a cost-effective,
technically viable, and environmentally friendly fuel. The table below gives the data
regarding the available biodiesel and petro-diesel to be mixed. These data include the
cost of each type of fuel, the heating value, and the extent of greenhouse gas (GHG)
emission upon combustion. The densities of both fuels are assumed to be the same.
For technical considerations, the heating value of the blend should not be less than
119,500 Btu/gal. For environmental reasons, the GHG emission associated with
burning the blend should not exceed 6540 gm CO2 /gal. What is the optimal mixing
ratio of the two fuels that will minimize the cost of the fuel blend ($/gal) satisfying the
technical and environmental constraints.

192
Table 7.18: The two diesel characteristic data
Characteristic Biodiesel Petro-diesel
Cost ($/gal) 3.80 3.20
Heating Value (Btu/gal) 117,000 129,000
GHG emission (gm CO2 /gal) 2100 9500

7.10 (Assignment problem)


Four streams are to be allocated to four extractors. The costs of each stream are:
Table 7.19: Costs of matching streams and heat exchangers
Extractor
Stream 1 2 3 4
1 45 P 5 56
2 27 2 82 74
3 19 55 3 P
4 3 10 4 84

The symbol P means the assignment is prohibited.


Formulate the problem and write a computer code for minimizing the total costs.

7.11 Solve example 7.11

7.12 Four new reactors (R1, R2, R3, R4) are to be installed in a plant. There are six
vacant spaces. The following table shows the cost f assigning reactor i to space j.
Assign the reactors to spaces so as to minimize total cost.

Table 7.20: Costs for assignment of reactors to spaces


Assignment Costs ($MM)
Space Space Space
Space 1 Space 2 Space 3
4 5 6
Reactor R1 15 11 13 15 10 12
R2 13 9 12 17 11 9
R3 14 15 10 14 15 16
R4 17 13 11 16 16 8

7.13 A polymer plant consists of two production lines that yield two polymer
products: A and B [6]. Both lines use the same monomer (M) as a feedstock. Due to
the formation of by-products and product losses, each ton produced of either polymer
requires four tons of M. The maximum supply of monomer M to the plant is 45
tons/hr. The process requires refrigeration and heating. The table below lists the

193
consumption of these utilities required for both products in units of MW/ton per
hour of produced polymer.

Table 7.21: Utility requirements


Utility Polymer A Polymer B
Refrigeration 5 3
Heating 5 6

Available for service are 60 MW of refrigeration and 75 MW of heating. The net


profits for processing A and B are 1000 and $1500/ton produced respectively.
What is the optimal production rate that will maximize the net profit of the plant?

7.14 A major oil company wants to build a refinery that will be supplied from three
port cities [6]. Port B is located 300 km east and 400 km north of port A. Port C is
400 km east and 100 km south of port B. Determine the location of the refinery so
that the total amount of pipe required to connect the refinery to the ports is
minimized.

7.15 (Use of LP to optimize a separation train. [17])


The feed to a solvent splitter is naphtha which has a value of $42/bbl in its alternate
use as a gasoline blending block. The light ends sell at $53/bbl while the bottoms are
passed through a second distillation column to yield two solvents: A medium solvent
comprising 50 to 70 percent of the bottoms and can be sold for $68/bbl, while the
remaining heavy solvent (30 to 50 percent of the bottoms) can be sold for $42/bbl.
Another part of the plant requires 200 bbl/day of medium solvent; an additional 200
bbl/day can be sold to an external market. The maximum feed that can be processed
in column 1 is 2000 bbl/day. The operational costs (i.e. utilities) associated with each
distillation column are $1.25/bbl. The operating range for column 2 is given as
percentage split of medium and heavy solvent.
Formulate the problem as linear programming problem by developing the objective
function and constraints.
Solve the problem to get the maximum revenue and percentages of the output
streams in column 2.

194
Figure 7.7: Separation train for problem 7.15

7.16 Solve problem 7.15 by expressing the five variables shown in the Figure as
functions of two independent variables 𝑥4 and 𝑥5 .

7.17 Three biodiesel-manufacturing plants (𝑆1 , 𝑆2 ,and 𝑆3 ) are used to provide four
customers (𝐶1 , 𝐶2 , 𝐶3 , and 𝐶4 ) with their biodiesl requirements [7]. The yearly
capacities of suppliers 𝑆1 , 𝑆2 , and 𝑆3 are 135, 56, and 93 MM gal/year, respectively.
The yearly requirements of the consumers 𝐶1 , 𝐶2 , 𝐶3 , and 𝐶4 are 62, 83, 39, and 91
MM gal/ear, respectively. Table 7.6 Gives the unit costs ($/gal) for supplying each
customer from each supplier. A dash in the table indicates the impossibility of certain
supplies for certain customers.
What are the optimal transportation quantities from suppliers to customers that will
minimize the total transportation cost?

7.18 A juice manufacturing factory has received an order for 1000 liters of juice with
the constraint that the juice must contain 4% nectar by volume. However no 4%
nectar juice is in stock. The factory owner wishes to mix two juice brands in stock (A
and B juice brands) to meet the order. Juice (A) contains 4.5% nectar by volume and
costs $0.33 per liter. Juice (B) contains 3.8% nectar by volume and is valued at $0.25
per liter. Water can be added to the blend at no cost. What volume combination of
the two juice brands in stock will give the required stock including at least 100 liters of
juice A.

195
196
CHAPTER

8
8.1 Symbolic Variables
Symbolic Mathematics in
MATLAB

MATLAB uses many data types such as floating-point numeric data, character data,
logical data, and symbolic data [15].
Symbolic Variables are those variables that don’t have specific numerical values when
the operation is executed. The results of such operations are also a mathematical
expression in terms of the symbolic variables.
8.2 Declaration of symbolic variables
Variable x as symbolic can be done in two ways:
sym ('x')
Or
syms x
A group of variables can declared symbolic in one line:
syms x a b c
8.3 Symbolic Commands
The double command converts symbolic matrix to MATLAB numeric form; Syntax:
r = double(S) converts the symbolic object S to a numeric object r.
Input Arguments (S):
S is a symbolic constant, constant expression or symbolic matrix whose entries are
constants or constant expressions.
Output Arguments(r):
If S is a symbolic constant or constant expression, r is a double-precision floating-point
number representing the value of S. If S is a symbolic matrix whose entries are
constants or constant expressions, r is a matrix of double precision floating-point
numbers representing the values of the entries of S.
Example 8.1
𝟏+√𝟓
Find the numeric value for the expression :
𝟐
double (sym('(1+sqrt(5))/2'))
ans = 1.6180
The collect command collects the terms in the expression that have the variable with
the same power:
syms x y

197
f = (2*x^2+y^2)*(x+y^2+3)
f =
(2*x^2 + y^2)*(y^2 + x + 3)
collect(f)
ans = 2*x^3 + (2*y^2 + 6)*x^2 + y^2*x + y^2*(y^2 + 3)
However, if we take y as the symbolic variable:
collect (f,y)
ans = y^4 + (2*x^2 + x + 3)*y^2 + 2*x^2*(x + 3)
The factor command changes a polynomial into a product of polynomials of lower
degree:
f = x^3 - 3*x^2 - 4*x + 12;
factor (f)
ans =
[ x - 3, x + 2, x - 2]
ans =(x - 3)*(x + 2)*(x - 2)
The expand command multiply expressions:
f = (x^3 - 3*x^2 - 4*x + 12)*(x - 3)^3;
expand(f)
ans = x^6 - 12*x^5 + 50*x^4 - 60*x^3 - 135*x^2 + 432*x - 324
The simplify command generates a simpler form of the expression:
f = (x^3 - 3*x^2 -4*x + 12)/(x - 3)^3;
simplify(f)
ans = (x^2 - 4)/(x - 3)^2
The simple command generates a form of the expression with the fewest number of
characters:
f=cos(x)*cos(y) + sin(x)*sin(y);
simple(f)
ans = cos(x - y)
The pretty command displays a symbolic expression in a type-written text format:
f = sqrt(x^3 - 3*x^2 - 4*x + 12);
pretty(f)
sqrt(𝑥 3 - 3𝑥 2 - 4𝑥 + 12)
The findsym command displays what symbolic variables are used in an expression:
>>syms a b c x y z
>>f1 = a*x^2 + b*x + c;
>>f2 = x*y*z;
>>findsym(f1)
ans = a,b,c,x
>>findsym(f2)
ans = x,y,z

198
The is numeic command checks the data type of a variable. If variable type is
numeric, MATLAB returns an answer of 1. If data type is symbolic, MATLAB
returns an answer of 0.
>>x = 10;
>>isnumeric(x)
ans = 1
>>syms x
>>isnumeric(x)
ans = 0
The command clear clears the memory of all variables, and symbolic variables will
need to be redefined as symbolic.
The subs command is used to substitute a numerical value for a symbolic variable.
For instance to substitute the value x = 2 in an expression f:
>>f = x^3*y + 12*x*y + 12;
>>subs(f,2)
ans = 32*y + 12
Note that if we do not specify a variable to substitute for, MATLAB chooses a default
variable according to the following rule: For one letter variables, MATLAB chooses
the letter closest to x in the alphabet.
To substitute y = 3 in above example:
>> subs(f,y,3)
ans = 3*x^3 + 36*x + 12
To determine the default variable in an expression, use the findsym command:
>>syms u v
>>f = u*v;
>>findsym(f,1)
ans = v
8.4 Symbolic Equation Solving
We can use the solve command to solve the nonlinear equation:
>> f = x^3 - 2*x -1;
>> f = x^3 - 2*x - 1;
>> solve(f)
ans =
-1
1/2 - 5^(1/2)/2
5^(1/2)/2 + 1/2
The answer above consists of the exact (symbolic) solutions. To get numerical
solutions, type double(ans):
>> double(ans)
ans =
-1.0000

199
-0.6180
1.6180
The solve command can also be used to solve simultaneous algebraic equations:
>> [x,y] = solve('3*x+3*y=2','x+2*y^2=1')
x=
33^(1/2)/12 + 5/12
5/12 - 33^(1/2)/12
y=
1/4 - 33^(1/2)/12
33^(1/2)/12 + 1/4
Note that both solutions can be extracted with x(1), y(1), x(2), and y(2). For instance,
type:
>> x(1)
ans = 33^(1/2)/12 + 5/12
>> y(1)
ans = 1/4 -33^(1/2)/12
Numeric solutions can be extracted with the double command as outlined before:
>> double(x(1))
ans = 0.8954
>> double(y(1))
ans = -0.2287
If we want to solve x + xy2 + 3xy for y in terms of x, then we have to specify the
equation as well as variable y as a string:
syms x y
solve('x+x*y^2+3*x*y=3','y')
ans =
-(3*x - (x*(5*x + 12))^(1/2))/(2*x)
-(3*x + (x*(5*x + 12))^(1/2))/(2*x)
8.4.1 Symbolic Differentiation
The diff command is used to perform symbolic differentiation of function f. For
instance:
>>syms x
>>f = x^3 + 3*x^2 + 20*x -12;
>>diff(f)
ans = 3*x^2 + 6*x + 20
If function f is a function of several variables we can use the command:
>>diff(f,var)
In such a case, MATLAB differentiates f with respect to x (default symbolic variable) .
If
2
𝑓 = 𝑥 3 + 𝑥𝑙𝑛𝑦 + 𝑦𝑒 𝑥
Then

200
>>syms x y
>>f = x^3 + x*log(y) + y*exp(x^2);
>>diff(f)
ans = log(y) + 3*x^2 + 2*x*y*exp(x^2)
2
If we want to differentiate 𝑥 3 + 𝑥𝑙𝑛𝑦 + 𝑦𝑒 𝑥 with respect to y, then we use the
MATLAB diff(f,y):
>> f = x^3 + x*log(y) + y*exp(x^2);
>>diff(f,y)
ans = exp(x^2) + x/y
To find the numerical value of the symbolic expression use the MATLAB subs
2
command. For instance, to find the derivative of 𝑓 = 𝑥 3 + 𝑥𝑙𝑛𝑦 + 𝑦𝑒 𝑥
at x= 2, we do the following:
>> f = x^3 + 3*x^2 + 20*x -12;
>>df = diff(f);
>>subs(df,x,2)
ans = 44
The diff command can be extended to second and higher derivatives. To find the nth
derivative:
>>diff(f,n)
To find the nth derivative with respect to variable (var):
>>diff(f,var,n)
2
For instance, to find the second derivative of 𝑓 = 𝑥 3 + 𝑥𝑙𝑛𝑦 + 𝑦𝑒 𝑥 with respect to y:
>> f = x^3 + x*log(y) + y*exp(x^2);
>>diff(f,y,2)
ans = -x/y^2
8.4.2 Symbolic Integration
The command int can be used to determine indefinite and definite integrals of
expression f.
8.4.2.1 Indefinite integrals
int(f) when the expression contains one symbolic variable. If the expression contains
more than one symbolic variable, then the integration is performed with respect to the
default symbolic variable. The command: int(f,var) will perform the integration with
respect to variable var.
2
To find the indefinite integral of the expression: 𝑓 = 𝑥 3 + 𝑥𝑙𝑛𝑦 + 𝑦𝑒 𝑥 we use the
MATLAB command:
>>syms x y
>>f = x^3 + x*log(y) + y*exp(x^2);
>>int(f,y)
ans = (y*(y*exp(x^2) - 2*x + 2*x*log(y) + 2*x^3))/2

201
8.4.2.2 Definite integrals
The command int(f,a,b) is used to find the integral of function f between the limits of
integration a and b. Limits a and b can be numbers or symbolic variables.
The command int(f,var,a,b) is used to find the integral of function f between the limits
of integration a and b with respect to variable var.
>>syms x y
>>f = x^2 + 3*exp(x) + x*log(y);
>>int(f,0,1)
ans = 3*exp(1) + log(y)/2 - 8/3
8.5 Symbolic Ordinary Differential Equations
The dsolve command solves a single symbolic differential equation or a system of
differential equations. For first-order differential equation, we use:
>>dsolve(‘eq’)
Or
>>dsolve(‘eq’,’var’)
For finding the general solution of the following ODE:
𝑑𝑦 3𝑦
=𝑡+
𝑑𝑡 𝑡
we use the following commands:
>>syms t y
>>f = t + 3*y/t;
>>dsolve('Dy=f')
ans = C3 + f*t
Example 8.2 (Solution of initial value ODE)
Solve the following initial value differential equation:
𝑑𝑦 3𝑦
=𝑡+
𝑑𝑡 𝑡
with the initial condition y(1) = 4
Solution:
>>syms ty
>>f = t + 3*y/t;
>>dsolve('Dy=f','y(1)=4','t')
ans = f*t - f + 4
Similarly, a higher order ODE can be solved symbolically using the following
command: dsolve(‘eq’,’cond1’,’cond2’,…,’var’).
Example 8.3 (Solution of second-order ODE)
Find the solution of the second-order ODE:
𝑑2𝑦 𝑑𝑦
− 4 − 5𝑦 = 0, 𝑦(1) = 0, 𝑦 ′ (1) = 2
𝑑𝑥 2 𝑑𝑥
>>syms x y

202
>>dsolve('D2y - 4*Dy - 5*y =
0','y(1)=0','Dy(1)=2','x')
ans = (exp(5*x)*exp(-5))/3 - (exp(-x)*exp(1))/3
8.6 Plotting symbolic expressions
The ezplot command is used to plot symbolic expressions. To plot a symbolic
expression Z that contains one or two variables:ezplot(Z) orezplot(Z,[min,max])
Or ezplot(Z,[xmin,xmax,ymin,ymax])
Example 8.4 (Plotting a graph of symbolic expression)
Plot a graph of the symbolic expression:
2 ∗ 𝑥2 + 2
𝑍=
𝑥 2 – 64
>>syms x
>>Z = (2*x^2+2)/(x^2-64);
>>ezplot(Z)
(2 x 2 + 2)/(x 2 - 64)

-0.5

-1

-1.5

-2

-2.5

-3

-3.5
-6 -4 -2 0 2 4 6
x

Figure 8.1 Plot for example 8.4


Example 8.5 (Plotting a function given in parametric form)
Given:
x = cos(2*t);
y = sin(4*t);
Plot x versus y.
Solution:
>>syms t
>>x = cos(2*t);
>>y = sin(4*t);
>>ezplot(x,y)

203
x = cos(2 t), y = sin(4 t)

0.8

0.6

0.4

0.2

y
-0.2

-0.4

-0.6

-0.8

-1 -0.5 0 0.5 1
x

Figure 8.2 Plot for example 8.5

204
Exercises
8.1 The heat capacity of nitrogen gas (in kJ/kmol.K)is modeled as a function of
temperature in degrees Kelvin as follows:
𝐶𝑃 = 𝑎 + 𝑏𝑇 + 𝑐𝑇 2 + 𝑑𝑇 3
Use symbolic mathematics to solve the above equation for T if the heat capacity (𝐶𝑃 )
is equal to 29.15 kJ/kmol.K

8.2 The Antoine equation uses empirical constants to model the vapor pressure of a
gas as a function of temperature as follows:
𝐵
𝑙𝑜𝑔10 (𝑃) = 𝐴 −
𝐶+𝑇
Where
P = pressure, in mmHg
T = Temperature in OC
A, B,C = empirical constants
The normal boiling point of a liquid is the temperature at which the vapor pressure
(P) of the gas is equal to atmospheric pressure, 760 mmHg. Use MATLAB’s
symbolic capability to find the normal point of benzene if the empirical constants are:
A = 6.89272
B = 1203.531
C = 219.888

8.3 Solve the following two equations using symbolic and numeric MATLAB
capabilities:
𝑥 2 + 𝑦 2 = 42
𝑥 + 3𝑦 + 2𝑦 2 = 6

8.4 Determine the first and second derivatives of the following functions using
MATLAB symbolic functions:
(a)𝑦 = 𝑥 4 − 3 𝑥 2 + 5 𝑥 − 13
(b)𝑦 = (𝑥 2 − 6𝑥 + 8)(𝑥 − 3)

8.4 With reference to question (1), where the heat capacity of nitrogen gas (in
kJ/kmol.K) is modelled as a function of temperature in degrees Kelvin as follows:
𝐶𝑃 = 𝑎 + 𝑏𝑇 + 𝑐𝑇 2 + 𝑑𝑇 3
Use symbolic mathematics to calculate the change in the enthalpy (ΔH) of 50 moles
of nitrogen gas as it is heated from 300 to 1000K.
Note that:
𝑇2
𝛥𝐻 = ∫ 𝐶𝑃 𝑑𝑇
𝑇1

205
8.5 Use ezplot to graph the following implicit functions
(a)𝑥 2 + 𝑦 3 = 0
(b) 𝑥 + 𝑥 2 − 𝑦 = 0

8.6 Use ezplot to graph the following expressions on the same Figure for x values fro,
-2π to 2π:
𝑦1 = sin(𝑥)
𝑦2 = sin(2𝑥)
𝑦3 = sin(3𝑥)
8.7 A batch reactor has the following reacting system:
𝐴+𝐵 →𝐶
𝐶+𝐵 → 𝐷
𝑑𝐶𝐴 𝑑𝐶𝐵 𝑑𝐶𝑐 𝑑𝐶𝐷
= −𝑟1 , = −𝑟1 − 𝑟2 , = 𝑟1 − 𝑟2 , = 𝑟2
𝑑𝑡 𝑑𝑡 𝑑𝑡 𝑑𝑡
𝑟1 = 𝑘1 𝐶𝐴 𝐶𝐵 𝑟2 = 𝑘2 𝐶𝐶 𝐶𝐵
𝑘1 = 1.0, 𝑘2 = 0.5
𝐶𝐴0 = 1, 𝐶𝐵0 = 2, 𝐶𝐶0 = 0, 𝐶𝐷0 = 0
Use ezplot to plot the concentration profiles of the reactor over the specified time
span of t_end = 10.

206
CHAPTER

9
9.1 Introduction
Simulink

Simulink is an interactive, graphic-based program that allows you to solve problems by


creating models using a set of built-in blocks. Simulink is designed to provide a
convenient method for analyzing complex dynamic systems, that are modelled as
differential equations [9,13,17,23].
It is part of the MATLAB software suite and requires MATLAB to run.
Its applications include: (a) Electrical systems, (b) dynamic mechanical systems, (c)
reactive chemical systems, (d) dynamic fluid systems.
MATLAB has thus three techniques for solving differential equations:
1. MATLAB ode solvers.
2. MATLAB symbolic algebra toolbox.
3. MATLAB simulink blocks.
9.2 Introductory Example
In command window type:
>> simulink
The simulink Library Browser opens, showing the available libraries of blocks used o
create a simulink model. The browser is the location where you’ll select blocks and
drag them to into the model workspace.
The most commonly used simulink libraries are:
(1)The Blocks Library
(2)Source and Sink Libraries
(3)Math Operations Libraries
9.3 Problem-Solving Procedure
1. Create a new model: File/New/Model: the model window opens.
2. Resize the library browser window and the model window so that you can see both
on the computer screen. Keep the MATLAB desktop open without overlapping
other windows.
Let us add two numbers as an illustrating example:
1. From either the Source library or the Commonly Used Blocks library, click and
drag the constant block in the model.
2. Repeat the process, so that you have two copies of the constant block into the
model window.

207
3. Drag the sum block (either from the Commonly Used Blocks library or the Math
Operations library) into the model.
Draw connections between the constants and the sum block by clicking and dragging
between the ports.
5. Double click on each constant block and change the ‘constant value’ field to 5 in
the top block and 6 in the bottom block.
6. To add a display option, drag the display block in the sink library to the model and
connect it to the output port of the sum block.
7. Adjust the simulation time from the box in the menu bar. Since nothing in this
calculation changes with time, we can change the value to zero.
8. Run the simulation by selecting the run button on the tool bar, or by selecting
Simulation/ Start from the menu bar.

Figure 9.1: Addition of two numbers and display


9.4 Ordinary Differential Equations in simulink
𝑑𝑦
A first-order differential equation has the form 𝑓 (𝑥, 𝑦, 𝑑𝑥 ) = 0.
𝑑𝑦 𝑑2 𝑦
A second-order differential equation has the form: 𝑓 (𝑥, 𝑦, 𝑑𝑥 , 𝑑𝑥 2 ) = 0 … so forth.
The solution of a differential equation is a function that satisfies the differential
equation over some range of the independent variable.
To find the solution of a differential equation we always employ the integrator
operator. The linking sequence is:
Simulink → Continuous → Integrator
When you bring the integrator block in your model file, it appears as follows:

208
The main aim of simulating the differential equation is to find the wave shape of the
𝑑𝑦
dependent variable𝑦. The simulink operation of obtaining y from can be
𝑑𝑥
represented as follows:
𝑑𝑦
1
𝑦
𝑑𝑥
𝑆
Integrator
𝑑𝑦
Figure 9.2: Integrating
𝑑𝑥
𝑑2𝑦
The simulink operation of obtaining y from can be represented as follows
𝑑𝑥 2
𝑑2 𝑦 𝑑𝑦
𝑦
𝑑𝑥 2 𝑑𝑥
1 1
𝑆 𝑆
Integrator1 Integrator2
𝑑2 𝑦
Figure 9.3: Integrating
𝑑𝑥 2
Example 9.1 (Modeling of a first-order differential equation)
Plot the profile of the differential equation:
𝑑𝑦
= 2𝑦 = 0 with the initial condition𝑦(0) = 10
𝑑𝑥
(a)Analytically
(b)Using simulink
Solution:
(a)The analytical solution is: y = 10𝑒 −2𝑥
The plot of the above function is:
10

0
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2

Fgure 9.4: Plot of analytical solution in example 9.1

209
(c) Simulink solution
Simulink Model is as follows:

Figure 9.3: Simulink model for example 9.1


Simulink model functional flow:
𝑑𝑦 1 𝑦
𝑑𝑡 𝑆
Integrator Scope
𝑑𝑦
= −2𝑦
𝑑𝑡

−2𝑦 -2

Gain
Figure 9.4: Simulink model in functional flow for example 9.1
The Simulink Procedure:
Open a new Simulink model file, save the file in your working path, and click the
library browser icon.
Bring an integrator block in the model file following the link:
Simulink/Continuous/Integrator.
Double click integrator to insert the initial condition y(0) = 10
Bring a Gain block in the model file following the link:Simulink/Math
Operations/Gain.
Double click the Gain block to change its gain to -2 and flip the block
(select → click the right button of the mouse → Format → flip block).
Bring a scope block in model file following the link:Simulink/Sinks/Scope.
Place the three blocks relatively and connect. Click Simulation/Simulation
parameters/Solver from the menu bar in your model file and enter start time as 0 and
stop time as 2 to insert 0 ≤ t ≤ 2 in the solver parameter window.
210
Click the start simulation window, double click the Scope block, bring the mouse
pointer in the plot area of the scope output, click the right button of the
mouse →Axes properties to see the Y axes properties and enter there 0 and 12 as Y
min and Y max axes values respectively .
Example 9.2
Solve the following differential equation in MATLAB using:
1. simulink
2. Symbolic Algebra
3. ODE45
𝑑𝑦
= 𝑡2 + 𝑦
𝑑𝑡
(a) simulink Solution
To solve using simulink, you need the following blocks:
*A clock, to generate times (Source library).
*A math function block, modified in the parameter window to square the block input
(Math Operation Library)
*A sum block (Commonly Used Blocks library)
*An integrator block (Continuous library)
*A scope block (Sink library)
Adjust the integrator block in the parameter window so that the initial condition is 0.
You may need to click on the binocular icon to see the entire plot in the scope screen.

Figure 9.5: Simulink model blocks for example 9.1

211
Figure 9.6: Simulink solution example 9.1
(b) Symbolic Algebra Solution:
>>y=dsolve ('Dy = t^2 + y' , 'y(0) = 0');
>>ezplot (y,[0,10])

Figure 9.7: Simulink solution using symbolic math. In example 9.1


(c) ODE45 Solution:
>>dydt = @(t, y)t^2+y;
>>[t, y] = ode45(dydt , [0,10],0);
>>plot(t, y)

212
Figure 9.6: Simulink solution using ode45 in example 9.1
Example 9.3 (Modeling a differential equation with input function)
Simulate the differential equation:
𝑑𝑦
+ 7𝑦 = 1 + 𝑡 − 𝑡 2
𝑑𝑡
For the span 0 ≤ t ≤ 5 with the initial condition y(0) = -4
Solution:
Open a new Simulink model file.
Bring one Integrator block, set the initial condition y(0) = -4
Bring one Gain block, set its gain to -7, and rotate it.
Bring one Sum (or Add) block and flip it.
Bring one Scope block
Bring a Fcn (simulates function) in the model file following the link ‘Simulation/User-
defined functions/Fcn. Double the block to change the parameters expression to 1 +
u – u2. Connect the blocks as shown below.
Bring a ramp block following the link ‘Simulation/Sources/Ramp’
Click Simulation, Simulation parameters, Solver and set the start and stop times as 0
and 5 respectively. Click the run icon
Double click the scope to view plot

Figure 9.8: Modeling a differential equation with an input function

213
For a second-order differential equation, two integrator blocks and two initial
conditions are necessary for the simulation.
Example 9.4 (Modeling a second-order differential equation)
Plot the profile of the dependent variable y for the differential equation:
𝑑2𝑦 𝑑𝑦
4 2
+ 12 + 8𝑦 = 0
𝑑𝑥 𝑑𝑥
𝑦(0) = −5 and 𝑦′(0) = 3 over the span 0 ≤ t ≤ 9
Solution:
Rewrite the equation so that the highest derivative is on the left side as follows:
𝑑2 𝑦 𝑑𝑦
2
+3 + 2𝑦 = 0
𝑑𝑥 𝑑𝑥
𝑑2𝑦
Two integrator blocks are needed to obtain y from :
𝑑𝑥 2

Figure 9.9: Modeling a second-order differentiak equation


Solution steps:
Open a new Simulink model file.
Bring one Integrator block, set the initial condition y’(0) = 3
Bring another Integrator block and set initial condition y(0) = 5
Bring one Gain block, set its gain to -3, and rotate it.
Bring another Gain block, set its gain to -2, and rotate it.
Bring one Sum (or Add) block and flip it.
Bring one Scope block
Connect the blocks as shown below
Click Simulation, Simulation parameters, Solver and set the start and stop times as 0
and 9 respectively
Click the run icon
Double click the scope to view plot

214
Figure 9.10: Simulink blocks for modeling a second-order differentiak equation

Figure 9.11: Simulink output for modeling a second-order differentiak equation


9.5 Modelling Common Problems of Control Systems in
Simulink
The fundamental notion in the control system theory is that some blocks , with inputs
and outputs, can portray the system [8]. The required response to an input can be
analysed and visualized in some mathematical form or another such as a transfer
function, the state space model or a differential equation.
9.5.1 Step response of a control system from the transfer function
A continuous (ratther than discrete) can be characterized by some Laplace transform
transfer function H(s)., which is often a polynomial in s:
𝑁(𝑠)
𝐻(𝑠) =
𝐷(𝑠)
Where N(s) and D(s) are the numerator and denominator polynomials in s
respectively.
The step response of a continuous time system means the output of the system when
a step function is the input to the system.

215
The mathematical procedure to obtain the step response is to take the Laplace
transform of the input function and then multiply this transform with the system
transform function. The time domain step response is obtained by taking the inverse
Example 9.5 (Step response)
Plot the step response y(t) of the first-order control system:
1
𝐻(𝑠) =
−80𝑠 + 7

over the time span: 0 ≤ t ≤ 20.

u(t) y(t)
Solution:
The simulink model for simulating the problem is shown in Fig. 9.12(a) below.

Fig. 9.12(a) Simulink model for step function


The numerator and denominator of H(s) are entered as the polynomial coefficients
but in descending power of s. So we have the polynomial coefficients [1] and [-80 7]
for the numerator and denominator of H(s) respectively.
Solution steps:
Open a new simulink model file
Click the library browser icon
Bring a step block in the model file following the link:
“Simulink Sources Step”
Since the step for u(t) starts at t = 0, double click the block to change its default step
time from 1 to 0 in the block parameter’s window.
Bring a Transfer Fcn block in the model file following the link:
“Simulink Continuous Transfer Fcn”
Double click the transfer Fcn block to open the block parameter window and insert
the specifications of H(s).
Bring a scope block in the model file following the link:
“Simulink Sinks Scope”
Connect the three blocks
To insert 0 ≤ t ≤ 20, click “Simulink Simulation parameters Solver”
From menu bar to enter start time as 0 and stop time as 20. Click OK.
Save the model file and start the simulation icon
Double click the Scope block and change its axes settings to autoscale.

216
Fig. 9.12(b) Simulink model for step function

Fig. 9.13 Simulink step response

217
Exercises
(1) Use Simulink to simulate the differential equation containing polynomial input
function:
𝑑𝑦
+ 7𝑦 = 1 + 𝑡 − 𝑡 2
𝑑𝑡
For 0 ≤ t ≤ 5 with the initial condition y(0) = -4
Compare your results with MATLAB built-in solver and Symbolic mathematics.

(2)Use simulink to find the solution for:


𝑑𝑦
= 4𝑦 2 𝑥 4
𝑑𝑥
With the initial condition y(0) = 10 over 0 ≤ x ≤ 2

(3)Use simulink to find the solution for:


𝑑𝑦
( 𝑥2 + 𝑦3) = 𝑥 + sinh 𝑦
𝑑𝑥
With the initial condition y(0) = 5 over 0 ≤ x ≤ 3

(4)Use simulink to find the solution for the second-order differential equation:
𝑑2𝑦 𝑑𝑦
4 2 + 12 + 8𝑦 = 0
𝑑𝑥 𝑑𝑥
With the initial condition y(0) = -5 and y’(0) = 3
over 0 ≤ t ≤ 9

(5) Use simulink to draw a sketch of the of the response C(t) when the following
proportional control loop, shown in Figure 9.14, is subjected to a step change of 0.1
unit.

Figure 9.14 Proportional control loop

(6) Draw the response curve (C versus t) for a unit step change in the load when K= 1
and K = 2 for the following proportional integral derivative (PID) closed-loop control
system. In both cases determine the maximum value of C and the time at which it
occurs. The parameter U is the load.
The parameters have the following values 𝜏𝐷 = 𝜏𝐼 = 1 and 𝜏𝐷 = 2

218
Figure 9.15 PID control loop

219
220
CHAPTER

10
Prelude
Process Dynamics and
Control

The material presented in the following sections of this chapter assume that the
student has already completed an introductory course on process dynamics and
control. Classical transfer function feedback control builds on linear differential
equations (ODEs) and the technique of the Laplace transform [21,22].
The Laplace transform of a function f(t) is defined as:

L[𝑓(𝑡)] = ∫0 𝑓(𝑡)𝑒 −𝑠𝑡 𝑑𝑡
Where s is the transform variable. The relationship between time domain and
Laplace domain can depicted as follows:
f(t)
𝑑𝑦
y(t) L F(s) Y(s)
= 𝑓(𝑡) 𝐺(𝑠)
𝑑𝑡
Input Output Input Output
Input : can be a forcing function (e.g. disturbances, manipulated variable)
Output : Controlled variable
For complex systems , with multiple inputs and outputs, transfer function matrices can
become very clumsy. Model control theory relies on state space representation or
state variables in the time domain. As an illustration, we will develop transfer function
representation and state space representation of a second-order differential equation.
10.1 Single-Loop Control Systems
The focus in this section is on how to derive the closed-loop characteristic equation.
This is the necessary condition to learning how to design and tune a proportional-
integral (PID) controller.
Figure 10.1 shows a schematic diagram of a liquid-level classic feedback control
system. The liquid level in the vessel is measured and this information is used to
adjust the opening of a valve in the exit stream so as to keep the liquid level at some
user-specified value (the set point or reference). In this case, the liquid level is both
the measured variable and the controlled variable – they are the same in a single-input
single-output (SISO) system. The word system refers to the process that we need to
control i.e. the liquid level in addition to the controller as well as accessories, such as
sensors and actuators. A sensor and actuator can be packaged in a single device called
transducer.

221
hs is the set point (i.e. the level at which we want to maintain the liquid level). A surge
in the inlet flow rate 𝑞𝑖 is called a disturbance (or load). An increase in the level h’ is
called a deviation and is: h’ = h - hs . The signal from the controller p(t) should be a
function of such a deviation. However, because we are to implement feedback, the
controller decision is based on the error.
error(t) = hs (t) – h(t)
The error is thus the negative of the deviation.
The controller output ; p(t) is:
𝑝(𝑡) = 𝑝 𝑠 + 𝑓[𝑒(𝑡)] = 𝑝 𝑠 + 𝑓[ℎ 𝑠 − ℎ(𝑡)]
Where 𝑓 is some function of 𝑒(𝑡) and 𝑝 𝑠 is the actuating signal at steady state when
the deviation is zero. The compensation signal is the actual controller output.
The plausible controller functions of e(t) define the type of control action we use:
proportional, derivative, integral, or combinations thereof.

Figure 10.1 Liquid-level control system

10.1.1 Proportional Control


When the actual controller output is proportional to error we have proportional
control [22]:
𝑝(𝑡) = 𝑝 𝑠 + 𝐾𝐶 e(t) = 𝑝 𝑠 + 𝐾𝐶 [ℎ 𝑠 − ℎ(𝑡)]
𝐾𝐶 is the proportional gain of the controller.
Figure 10.2 shows the summing point in a negative feedback control system.

+ E(S) P(S)
𝑠 𝐺𝐶
𝐻 (S) _
H(S)

Figure 10.2 summing point

222
The transfer function of a proportional controller is:
𝑃(𝑆)
𝐺𝐶 (𝑆) = = 𝐾𝐶
𝐸(𝑆)
A system with only proportional control will exhibit a steady state error (or offset).
10.1.2 Proportional-Integral Control
The offset referred to in the previous section can be eliminated by using integral
action which is related to the history of the error. The time domain equation is:
1 𝑡
𝑝(𝑡) = 𝜏 ∫0 𝑒(𝑡)𝑑𝑡
𝐼
The transfer function equation is:
𝑃(𝑆) 1
=
𝐸(𝑆) 𝑠𝜏𝐼
𝜏𝐼 is called integral time constant (or reset time).
Integral control is never used alone. Usually it is used in conjunction with proportion
control to yield the proportional-integral controller (PI):
1
𝐺𝐶 (𝑆) = 𝐾𝐶 [1 + ]
𝑠𝜏𝐼
PI can eliminate offset but can introduce an underdamped response.
10.1.3 Proportional-Derivative Control
To obtain a faster control action we use derivative action which is related to the rate of
change of error (i.e. on how fast the error is changing with time).
𝑑𝑒
𝑝(𝑡) = 𝜏𝐷
𝑑𝑡
𝜏𝐷 is called derivative time constant.
As was the case with derivative action is never used on its own. A proportional-
derivative controller will have the following transfer function:
𝐺𝐶 (𝑆) = 𝐾𝐶 [1 + 𝜏𝐷 𝑠 ]
Qualitatively, derivative action is not suitable when there is large dead time.
10.1.4 Proportional-Integral-Derivative Control
PID (also known as three mode control) has the following transfer function:
1
𝐺𝐶 (𝑆) = 𝐾𝐶 [1 + + 𝜏𝐷 𝑠 ]
𝑠𝜏𝐼
10.2 Transfer function representation
Consider the second-order differential equation:
𝑑2𝑦 𝑑𝑦
𝑎2 + 𝑎1 + 𝑎0 𝑦 = 𝑏𝑥(𝑡) 𝑎2 ≠ 0, 𝑦(0) = 𝑦´(0) = 0
𝑑𝑡 2 𝑑𝑡
Which is usually arranged to take the forms:
𝑑2 𝑦 𝑑𝑦
𝜏2 + 2𝜉𝜏 + 𝑦 = 𝐾𝑥(𝑡) Or
𝑑𝑡 2 𝑑𝑡
𝑑2𝑦 𝑑𝑦
+ 2𝜉ω𝑛 + ω2𝑛 𝑦 = 𝐾ω2𝑛 𝑥(𝑡)
𝑑𝑡 2 𝑑𝑡

223
𝑎2 𝑎1 𝑏
Where 𝜏 2 = , 2𝜉𝜏 = ,K= , ω𝑛 = 1/𝜏
𝑎0 𝑎0 𝑎0
The corresponding Laplace transforms are:
𝑌(𝑠) 𝐾
G(s) = = 22
𝑋(𝑠) 𝜏 𝑠 + 2𝜉𝜏𝑠 + 𝑦

𝑌(𝑠) 𝐾 ω2𝑛
Or G(s) = =
𝑋(𝑠) 𝑠2 + 2𝜉 ω𝑛 𝑠 +ω2𝑛
Where:
𝜏 is the natural period
ω𝑛 is the natural frequency
𝜉 is the damping ratio
10.2.1 Transform Function Poles, and Zeroes
We refer to the roots of the numerator of a transform function as the zeroes. The
roots of the denominator are referred to as the poles. In pole-zero form:
𝑄(𝑠) (𝑠−𝑧1)(𝑠−𝑧2)(𝑠−𝑧3)
G(s) = =
𝑃(𝑠) (𝑠−𝑝1(𝑠−𝑝2)(𝑠−𝑝3)
10.3 State space representation
We intend to derive the state-space representation of a second-order differential
equation in a form similar to that of the transform function form shown earlier.
𝑑2𝑦 𝑑𝑦
+ 2𝜉ω𝑛 + ω2𝑛 𝑦 = 𝐾𝑢(𝑡)
𝑑𝑡 2 𝑑𝑡
With zero initial conditions the transform function is:
𝑌(𝑠) 𝐾
G𝑃 (s) = = 2
𝑈(𝑠) 𝑠 + 2𝜉 ω𝑛 𝑠 +ω2𝑛
Rewrite the equation as follows:
𝑑2𝑦 𝑑𝑦
= − 2𝜉ω𝑛 - ω2𝑛 𝑦 + 𝐾𝑢(𝑡)
𝑑𝑡 2 𝑑𝑡
Define the state variables:
dx1
x1 = y, x2 =
dt
We can now redefine the second-order equation as a set of two coupled first-order
equations. The first equation is:
dx1
= x2
dt
The second equation is obtained by differentiation:
dx2
= − 2𝜉ω𝑛 x2 - ω2𝑛 x1 + 𝐾𝑢(𝑡)
dt
In matrix form:

224
dx1
dt 0 1 x1 0
[dx ]=[ 2 ] [x ] + [ ]u(t)
2 −ω𝑛 − 2𝜉ω𝑛 2 K
dt
x
Let 𝑦 = [1 0] [x1 ]
2
Comparing the results with previous equations we observe that :
0 1
A=[ 2 ]
−ω𝑛 − 2𝜉ω𝑛
0
B=[ ]
K
C = [1 0]
D=0

A denotes the process (plant) matrix, B is the input matrix, C is the output matrix,
and D is the feed through matrix. Very few processes have an input that has a direct
influence on the output. Hence D is usually zero.
To convert a transfer function to state-space form the MATLAB function tf2ss()
Example 10.1 (Conversion of transfer function to state-space form)
Convert the transfer function in the equation:
𝑌(𝑠) 𝐾
G𝑃 (s) = = 2
𝑈(𝑠) 𝑠 + 2𝜉 ω𝑛 𝑠 +ω2𝑛
to state-space form for 𝜉 = 0.5 and ω𝑛 = 1.5
Solution:
To comply with MATLAB syntax we replace 𝜉 by z and ω𝑛 by wn.
MATLAB program:
P = [1 2*z*wn wn*wn];
[A B C D] = tf2ss(wn*wn,P)
Results:
A = -1.5000 -2.2500
1.0000 0
B= 1
0
C = 0 2.2500
D= 0
Example 10.2 (transfer function write-up from differential equation)
Write the transfer function of the following differential equation:

𝑑2𝑦 𝑑𝑦 𝑑𝑈 𝑑𝑦
+ 0.4 + 𝑦= + 3u, y(0) = (0) = 0, u(0) = 0
𝑑𝑡 2 𝑑𝑡 𝑑𝑡 𝑑𝑡

Where x is the state variable vector, u is the input, and y is the output.

225
Solution:
The transfer function is:
𝑌 𝑠+3
= 2
𝑈 𝑠 + 0.4𝑠 + 1
Example 10.3 (MATLAB program for derivation of state-space form)
Write a MATLAB program for derivation of the state-space form of the differential
equation in example 10.2 above.
Solution:
MATLAB program:
% coefficients of transfer function numerator:
q = [1 3];
% coefficients of transfer function denominator:
p = [1 0.4 1];
[a,b,c,d] = tf2ss(q,p)
MATLAB Results:
a = -0.4000 -1.0000
1.0000 0
b= 1
0
c= 1 3
d= 0
10.4 Object-Oriented Transfer Functions
MATLAB is object oriented. Linear-time-invariant (LTI) models are handled as
objects.LTI include transfer functions in polynomial or in pole-zero form [21].
To define a transfer function object, we use tf(), which takes the numerator and
denominator polynomials as arguments. For example, we define
G(s) = [s/s2 – 5s + 4)]
with G1 = tf([1 0], [1 -5 4])
We define G(s) = [(6 s2 - 12)/(s3 + s2 – 4s - 4)]
with G2= tf([6 0 -12], [1 1 -4 -4])
We can also use the zero-pole-gain function zpk() which takes as arguments the
zeros, poles, and gain factor of a transfer function. For example, we define
G(s) = {4/[s(s+1)(s+2)(s+3)]} with
G3 = zpk([ ], [0 -1 -2 -3], 4) % the [ ] means there is no zero
The tf() and zpk() functions also serve to perform model conversion from one form to
another. We can find the polynomial form of G3 with tf(G3) and the pole-zero form
of G2 with zpk(G2).
The addition and multiplication operators can be used as follows:
Example 10.4
1 2
G1 = , G1 =
𝑠+1 𝑠+2

226
Find G1+G2, and G1G2
Solution:
Scrip M-file Add_tr:
G1 = tf(1,[1 1]);
G2 = tf(2,[1 2]);
G1+G2
G1*G2
MATLAB output:
>> add_trf
ans =
3s+4
-------------
s^2 + 3 s + 2
ans =
2
-------------
s^2 + 3 s + 2
10.5 Time-response Simulation
Time-response simulation functions include:
damp Find damping factor
impulse Impulse response
step unit-step response
pade Time delay Pade” approximation
10.5.1 Step- and Impulse-Response Simulations
The time-domain calculation is done as follows:
𝑌(𝑠) 1
If = 2
𝑋(𝑠) 𝑆 +0.4S + 1
The script M-file for plotting y(t) for a given input x(t) is:
q = 1;
p = [1 0.4 1];
G = tf(q,p)
step(G) % Plots y(t) for unit step input, X(s) = 1/s

227
Figure 10.1 Step response
q = 1;
p = [1 0.4 1];
G = tf(q,p)
impulse(G) %Plots y(t) for impulse input, X(s) = 1

Figure 10.2 Impulse response

228
The functions also handle multiple transfer functions. Consider a second transfer
function in pole-zero form:
2
H(s) = 2
(𝑠+2)(𝑠 +2𝑠+2)
H = zpk([], [-2 -1+j -1-j], 2)
To compare the unit-step responses of the two transfer functions G and H:
Step(G,H)
See Fig. 10.3

Figure 10.3 Comparison of step responses of two transfer functions

10.5.2 Sinusoidal Response


To obtain the response y(t) to a sinusoidal input x(t) sin(t), we use the function 1sim()
which is a general simulation function which takes any given input vector.
q = [2 1]; % a zero at -1/2
p = conv([4 1], [1 1]); % poles at -1/4 and -1
G = tf(q,p) % can use zpk instead
t = 0:0.5:30;
u= sin(t)
y = lsim(G,u,t); % response to a sine function input
(Be careful : It is Lsim and not 1sim)
plot(t,y,t,u,’-.’), grid

229
Figure 10.4 Response to sinusoidal input
To plot responses to step, impulse and sinusoidal inputs on same graph, prepare the
following script M-file and run it:
q = [2 1]; % a zero at -1/2
p = conv([4 1], [1 1]); % poles at -1/4 and -1
G = tf(q,p); % can use zpk instead
t = 0:0.5:30;
u = sin(t);
y =lsim(G,u,t); % response to a sine
function input
plot(t,y,t,u,'-.'), grid
hold
ys =step(G,t);
yi =impulse(G,t);
plot(t,ys,t,yi)
hold off

230
Figure 10.5 Response to step, impulse, and sinusoidal sinusoidal inputs
10.6 Feedback Simulation Functions
Simulink function, which has feedback simulation capabilities, was presented in
chapter nine. As explained, simulink is a user-friendly simulation tool with an icon-
driven graphics interface that runs within MATLAB [21].
The following diagram depicts a closed-loop for a stirred-tank heater which is a typical
Single Input Single Output (SISO) control system.
𝑇𝑆𝑃 (or R) = Set point (or Reference); the desired steady state tank temperature
𝐺𝐶 = Controller transfer function
𝐺𝑎 = Actuator function
𝐺𝑃 = Process (or Plant) transfer function
𝐺𝐿 = Load transfer function
M(𝑇𝐻 ) = Manipulated variable (𝑇𝐻 e. g. steam temperature)
𝐾𝑚 = Steady state gain
𝑇𝑖 = Inlet temperature
L(𝑇𝑖 ) = Load variable (the inlet temperature)
P = Controller signal
E = Error
𝐺𝑚 = measurement device (or transducer) transfer function
C(T) =The controlled variable (The system output; the tank temperature)

231
Figure 10.6 Block diagram of a simple SISO closed-loop system [21]
The tank temperature can be affected by variables such as the inlet temperature, the
jacket temperature, and the inlet flow rate.
In Laplace transform, the change in temperature is given by:
𝑇(𝑆) = 𝐺𝐿 (S) 𝑇𝑖 (S) + 𝐺𝑃 (S) 𝑇𝐻 (S)
The closed-loop transfer function is derived as follows:
E = 𝐾𝑚 R − 𝐺𝑚 C
From the process we have:
C = 𝐺𝑃 (𝐺𝑎 𝐺𝐶 E) + 𝐺𝐿 L
Substituting for E we obtain:
C = 𝐺𝑃 𝐺𝑎 𝐺𝐶 (𝐾𝑚 R − 𝐺𝑚 C) + 𝐺𝐿 L
Rearranging we get:
𝐾 𝐺 𝐺 𝐺 𝐺𝐿
C = ( 𝑚 𝐶 𝑎 𝑃 )R + ( )L
1+ 𝐺𝑚 𝐺𝐶 𝐺𝑎 𝐺𝑃 1+ 𝐺𝑚 𝐺𝐶 𝐺𝑎 𝐺𝑃
= 𝐺𝑆𝑃 R + 𝐺𝑙𝑜𝑎𝑑 L
From the above closed-loop transfer function equation, the inputs to the system are
the set point (The Reference) and the load variable L. The controlled variable is the
system output.
The first transfer function 𝐺𝑆𝑃 accounts for the effect of a set-point change and is also
called the command tracking function. The second transfer function 𝐺𝑙𝑜𝑎𝑑 accounts
for the effect of changes in inlet temperature (disturbances).
The important point is that the dynamics and stability of the system are governed by
the closed-loop characteristic polynomial equation:
1 + 𝐺𝑚 𝐺𝐶 𝐺𝑎 𝐺𝑃 = 0

232
This section will present control toolbox functions which handle synthesis of closed-
loop transfer functions. The closed-loop transfer function is:
𝐶 2
= 2
𝑅 (𝑠+2)(𝑠 +2𝑠+2)
The derivation of the transfer functions helps analyses the dynamic and control
system to understand the following :
(a) Why a system may have a faster response
(b) Why a system may become underdamped
(c) When there is an offset
10.6.1 Steps to develop a closed-loop transfer function
(1) Draw the control loop and derive the individual transfer functions
(2) Pick either the servo (fixed set point) or the regulator (fixed load but changing
set point).
(3) For 𝐺𝐶 chose between P, PI, PD, or PID. Decide on which transfer functions
(𝐺𝑃 , 𝐺𝑎 , 𝐺𝑚 ) to include in the closed-loop transfer function. Insert the selected
transfer functions into the closed-loop equation. The characteristic equation now
becomes known.
(4)Rearrange the algebra such that we can redefine the parameters as (a) time
constants and (b) steady state gains for the closed system.
As an example let us consider the servo simple unity system show in Fig. 10.7 below:

Figure 10.7 Simple unity feedback system


For the system in Fig. 10.7, we take 𝐺𝑚 = 𝐺𝑎 = 1 for a servo system (L = 0)
Therefore:
𝐶 𝐺𝐶 𝐺𝑃
=
𝑅 1+ 𝐺𝐶 𝐺𝑃

For a first-order process the process transfer function 𝐺𝑃 is:

𝐺𝑃 = [ 𝐾𝑃
]
𝜏𝑃 𝑆 + 1
For a second-order overdamped process the process transfer function 𝐺𝐶 is:

𝐺𝑃 = [ ( 𝜏1𝑆 + 1)𝐾 ( 𝜏2𝑆 + 1)]


𝑃

For a first-order process the proportional control transfer function 𝐺𝐶 is:

233
𝐺𝐶 = 𝐾𝐶
For a first-order process the proportional integral control transfer function 𝐺𝐶 is:
(𝜏𝐼 𝑆 + 1)
𝐺𝐶 = 𝐾𝐶 [ ]
𝜏𝐼 𝑆
For a first-order process the proportional derivative control transfer function 𝐺𝐶 is:

[
𝐺𝐶 = 𝐾𝐶 (𝜏𝐷 𝑆 + 1) ]
Example 10.5
Derive the closed-loop transfer function of a system with proportional control and a
process
Solution:
𝐶 𝐺𝐶 𝐺𝑃
=
𝑅 1+ 𝐺𝐶 𝐺𝑃
𝐺𝐶 = 𝐾𝐶
𝐺𝑃 = [ 𝐾𝑃
𝜏𝑃 𝑆 + 1 ]
Therefore:
𝐶 𝐾𝐶 𝐾𝑃
=
𝑅 𝜏𝑃 𝑆 + 1 + 𝐾𝐶𝐾𝑃
Example 10.6
Derive the closed-loop transfer function of a system with PI control and a first-order
first-order process
Solution:
𝐶 𝐺𝐶 𝐺𝑃
=
𝑅 1+ 𝐺𝐶 𝐺𝑃

[
𝐺𝐶 = 𝐾𝐶 (𝜏𝐷 𝑆 + 1) ]
𝐺𝑃 = [ ]
𝐾𝑃
𝜏𝑃 𝑆 + 1
Therefore:
𝐶 𝐾𝐶 𝐾𝑃 (𝜏𝐷 𝑆 + 1)
=
𝑅 𝜏𝐼 𝑆(𝜏𝐼 𝑆 + 1) + 𝐾𝐶 𝐾𝑃 (𝜏𝐼 𝑆 + 1)
Example 10.7
Derive the closed-loop transfer function of a system with PD control and a first-order
first-order process
Solution:
𝐶 𝐺𝐶 𝐺𝑃
=
𝑅 1+ 𝐺𝐶 𝐺𝑃
(𝜏𝐼 𝑆 + 1)
𝐺𝐶 = 𝐾𝐶 [ ]
𝜏𝐼 𝑆

234
𝐺𝑃 = [ 𝐾𝑃
𝜏𝑃 𝑆 + 1 ]
Therefore:
𝐶 𝐾𝐶 𝐾𝑃 (𝜏𝐷 𝑆 + 1)
=
𝑅 (𝜏𝑃 𝑆 + 1) + 𝐾𝐶 𝐾𝑃 (𝜏𝐷 𝑆 + 1)
To generate the closed-loop feedback transfer function use the command :
feedback(Gc*Gp,1)
Example 10.8 (Plot of response of PI controlled first0order system)
A first-order process is to be controlled with PI control. The system parameters’
values are as follows: 𝜏𝑃 = 5 min, 𝐾𝑃 = 0.8 (unit).
Use MATLAB to generate the response for the case of a unit-step change in the set
point.
Solution:
kc = 1; taui = 10 %The two tuning parameters to be varied
Gc = tf(kc*[taui 1],[taui 0]; %The PI controller action
Gp = tf(0.8,[5 1]); % The process function
Gc1 = feedback(Gc*Gp,1) %Unity closed-loop function GcGp/(1+GcGp)
Step(Gc1);

Figure 10.8 Step response for feedback system of example 10.8


10.7 Control System Stability
The foremost concern in a control system is to keep the system stable.Controller
settings should aim at prevention of unstability. So what is stability? Consider the
closed-loop system response:
𝐾m 𝐺C 𝐺a 𝐺𝑃 𝐺L
C= R + L
1 +𝐺m 𝐺C 𝐺a 𝐺𝑃 1 +𝐺m 𝐺C 𝐺a 𝐺𝑃
with the characteristic equation:
1 + 𝐺m 𝐺C 𝐺a 𝐺𝑃 = 0

235
The closed-loop is stable if all the roots of the characteristic equation have negative
real parts. Or we can say that all the poles of the closed-loop transfer function lie in
the left-hand plane (LHP). On the basis of this definition the stability of the system
depend only on the dynamics of the system and not on the input functions. In other
words the result apply to both servo and regulating problems. Another definition of a
stable system is that it has to be a bounded-input bounded-output (BIBO) system.
A control system with its poles on the imaginary axis is not considered a stable system
because its response to a step change is a ramp which is unbounbed.
The two techniques used in stability analysis are Routh-Hurwitz criterion and root-
locus. Root-locus is by far , the more important and useful method.
10.7.1 Root-locus Analysis
rlocus computes the root locus of a SISO (Single-input Single-output) open-loop
model. The root locus gives the closed-loop pole trajectories as a function of the
feedback gain k (assuming negative feedback). Root loci are used to study the effects
of varying feedback gains on closed-loop pole locations. In turn, these locations
provide indirect information on the time and frequency responses.
rlocus(sys) calculates and plots the root locus of the open-loop SISO model system.
This function can be applied to any of the following negative feedback loops by
setting sys appropriately.

Figure 10.9 Negative feedback loops for root-locus analysis


If sys has transfer function
𝐶 𝑛(𝑠)
=
𝑅 𝑑(𝑠)
the closed-loop poles are the roots of d(s) +Kn(s) = 0

236
rlocus adaptively selects a set of positive gains K to produce a smooth plot.
Alternatively, rlocus(sys,K) uses the user-specified vector K of gains to plot the root
locus.
Example 10.9
Construct the root-locus plots of a (a) first- and (b) a second-order system with a
proportional controller.
Solution:
(a) The characteristic equation of a first-order system with a proportional
controller is:
𝐾P
1 + 𝐾C =0
(𝜏P S+ 1)
The solution (i.e. the closed-loop poles of the system, is:

−(1+ 𝐾C 𝐾P )
S= where 𝜏P is the proportional time constant
𝜏P

The root-locus plot is shown in Fig. 10.10.


The root locus is simply a line on the real axis starting at s = -1/ 𝜏P when 𝐾C = 0 and
extends to negative infinity as 𝐾C approaches infinity.

Figure 10.10 The root-locus for first-order system of example 10.9


(b) The closed-loop characteristic equation for a second-order system with
proportional control is:
𝐾P
1 + 𝐾C =0
(𝜏1 S+ 1)(𝜏2 S+ 1)
The two closed-loop poles are (𝐾C approaches zero) are: -1/ 𝜏1 and -1/ 𝜏2 which
are the locations of the two open-loop poles, see Fig. 10.11:

237
Figure 10.11 The root-locus for second-order system of example 10.9
When 𝐾C is increased beyond a certain value the closed-loop poles will branch-off (or
break away) from the real axis and become two complex conjugates. No matter how
much we increase 𝐾C further, the system will always be stable because the roots will
continue to have negative real parts.
We conclude from the above observation that with simple first- and second order
systems with no open-loop zeros in the RHS (Right hand side), the closed-loop system
is always stable [21].
10.8 Root-Locus Functions
In plotting the root-locus, we want to solve for s in the closed-loop equation
1 + 𝐺0 (s) = 1 + kG(s) = 0
We write 𝐺0 = kG(s) and G(s) is the ratio of two polynomials, G(s) = q(s)/p(s)
Example 10.10
Generate the root-locus plot of the system:
q(s) = 1, p(s) =𝑠 3 + 6𝑠 2 + 11𝑠 + 6
Solution:
p = [1 6 11 6];
roots(p)
G=tf(1,p);
rlocus(G)

Figure 10.12 The root-locus plot system of example 10.10


238
Example 10.11 (Plot of root-locus of a second-order system)
Plot the root-locus of the following system.

𝐶 2𝑠2 +5𝑠+2
=
𝑅 𝑠2 +2𝑠+3

Solution:
G = tf([2 5 1],[1 2 3]);
rlocus(G)

Figure 10.13 The root-locus plot system of example 10.11


The root-locus plot is prepared by selecting a set of a certain design parameter, most
commonly the proportional gain 𝐾𝐶 , and calculating the roots of the characteristic
polynomial for each chosen value of 𝐾𝐶 . The results (the values of the poles) are plotted
on a complex plane.
Root-locus is thus a graphical representation of the roots of the closed-loop
characteristic equation (i.e. the closed-loop poles) as a chosen parameter is varied.
10.9 SISO System Design Graphics Interface
The command sisotool opens the SISO Design Tool. This Graphical User Interface
lets you design single-input/single-output (SISO) compensators by graphically interacting
with the root locus, Bode, and Nichols plots of the open-loop system.
To import the plant data into the SISO Tool, select the Import item from the File
menu. By default, the control system configuration is where C and F are tunable
compensators. See Fig. 10.14 for SISO architecture.

239
Figure 10.14 SISO block diagram
The command sisotool(G) specifies the plant model G to be used in the SISO Tool.
Here G is any linear model created with TF, ZPK, or SS. sisotool(G,C) and
sisotool(G,C,H,F) further specify values for the feedback compensator C, sensor H,
and prefilter F. By default, C, H, and F are all unit gains.
sisotool(VIEWS) or sisotool(VIEWS,G,...) specifies the initial set of views for
graphically editing C and F. You can set VIEWS to any of the following strings or
combination of strings:
'rlocus' Root locus plot
'bode' Bode diagram of the open-loop response
'nichols' Nichols plot of the open-loop response
'filter' Bode diagram of the prefilter F
For example:
sisotool({'nichols','bode'})
opens a SISO Design Tool showing the Nichols plot and Bode diagrams for the open
loop CGH. The default view displays both the root-locus and Bode editors. SISO
supports a flexible block diagram, see Fig. 10.15.
The SISO Design Tool is an interactive graphical user interface that facilitates the
design of compensators for single-input single-output feedback loops. It can draw
Simulink block diagrams.
This interface is reported to be more intuitive and self-explanatory than Simulink. The
transfer functions are imported, as needed, under the File pull-down menu. The default
compensator shown in Figure 10.12 is a proportional controller., but can be changed to
become a PI, PD, or PID controller. Once a root-locus is generated, one can
interactively change the locations of the closed-loop poles and SISO will compute the
corresponding controller gain.
For a given system and chosen closed-loop poles displayed in the root-locus plot, we
can generate its corresponding time-response and frequency-response plots.

240
Figure 10.15 Default window of SISO design tool
Example 10.12 (SISO Plot)
Do the SISO plots for the linear system
𝐶 2𝑠2 +5𝑠+2
= 2
𝑅 𝑠 +2𝑠+3
Solution:
G = tf([2 5 1],[1 2 3]);
sisotool
sisotool(G)

241
Figure 10.16 SISO plots for example 10.12
10.10 Frequency-Response Functions
In this section, convenient graphical techniques will be presented for obtaining the
frequency response of linear systems. This is an alternative technique to obtaining the
response to sinusoidal forcing functions by the standard Laplace transform technique.
The SISO design tool will be used in this section to study the frequency-response
functions specially the Bode plots. The Nyquist and Bode plots address the stability
problem but need other techniques to reveal the dynamic response. The Bode plot is
the plot of magnitude vs. frequency and phase angle vs. frequency plotted individually.
The purpose of these plots is to calculate the proportional gain needed to satisfy the
gain or phase margin.
10.10.1 Nyquist and Nichols Plots
The Nyquist plot is a frequency parametric plot of the magnitude and the argument of
the open-loop transfer function in polar coordinates. Tare overlaid as contours. The
Nichols chart is a frequency plot of open-loop function magnitude vs. phase angle.
The SISO Design Tool (sisotool) can be used to do frequency-response plots.

242
Example 10.13 (Determination of K value that will result in an unstable system)
SISO design tool will be used a Nyquist plot in this example. Consider a simple open-
loop transfer function 𝐺0 . The closed-loop characteristic equation is: 1 + 𝐺0 = 0
We want to determine the proportional gain that will result in an unstable system.
For this exercise let us take 𝐺0 = KG(s):
The MATLAB code is as follows:
sisotool
G = tf(10,[-1 -2 -3]); % open-loop poles at -1, -2,
-3, with arbitrary value K = 10
nyquist(G);

Figure 10.17 Nyquist diagram for example 10.13


By default, MATLAB also maps and plots the image of the negative imaginary axis. If
only the positive image of the imaginary axis is needed, then do the following:

243
Figure 10.18 Nyquist diagram with positive image round imaginary axis
We can increase the gain K and repeat the calculation with, say, K = 30, and K = 50.

Figure 10.19 Nyquist diagram with K =10, 30, 50

244
10.10.2 Bode frequency response of dynamic systems
The amplitude ratio (AR) and phase lag can be calculated by direct substitution of
s = j ω into the transfer function for the particular frequency of interest. The Bode
diagram is a convenient graphical representation of the dependence of AR and phase
lag on the frequency.
If the theoretical system dynamics are not known, the frequency response may be
obtained experimentally. To do this, the open-loop system is disturbed with a sine-
wave at several frequencies. At each frequency, records of the input and output waves
are compared to establish AR and phase lag. The results are plotted as a Bode
diagram.
The Bode diagram consists of two graphs: logarithm of AR versus logarithm of
frequency, and phase angle versus logarithm of frequency. The Bode diagram is a
convenient tool for analysing controls systems. The stability of a control system can
usually be determined from the Bode diagram of its open-loop transfer function. The
Bode diagram also facilitates the rational selection of controller parameters; the gain
and phase margin.
10.10.3 Bode Plots
The Bode stability criterion stipulates that a control system is unstable if the open-
loop frequency response exhibits an AR exceeding unity at the frequency for which
the phase lag is 1800 . The so-called crossover frequency (ω0) occurs in the Bode
diagram when the phase lag is 1800 [22]. At this frequency, the AR is the amplitude
(A). If A exceeds unity, we know from the Bode criterion that the system is unstable.
The system shown in Figure 10.13 is therefore a theoretically stable system (just!).
It is important to quantify a measure for system stability. For this purpose the gain
margin yardstick (which is really a safety factor) is introduced:
1
Gain margin =
𝐴
Typical specifications for design are that the gain margin should be greater than 1.7.
A gain margin of unity or less at cross over indicates an unstable system.
Phase margin is another margin of safety for stable design. The phase margin is the
difference between 1800 and the phase lag at the frequency for which the gain margin
is unity. The phase margin (as shown in Figure 10.13) therefore represents the
additional amount of phase lag required to destabilize the system, just as the gain
margin represents the additional gain for destabilization. Typical design specifications
are that the phase margin must be greater than 300 . A negative phase margin indicates
an unstable system.

245
Figure 10.20 Open-loop Bode diagram for typical control system

Example 10.14 (Bode diagram generation)


Generate the Bode plot for the closed-loop characteristic equation:
1 + (𝑠 2 + 0.4𝑠 + 1) = 0
Solution:
The Bode plot is generated as follows:
G = tf(1, [1 0.1 1]);
bode(G)

Figure 10.21 Bode Diagram for example 10.14

246
The upper half of the diagram is sometimes plotted as Amplitude ratio (AR) versus
frequency.
The default in MATLAB is the use of decibels as the unit for the magnitude which is
the convention in the control industry.
To find the gain margin with its crossover frequency (Gm, Wcg) and phase margin
with its crossover frequency (PM, Wcp) include the following command in the script
M-file: [Gm,Pm, Wcg, Wcp] = margin(G).
MATLAB Script M-file:
G = tf(1, [1 0.1 1]);
bode(G)
[Gm,Pm, Wcg, Wcp] = margin(G)
Results:
Gm = Inf
Pm = 8.1082
Wcg = Inf
Wcp = 1.4108

247
Exercises
10.1 Derive the transfer function for the differential equation:

𝑑2𝑦 𝑑𝑦 𝑑𝑈 𝑑𝑦
+ 0.4 + 𝑦= + 3u, y(0) = (0) = 0, u(0) = 0
𝑑𝑡 2 𝑑𝑡 𝑑𝑡 𝑑𝑡

10.2 Show that the state-space representation of equation in problem 10.1 is:

dx1
dt 0 1 x1 0
[dx ]=[ ] [x ] + [ ]u
2 −1 − 0.4 2 1
dt

10.3 The mass balance of a well-mixed tank can be written (with concentrations as
deviations):

𝑑𝐶
τ = 𝐶𝑖𝑛 - C, with C(0) = 𝐶0
𝑑𝑡

What is the time domain response C (t) if the change in inlet concentration is:
(a) A unit-step function
(b) An impulse function

10.4 Plot the root-locus of the following system.

𝐶 2𝑠2 +2
=
𝑅 𝑠2 +2𝑠+3

10.5 Do the SISO plots for the linear system

𝐶 2𝑠2 +5
=
𝑅 𝑠2 +3𝑠+3

10. 6 Generate the Bode diagram for the system with the following closed-loop
characteristic equation:
1 + (2𝑠 2 + 0.5𝑠 + 1) = 0
(a) Find the gain margin with its crossover frequency .
(b) Find the phase margin with its crossover frequency.

248
Appendix A Degrees of Freedom
A.1 Checking Independence of Algebraic Equations:
For a set of equations to be independent, no equation can be obtained by
manipulating any set of the other equations in the system.
Consider the following set of equations:
x1 + x2 = 3
2x1 – 3x2 = – 4
x1 + 4x2 = 9
The third equation is dependent because this equation can be obtained by subtracting
the first equation from the second equation. Similarly, the flow rate of toluene (T) in
the following four-component stream: B = 10%, T= 20%, X = ….%, D = ....% is not
independent if the flow rate of benzene is given as, say, 80 moles/h, then the flow of
toluene would be 160 moles/h.
It should be noted that the existence of a zero degree of freedom is a pre-requisite but
not sufficient condition for the existence of a solution. For instance the following set of
equations has a zero degree of freedom the equations re may be contradictory as:
x1 + x2 = 10
2x1 + 2x2 = 22
A.2 Checking by Inspection
If a set of equations is such that in each equation there is an unknown variable which
is not present in any other equation. Then the whole set of equations is an
independent set.
A.3 Checking Using MATLAB Function rref
Check independence of following set of equations:
2x1 + 4x2 + 5x3 + 6x4 = 0.0
x1 + 4x2 - x3 + 3x4 = 0.0
4x1 - 2x2 + 2x3 + 4x4 = 0.0
3x1 + 4x2 + 5x3 + 6x4 = 0.0
Solution:
Construct the coefficient matrix A in the command window:
>>A = [2 4 5 6;
1 4 -1 3;
4 -2 2 4;
3 4 5 6]
>> R = rref(A)
R=
1 0 0 0
0 1 0 0
0 0 1 0
0 0 0 1

249
Therefore the set of the given four equations is independent. Note that no vector can
be obtained from any combinations of the other three vectors.
A.4 Consistency of Equations and Existence of Solutions
The following set of linear equations:
𝑎11 𝑥1 + 𝑎12 𝑥2 +... + 𝑎1n 𝑥n = 𝑐1
𝑎21 𝑥1 + 𝑎22 𝑥2 +... + 𝑎21 𝑥n = 𝑐2
....................................................
𝑎n1 𝑥1 + 𝑎n2 𝑥2 +...+ 𝑎nn 𝑥n = 𝑐n

has a coefficient matrix A:


𝑎11 𝑎12 … 𝑎1𝑛
𝑎21 𝑎22 … 𝑎2𝑛
A = [……………….]
𝑎𝑛1 𝑎𝑛2 … 𝑎𝑛𝑛
It also has a vector of unknowns x, and a vector of constants c:
The augmented matrix AUG is created by joining the vector to the columns of matrix
A as shown below:
𝑎11 𝑎12 … 𝑎1𝑛 𝑐1
𝑎21 𝑎22 … 𝑎2𝑛 𝑐2
AUG = [ … … … … … … … . ]
𝑎𝑛1 𝑎𝑛2 … 𝑎𝑛𝑛 𝑐𝑛
A.5 Definitions:
A.5.1 Order of a matrix
Matrix A has m rows and n columns and is said to be of order (mxn). If m=n, then
the matrix is a square matrix of order n.
A.5.2 What is a Vector
A special matrix with a single column is called a vector:
𝑥1
𝑥2
.
𝑥= .
.
[𝑥𝑛 ]
A.5.3 Determinant of matrix
The value of a determinant (which exists only for square matrices) can be calculated
from Laplace’s expansion theorem. To evaluate the determinant of a square matrix A
in MATLAB, use the built-in MATLAB function det (A).

250
A.5.4 Rank
The rank(r) of a matrix A is the order of the largest non-singular square matrix within
A. A matrix is singular if the determinant of the matrix is zero. In MATLAB, the
MATLAB function rank(A) gives the value of the rank (r). Consider the matrix A:
𝑎11 + 𝑎12 + ⋯ + 𝑎1𝑛
𝑎 + 𝑎22 + ⋯ + 𝑎2𝑛
A = [ 21 where r ≥ m
……………………… ]
𝑎𝑚1 + 𝑎𝑚2 + ⋯ + 𝑎𝑚𝑛
The largest square sub matrix within A is of order (mxn). If the determinant of this
(mxn) sub matrix is nonzero, then the rank of A is m (𝑟 = m). However, if the
determinant of the (mxn) sub matrix is equal to zero, then the rank of A is less than m
(𝑟 < m). The order of the next largest submatrix that can be located within A would
determine the value of the rank.
A.5.5 Existence of Solutions
A set of equations has a solution if, and only if, the rank of the augmented matrix is
equal to the rank of the coefficient matrix. If in addition the rank is equal to n (𝑟 = n),
the solution is unique. If the rank is less than n (𝑟 < n), there are more unknowns in
the set than there are independent equations.
A.5.6 Degree of freedom
The degree of freedom analysis is an accounting procedure for determining the
mathematical feasibility, as a pre-condition, for solving a set of equations. For such a
condition to exist, the degree of freedom should have a value of zero. In such a case,
the number of independent unknown variables should be equal to the number of
independent equations. The system is said to be under-specified if the number of
equations is less than the number of unknowns. Conversely, the system is over-
specified.
The degree of freedom represents the number of design variables or control variables
in a system. If a system has only one degree of freedom, then only one design variable
can be set independently and the rest of the system variables cannot be independently
selected and are called state variables.
Degree of freedom = Number of independent unknown variables – Number of
independent equations
The independent unknown variables can be flow rates, compositions, temperatures,
pressures, or other physiochemical properties for example.
The independent equations can be material balances, energy balances or given
mathematical relations between flow rates or compositions for example.
The degree of freedom can alternatively be calculated by the general relationship:
Degree of freedom = Number of all variables – Number of independent information
data
Information data can be in the form of material and energy balances, concentrations,
relations, reactor conversions, yields, selectivities, temperatures, heat loads, splitter
restrictions, ...,etc.
251
Here all variables include unknown and known (given) variable values (e.g. flow rates,
compositions ... etc). Independent information data includes both equations and given
variable values (e.g. material and energy balance equations, and relations).
Example A.1
The following diagram is for a chemical process. The mole fraction of component C
is given equal to 0.4.
Determine the degree of freedom of the feed stream.

Degree of freedom = Number of independent unknown variables – Number of


independent equations
The number of unknown variables is two (mole fractions of components A and
B).However these mole fractions are dependent through the relationship of the
summation of mole fractions:
𝑥𝐴 + 𝑥𝐵 + 𝑥𝐶 = 1.0
Therefore number of independent unknown variables is only one (𝑥𝐴 or 𝑥𝐵 ).
Degree of freedom = 1 – 0 = 1
On the basis of the alternative definition:
Degree of freedom = Number of all variables – Number of independent information
data
Number of all variables = 3, the three mole fractions
Number of independent information data = 2, (𝑥𝐶 = 0.4, and the relation: 𝑥𝐴 + 𝑥𝐵 +
𝑥𝐶 = 1.0)
For any stream:
Number of independent unknowns in any stream = Number of components in stream
– Number of independent given data for stream
Example A.2
Consider the following four-component stream which has a flow rate of 100 moles/h:

A 20 mol%
B
C 40 mol%
D

The number of independent variables = 4 – 2 = 2


In selecting a set of independent variables in this stream, we have several
combinations to choose from. We must be careful not to select the combination of

252
flow rates 𝑁𝐴 and 𝑁𝐶 because they are related i.e. 𝑁𝐶 = 2*𝑁𝐴 . Likewise if we choose
total flow rate 𝑁 as an unknown variable, then we should avoid choosing with it 𝑁𝐴 or
𝑁𝐶 .Therefore we limited to selecting any of the following combinations only.
𝑁𝐴 , 𝑁𝐵 or
𝑁𝐴 , 𝑁𝐷 or
𝑁𝐵 , 𝑁𝐶 or
𝑁𝐵 , 𝑁𝐷
Example A.3
In the following process, the ratio of the flow rate of stream (3) to that of stream (1) is
given equal to 0.3.
Determine:
(1)The degree of freedom for this unit
(2)The number of independent variables
(3)The number of independent equations
(4)Select a complete set of independent variables
(5)Write a MATLAB program to determine the concentrations in stream (4)
(a)Without using overall balances
(b)Using overall balances

Solution:
Take as basis 100 moles flow of feed stream (stream(1)
Take flow rates as system variables
(1)Table of degree of freedom:
The number of independent given concentrations is calculated as follows:
Number of independent given concentrations in stream(1) = 3
Number of independent given concentrations in stream(2) = 2
Number of independent given concentrations in stream(3) = 2
Total = 7

253
Note that the number of independent given concentrations in stream (1) for example
is 3 because the fourth concentration is not independent.

Table Appendix A_1: Degree of freedom table


Number of stream variables 13

Number of independent material balance equations 4


Number of independent given concentrations 7
Number of given stream flow rate relations 1
Basis 1
Degree of freedom Zero

Degree of freedom = 13 – (4+7+1+1) = 0.0


(2) Number of independent unknowns in any stream = Number of components in
stream – Number of independent given data for stream

Table Appendix A_2: Independent variables


Total number of independent
Stream Number 1 2 3 4 variables
- 1 1 3 5

(3) Number of independent equations:


Material balance equations = 4
Given relationships = 1
Total =5

(4) Selection of a set of independent variables


As a general rule, one can select as independent variables those variables without
given data (e.g. values of concentrations in this case)
Let us chose the following set of independent variables:
𝑁𝐴2 , 𝑁 3 , 𝑁𝐵4 , 𝑁𝐶4 , 𝑁𝐷4
(5)Before writing the program we must write the equations in terms of the selected
independent variables only.
At steady state: Output = input
Independent equations without using the overall balances:
Balance for species A: 0.77x𝑁 3 = 0.2x100 + 𝑁𝐴2
15
Balance for species B: 0.2x𝑁 3 + 𝑁𝐵4 = 0.25x100 + ( 5 )𝑁𝐴2
80
Balance for species C: 0.03x𝑁 3 + 𝑁𝐶4 = 0.4x100 +( 5 )𝑁𝐴2
Balance for species D: 𝑁𝐷4 = 0.15x100
The stream relation 𝑁 3 = 0.3x100

254
Mole fractions of stream 4:
stream_4 = 𝑁𝐵4 + 𝑁𝐶4 + 𝑁𝐷4
𝑥𝐵 = 𝑁𝐵4 / stream_4
𝑥𝐶 = 𝑁𝐶4 / stream_4
𝑥𝐷 = 𝑁𝐷4 / stream_4

(5)When writing independent equations using the overall balances, we will use same
set of equations except the balance for one specific species whose material balance
equation will be replaced by the overall balance as follows:
100
Overall balance: 𝑁 3 + 𝑁𝐵4 + 𝑁𝐶4 + 𝑁𝐷4 = 100 + ( 5 )𝑁𝐴2
Below are the two required MATLAB programs:
The set of equations is a set of 5 linear equations which will be solved by MATLAB
program as follows:
X = A\B
Where A is the coefficient matrix and B is the vector of constants:
Let 𝑁𝐴2 = 𝑥(1) , 𝑁 3 = 𝑥(2) , 𝑁𝐵4 = , 𝑁𝐶4 = 𝑥(4) , 𝑁𝐷4 = 𝑥(5)
The set of equations in terms of variables x is then:

Balance for species A: 0.77𝑥(2) = 0.2x100 + 𝑥(1)


15
Balance for species B: 0.2𝑥(2) + 𝑥(3) = 0.25x100 + ( 5 )𝑥(1)
80
Balance for species C: 0.03𝑥(2) + 𝑥(4)= 0.4x100 + ( )𝑥(1)
5
Balance for species D: 𝑥(5) = 0.15x100
The stream relation 𝑥(2) = 0.3x100
OR:
𝑥(1) - 0.77𝑥(2) = - 0.2x100
15
( 5 )𝑥(1) - 0.2𝑥(2) - 𝑥(3) = - 0.25x100
80
( 5 )𝑥(1) - 0.03𝑥(2) - 𝑥(4) = - 0.4x100
𝑥(5) = 0.15x100
𝑥(2) = 0.3x100
Therefore the coefficient matrix A is :
1 − 0.77 0 0 0
15
− 0.2 −1 0 0
5
A= 80
− 0.03 0 −1 0
5
0 0 0 0 1
[0 1 0 0 0]
The vector of constants is:

255
−20
−25
B = −40
15
[ 30 ]
MATLAB Program::

A = [1 -0.77 0 0 0;
15/5 -0.2 -1 0 0;
80/5 -0.03 0 -1 0;
0 0 0 0 1;
0 1 0 0 0];
B = [-20;-25;-40;15;30]; % B must be a column vector
% Use the “backslash” operator “\” :
x = A\B;
stream_4 = x(3) + x(4) + x(5);
B_fraction = x(3)/stream_4;
C_fraction = x(4)/stream_4;
D_fraction = x(5)/stream_4;
fprintf(' Component B mole fraction = %4.3f\n',
B_fraction)
fprintf(' Component C mole fraction = %4.3f\n',
C_fraction)
fprintf(' Component D mole fraction = %4.3f\n',
D_fraction)

Results:
>> MATLAB_Basics % MATLAB_Basics is the name of the script file.
Component B mole fraction = 0.214
Component C mole fraction = 0.672
Component D mole fraction = 0.114

A.5.7 Solution to problem 2.6 in chapter 2 (𝑺𝑶𝟑 plant):


The problem is correctly specified when the process degree of freedom is zero.

256
Table Appendix A_3: Degree of freedom table for sulphur plant

Table Appendix A_4: Table of Unknown variables

•You can set the flow rate of O2 in stream 7 equal to 0.5 but in this case you do not
need to use the given relation as an equation in the program
••The temp. of stream 8 is known from given pressure of 300 psia for saturated
steam.
••• The rate of reaction (r)

Function M file (for problem 2.6):


% Sulphur trioxide plant case study ( See Reklaitis page 531)
% symbols: D = sulphur dioxide, S = sulphur trioxide, O = oxygen, W = water
% ED4 is enthalpy of dioxide in stream number 4 for example.
% E4 is total enthalpy of stream number 4 for instance.
function f = sulphur(x)
O7 = x(1); D4 = x(2); O4 = x(3); S4 = x(4); r = x(5); T4 = x(6); ...
T5 = x(7); T6 = x(8); W8 = x(9);
% MB round reactor
f(1) = D4 - 1.0 + r; % D4 is flow rate of dioxide in stream 4
f(2) = O4 - O7 + 0.5*r; % O4 is flow rate of oxygen in stream 4
f(3) = S4 - r; % S4 is flow rate of trioxide in stream 4

257
% EB round reactor
Tref = 298; %25 C ; % Heat of reaction given = -23.52 kcal/mol at 25 Centigrade
%Use MATLAB function(integral)to integrate: exp(-x^2)*log(x)^2 as follows:
% y = @(x) exp(-x.^2).*log(x).^2
% Q = integral(y,Tref,T_final)
ED4 = D4*integral(@(x) 25.8+(5.8D-02)*x-(3.8D-05)*x.^2,Tref,T4);
EO4 = O4*integral(@(x) 29.8-(1.1D-02)*x-(4.3D-05)*x.^2,Tref,T4);
ES4 = S4*integral(@(x) 15.5+(1.5D-01)*x-(1.1D-04)*x.^2,Tref,T4);
E4 = (ED4 + EO4 + ES4)/4.18;%convert to cal/mol
E2 = (1.0*integral(@(x) 25.8+(5.8D-02)*x-(3.8D-05)*x.^2,Tref,698))/4.18;
E3 = (O7*integral(@(x) 29.8-(1.1D-02)*x-(4.3D-05)*x.^2,Tref,698))/4.18;
% Standard heat of reaction(25 C)= -23.52 kcal/gmol
% Heat removed from reactor = 10 kcal/gmol
f(4) = 1.5*10D+03 + r*(-23.52D+03) + E4 - (E2 + E3);
%EB round HE1
Tref = 698; % = 425 C
ED5 = D4*integral(@(x) 25.8+(5.8D-02)*x-(3.8D-05)*x.^2,Tref,T5);
EO5 = O4*integral(@(x) 29.8-(1.1D-02)*x-(4.3D-05)*x.^2,Tref,T5);
ES5 = S4*integral(@(x) 15.5+(1.5D-01)*x-(1.1D-04)*x.^2,Tref,T5);
E5 = (ED5 + EO5 + ES5)/4.18;%convert to cal/mol;
E1 = 1.0*integral(@(x) 25.8+(5.8D-02)*x-(3.8D-05)*x.^2,Tref,573)/4.8;
ED4 = D4*integral(@(x) 25.8+(5.8D-02)*x-(3.8D-05)*x.^2,Tref,T4);
EO4 = O4*integral(@(x) 29.8-(1.1D-02)*x-(4.3D-05)*x.^2,Tref,T4);
ES4 = S4*integral(@(x) 15.5+(1.5D-01)*x-(1.1D-04)*x.^2,Tref,T4);
E4 = (ED4 + EO4 + ES4)/4.18;%convert to cal/mol;
f(5) = E5 - (E1 + E4);
%EB round HE2
Tref = 298; % 25 C
ED5 = D4*integral(@(x) 25.8+(5.8D-02)*x-(3.8D-05)*x.^2,Tref,T5);
EO5 = O4*integral(@(x) 29.8-(1.1D-02)*x-(4.3D-05)*x.^2,Tref,T5);
ES5 = S4*integral(@(x) 15.5+(1.5D-01)*x-(1.1D-04)*x.^2,Tref,T5);
E5 = (ED5 + EO5 + ES5)/4.18;%convert to cal/mol;
ED6 = D4*integral(@(x) 25.8+(5.8D-02)*x-(3.8D-05)*x.^2,Tref,T6);
EO6 = O4*integral(@(x) 29.8-(1.1D-02)*x-(4.3D-05)*x.^2,Tref,T6);
ES6 = S4*integral(@(x) 15.5+(1.5D-01)*x-(1.1D-04)*x.^2,Tref,T6);
E6 = (ED6 + EO6 + ES6)/4.18;%convert to cal/mol;
E3 = O7*integral(@(x) 29.8-(1.1D-02)*x-(4.3D-05)*x.^2,Tref,698)/4.18;
f(6)= E6 + E3 - E5;
%EB round Boiler
Tref = 673 ;% 400 C
ED6 = D4*integral(@(x) 25.8+(5.8D-02)*x-(3.8D-05)*x.^2,Tref,T6);
EO6 = O4*integral(@(x) 29.8-(1.1D-02)*x-(4.3D-05)*x.^2,Tref,T6);

258
ES6 = S4*integral(@(x) 15.5+(1.5D-01)*x-(1.1D-04)*x.^2,Tref,T6);
E6 = (ED6 + EO6 + ES6)/4.18;%convert to cal/mol;
% 0.0 = E9 - E8 - E6
%LATENT_HEAT = 1885 kJ/kg = 1885/4.182 cal/gram = 450.74 cal/gram
% E9 - E8 = W8*LATENT_HEAT
f(7)= W8*450.74 - E6;
%Conversion
f(8) = 1.0 - D4 - 0.96;
% Given SO2 to O2 ratio
f(9)= O7 - 0.5*1;

Script file Sulphur_solve to run M file sulphur.m

% Script file to run sulphur.m


x0 = 10*diag(ones(9));
options.MaxFunEvals = 2000;
options.MaxIter = 2000;
options.TolX = 1e-12;
[x,fval,exitflag] = fsolve(@sulphur,x0,options)
fprintf('Steam production rate = %6.2f g\n',x(9))
fprintf('Temp. of stream 6 = %8.2f K\n',x(8))

Results:
Steam production rate = 11.50 g
Temp. of stream 6 = 1024.69 K

259
260
Appendix B Chemo-Physical Property Data[20]
B.1 Heat of Formation and Other Thermodynamic Data

261
262
263
264
B.2 Heat Capacity Data

265
266
References
1. G.V.Reklaitis,”Introduction to Material and Energy Balances”, John Wiley
and Sons, 1983.
2. Kamil.M.Wagialla,”Computer-Aided Material and Energy Balances for
Chemical Engineering Students”,Arab Scientific Publishers, Beirut, 2003.
3. Michael. B. Cutlip and Mordechai Shacham,” Problem Solving in Chemical
Engineering with POLYMATH, Excel and MATLAB”, Second Edition,
Prentice Hall International Series, 1999.
4. Michael. B. Cutlip and Mordechai Shacham,” Problem Solving in Chemical
Engineering with Numerical Methods”, Prentice Hall International
Series,1999.
5. Rizwan Butt and Yacine Benhadid,”Introduction to Numerical Analysis with
MATLAB”, Adwa’a Al-Muntada printing press, 2005.
6. Rizwan Butt,”Introduction to Numerical Analysis Using MATLAB”,Jones and
Bartlett Publishers,2010.
7. Mahmoud M. El-Halwagi,”Sustainable Design through Process Integration”,
Elsevier Inc., 2012.
8. Richard I. Burden and J.Douglas Faires,”” Numerical Analysis”, Ninth
Edition,CENGAGE Learning, 2011.
9. Mohammad Nuruzzaan,”Modeling and Simulation in simulink for Engineers
and Scientists”,authorHOUSE (USA) , 2004.
10. Kenneth J. Beers,”Numerical Methods for Chemical Engineers Applications
in MATLAB”,Cambridge University Press, 2007.
11. Ekkehard Holzbecher, Environmental Modeling Using MATLAB, Second
Edition, Springer, 2012.
12. William Menke and Joshua Menka, “Environmental Data Analysis with
MATLAB”, Elsevier, 2012.
13. Agam Kumar Tyagi,”MATLAB and Simulink for Engineers”, Fifth
Impression,Oxford University Press, 2015.
14. Steven C. Chapra and Raymond P. Canale,”Numerical Methods for
Engineers”, McGraw-Hill, Fifth ed., 2006.
15. Holly Moore,”MATLAB for Engineers”,Third edition, PEARSON, 2013.
16. Constantinides, A., and Mostoufi, N.,” Numerical Methods for Chemical
Engineers with MATLAB Applications, Ist ed., Upper Saddle River,
NJ:Prentice Hall,1999.
17. Luca Zamboni,”Getting Started with Simulink”,PACKT Publishing, 2013.
18. T.F.Edgar and D.M.Himmelblau,”Optimization of Chemical
Processes”,McGraw-Hill International Editions, 1989.
19. Elnashaie S. and Uhlig F., “Numerical Techniques for Chemical and
Biological Engineers Using MATLAB”, Springer 2007.
20.Richard M Felder and Ronald W. Rousseau,” Elementary Principles of
Chemical Processes”, Third Edition, 2005, John Wiley & Sons, Inc.

267
21. Pao C. Chau,”Process Control A First Course with MATLAB”,Cambridge
University Press, 2002.
22. Donald R. Coughanowr,”Process Systems Analysis and Control”, second
edition, McGraw-Hill International editions, 1991.
23. Agam Kumar Tyagi,” MATLAB and SIMULINK for Engineers”,Oxford
University Press, fifth Impression, 2015.
24. H. Scott Fogler,” Elements of Chemical Reaction Engineering”,Prentice Hall
International Series,Fourth edition, 2006.

268

You might also like