You are on page 1of 37

Computer Aided Chemical Engineering-I: Lab Manual

AISSMS COLLEGE OF ENGINEERING

DEPARTMENT OF CHEMICAL ENGINEERING

COMPUTER AIDED CHEMICAL ENGINEERING I: LAB MANUAL

LIST OF ASSIGNMENTS
Assignment
Title Page No
No
1 Numerical Interpolation 1
2 Numerical Integration 5
3 Integration of ODE 8
4 Numerical Differentiation 12
5 Root-Finding Method 15
6 Data Fitting 17
7 Process Calculation Using MS-EXCEL 20
8 Application of Neural Networks 23
9 Non-linear Optimization Methods 30
10 Design of Algorithms 33

Department of Chemical Engineering, AISSMSCOE, Pune Page 0


Computer Aided Chemical Engineering-I: Lab Manual

ASSIGNMENT NO.: 1

NUMERICAL INTERPOLATION

Aim: To develop computer program for the numerical interpolation of a chemical engineering
problem.

Interpolation
Interpolation is defined as the technique of calculating the value of a function for any
intermediate value of independent variable. If we are given the various values of y=f(x) for a
given set of value of x i.e.
x
y =f(x)
Then the process of finding the value of y corresponding to any value of x is called interpolation
The value of y can be found for the given range of x0 to xn (i.e. between x0 to xn ) or inside
the given range is called interpolation.
While the process of computing the value of function outside the given range is called
extrapolation. i.e. the process of finding the value of y for xn+2 or xn+3 is called extrapolation.
Engineering Applications:
Interpolation is often required in engineering and scientific investigation. For example
1. For a particular case, the various values of current and voltage are measured and
tabulated as

I (Amp) 0.8 -0.65 0.92 1.23


V (Volts) 0.32 0.89 1.03 2.12

Then the voltage drop across the current I=0.9 Amp can be calculated by interpolation

Polynomial Forms:
• Although it seems that there exists a relationship between two variables (x and y i.e.
y=f(x), but we do not know what that relationship is.
• It is not possible to find out the value of y corresponding to value of x which does not
appear in the table.
• In such cases we may consider a polynomial

Department of Chemical Engineering, AISSMSCOE, Pune Page 1


Computer Aided Chemical Engineering-I: Lab Manual

y = a0 + a1 x + a2 x 2 + ⋯ … … … . . +an x n
• The equations is such that it satisfies all the given points from
(x0 , y0 ), (x1 , y1 ) (x2 , y2 ) … … … … … . . (xn , yn )
• All these point will lie on the curve obtained from polynomial equation.
• The unknown value of yg at a given value ofxg . i.e. point (xg , yg ) will also lie on the
curve. We cannot say the polynomial equation defines the function y=f(x) precisely.
• This is because the values other than (xg , yg ) may satisfy the function y=f(x) but may
not satisfy the polynomial equation. Hence the polynomial equation is called
polynomial approximation of the function y=f(x).

Various Methods of Interpolation:


Following are the methods of interpolations
1. Langrange’s Interpolation
2. Newton’s Forward Difference Interpolation
3. Newton’s Backward Difference Interpolation
4. Hermite Interpolation
5. Cubic Spline Interpolation

When the values of x are equispaced i.e. when step size h is same for all values of x i.e. x1 −
x0 = x2 − x1
Then we use,
• Newton’s Forward Difference Method
• Newton’s Backward Difference Method
• Cubic Spline Interpolation

Interpolation by Finite Differences:


When the interpolation points are equally spaces, the values of the interpolation polynomial
can be expressed in terms of finite differences.
Suppose that for xi = x0 + ih , where h is grid size, the values f0,f1 , f2 , … … … … fn of the
function f(x) are known. The differencef0,f1 , f2 , … … … … fn are then called finite differences of
first order.
Furthermore, we define the differences of order k + 1 inductively by
∆k+1 fi = ∆k fi+1 − fi
Furthermore, we define the differences of order k + 1 inductively by

Department of Chemical Engineering, AISSMSCOE, Pune Page 2


Computer Aided Chemical Engineering-I: Lab Manual

Operator∆ − Forward Difference operator


Operator ∇ −Backward Difference operator
Operator δ − Central Difference operator
Forward Difference Table:
I X Y ∆1 ∆2 ∆3 ∆4
0 x0 y0 ∆1 y0 ∆2 y0 ∆3 y0 ∆4 y0
1 x1 y1 ∆1 y1 ∆2 y1 ∆3 y1
2 x2 y2 ∆1 y2 ∆2 y2
3 x3 y3 ∆1 y3
4 x4 y4

Netwon’s Forward Difference Interpolation Formula:


u(u + 1) 2 u(u + 1)(u + 2) 3
yp = y0 + u∆y0 + ∆ y0 + ∆ y0 +. . … … … … … … …
2! 3!
xg − x0
Where, u =
h

Note this formula is used for interpolating the values of y near the beginning of the set of the
tabulated values and also for extrapolating values of y a little backwards (to the left) of y0 .
Backward Difference Table:
I X Y ∇1 ∇2 ∇3 ∇4
0 x0 y0
1 x1 y1 ∇1 y1
2 x2 y2 ∇1 y2 ∇2 y2
3 x3 y3 ∇1 y3 ∇2 y3 ∇3 y3
4 x4 y4 ∇1 y4 ∇2 y4 ∇3 y4 ∇4 y4

Newton’s Backward Difference Interpolation Formula:


u(u + 1) 2 u(u + 1)(u + 2) 3
yp = yn + u∇yn + ∇ yn + ∇ yn +. . … … … … … … …
2! 3!
xg − xn
Where, u =
h

Problem Statement: For the data tabulated in the following table,

Department of Chemical Engineering, AISSMSCOE, Pune Page 3


Computer Aided Chemical Engineering-I: Lab Manual

x 0 2 4 6 8
y -77.5 -69.7 -51.5 15.5 169.7

Calculate y at x = 1.2 using Newton Forward Interpolation.

ASSIGNMENT NO.: 2

NUMERICAL INTEGRATION

Department of Chemical Engineering, AISSMSCOE, Pune Page 4


Computer Aided Chemical Engineering-I: Lab Manual

Aim: To develop computer program for the numerical integration of a chemical engineering
problem.

Introduction:

Fig. 1 Integration by Area under the Curve

Integration is the process of measuring the area under a function plotted on a graph.
b
I = ∫a f(x)dx where f(x)is called the integrand and is given at discrete value of x,
a = lower limit of integration
b = upper limit of integration
Numerical Methods Integration:
1. Trapezoidal Method:
The trapezoidal rule can also be derived from geometry. The area under the curve f1 (x)
is the area of a trapezoid.
b
The integral ∫a f(x)dx =area of trapezoid
1
= (sum of length of parallel sides)(perpendicular distance between parallel sides)
2

Department of Chemical Engineering, AISSMSCOE, Pune Page 5


Computer Aided Chemical Engineering-I: Lab Manual

Fig. 2 Integration by Trapezoidal Method

If a = x0 and b = x1 then h = (x1 − x0 )


For Single step: If a = x0 and b = x1 then h = (x1 − x0 )
b x1
h
∫ f(x)dx = ∫ f(x)dx = [f(x0 ) + f(x1 )]
2
a x0

For multiple step: If Lower Limit = x0 and Upper limit = xn


Then h = (x1 − x0 ) = (x2 − x1 ) and hx1 = x0 + h
xn
h
∫ f(x)dx = [f(x0 ) + 2f(x1 ) + 2f(x2 )+ . . … … … … . +f(xn )]
2
x0

2. Simpson’s 1/3rd Rule:


For Single step: If Lower Limit = x0 and Upper limit = x2 then h = (xn+1 − xn )
x2
h
∫ f(x)dx = [f(x0 ) + 4f(x1 ) + f(x2 )]
3
x0

For Multiple steps: If Lower Limit = x0 and Upper limit = xn


xn
h
∫ f(x)dx = [f(x0 ) + 4f(x1 ) + 2f(x2 ) + 4f(x3 ) + 2f(x4 ) . . … … … … . +4f(xn−2 )
2
x0

+ 2f(xn−1 ) + f(xn )]
Because the above form has 1/3rd in its formula, it is called Simpson’s 1/3rd Rule. Number of
subintervals (h) is a multiple of 2.
3. Simpson’s 3/8th Rule:
For Single step: If Lower Limit = x0 and Upper limit = x3 then h = (xn+1 − xn )

Department of Chemical Engineering, AISSMSCOE, Pune Page 6


Computer Aided Chemical Engineering-I: Lab Manual

x3
3h
∫ f(x)dx = [f(x0 ) + 3f(x1 ) + 3f(x2 ) + f(x3 )]
8
x0

For Multiple steps: If Lower Limit = x0 and Upper limit = xn


xn
3h
∫ f(x)dx = [f(x0 ) + 3f(x1) + 3f(x2 ) + 2f(x3 ) + 3f(x4 ) . . … … … … . +2f(xn−3)
8
x0

+ 3f(xn−2 ) + 3f(xn−1 ) + f(xn )]


Because the above form has 1/3rd in its formula, it is called Simpson’s 1/3rd Rule. Number of
subintervals (h) is a multiple of 2.
Method No. of steps Multiplier Single Step Multiple
Steps
Trapezoidal Any integer h 1-1 1-2-1
Rule 2

Simpson’s 1/3rd Even h 1-4-1 1-4-2-4-1


Rule 3

Simpson’s 3/8th Multiple of 3 3h 1-3-3-1 1-3-3-2-3-3-1


Rule 8

Problem Statement: Pure Ethylene is heated from 0⁰C to 30⁰C at a constant pressure.
Calculate heat added per kmol of ethylene using the following equation

Cp=2.83+(28.601*10^-3*T)-(87.26*10^-7*T2)
Use (a) Trapezoidal Rule
(b) Simpson’s 1/3rd Rule
(c) Simpson’s 3/8th Rule

Department of Chemical Engineering, AISSMSCOE, Pune Page 7


Computer Aided Chemical Engineering-I: Lab Manual

ASSIGNMENT NO.: 3

INTEGRATION OF ODE

Aim: To develop computer program for the numerical integration of a chemical engineering
batch reaction operation.

Introduction:
An equation that consists of derivatives is called a differential equation. Differential equations
have application in all areas of science and engineering. Mathematical formulation of most of
the physical and engineering problems lead to differential equations.
1) Ordinary Differential Equation (ODE)
2) Partial Differential Equation (PDE)
An ordinary differential equation is that in which all the derivatives are w.r.t. a single
independent variable.
Examples of ordinary differential equation include
d2 CA dCA dCA
+ 2 + C A = 0, ( ) = 2, CA at t=0 = 4
dt 2 dt dt t=0
d3 CA d2 CA dCA d2 CA dCA
+ 3 + 5 + CA = sin t, ( ) = 12, ( ) C =4
dt 3 dt 2 dt dt 2 at t=0 dt at t=0 A at t=0

Ordinary differential equations are classified in terms of order and degree


• Order is the same as the highest order derivative
• Degree is the power of highest order derivative
e.g.

3
d3 CA 2
d2 CA dCA
t 3
+t 2
+t + tCA = et Order = 3 and Degree = 1
dt dt dt

2
dCA dCA
( + 1) + t 2 = sin t. . … . Order = 1 and Degree = 2
dt dt

Department of Chemical Engineering, AISSMSCOE, Pune Page 8


Computer Aided Chemical Engineering-I: Lab Manual

Taylor Series Method:


dCA
Consider the differential method = f(t, CA ) with initial condition of CA (t 0 ) = CA 0
dt

If CA (t) is the exact solution then CA (t) can be expanded into Taylor’s series about point t =
t 0 is
(t − t 0 )2 ′′ (t − t 0 )3 ′′′
CA (t) = CA 0 + (t − t 0 )CA ′ 0 + CA 0 + CA 0 + . . … . . (I)
2! 3!
Where dashed indicates the differentiation of CA w. r. t. ′t′
Substituting t = t 0 and CA = CA 0in the expression forCA ′ , CA ′′ ,CA ′′′ , .. …etc. and
dCA
substituting them in equation (I) we get solution for ( )
dt t=t0

Note:
1. Taylor’s series has advantage that is derived in any order and values of y(x) are easily
obtained.
2. However, method suffers from time consumed in computing higher derivatives.
Euler’s Method:
• Oldest and simplest method
• Determine the change ∆CAis CA corresponding to the small increment in the argument
t.
dCA
Consider differential equation = f(t, CA ) with initial condition of CA (t 0 ) = CA 0
dt

Integrating w.r.t. t between t 0 and t1, we get


CA1 t1 t1

∫ dCA = ∫ f(t, CA )dt then CA1 = CA0 + ∫ f(t, CA )dt


CA0 t0 t0

Now replacing f(t, CA ) by the approximationf(t 0 , CA0 ), we get


t1

CA1 = CA0 + ∫ f(t 0 , CA0 )dt


t0

= CA0 + (t1 − t 0 )f(t 0, CA0 )

= CA0 + hf(t 0 , CA0 ). . … … … where (t1 − t 0 ) = h


Similarly,
CA2 = CA1 + hf(t1 , CA1 )
CA3 = CA2 + hf(t 2 , CA2 )

Department of Chemical Engineering, AISSMSCOE, Pune Page 9


Computer Aided Chemical Engineering-I: Lab Manual

In general,
CA(n+1) = CA(n) + hf(t n , CA(n) )
Modified Euler’s Method:
Instead of approximating f(t, CA ) by f(t 0 , CA0 ).Let the integral approximated by
trapezoidal rule to obtain
h
CA1 (1) = CA0 + [f(t 0 , CA0 ) + f(t 0 + h, CA1 )]
2
h
CA1 (2) = CA0 + [f(t 0 , CA0 ) + f(t 0 + h, CA1 (1) )]
2
h
CA1 (3) = CA0 + [f(t 0 , CA0 ) + f(t 0 + h, CA1 (2) )]
2
|
|
h
CA1 (n+1) = CA0 + [f(t 0 , CA0 ) + f(t 0 + h, CA1 (n) )]
2
This is called as modified Euler’s Method which gives great improvement in accuracy over
the original method.

Runge-Kutta 2nd Order Method:


By Modified Euler’s Rule,
h
CA1 (n+1) = CA0 + [f(t 0 , CA0 ) + f(t 0 + h, CA1 (n) )]
2
It is rewritten as,
1
CA1 = CA0 + [k1 + k 2 ]
2
Where,
k1 = hf(t 0 , CA0 ) and k 2 = f(t 0 + h, k1 )
Runge-Kutta 4th Order Method:
dCA
Consider differential equation dt
= f(t, CA ) with initial condition of CA (t 0 ) = CA 0

CA1 = CA0 + k
Where,
k1 = hf(t 0 , CA0 )
h k1
k 2 = hf (t 0 + , CA0 + )
2 2
h k2
k 3 = hf (t 0 + , CA0 + )
2 2

Department of Chemical Engineering, AISSMSCOE, Pune Page 10


Computer Aided Chemical Engineering-I: Lab Manual

k 4 = hf(t 0 + h, CA0 + k 3 )
Finally compute,
1
k= (k + k 2 + k 3 + k 4 )
6 1

Problem Statement: The equations describing the series of isothermal CSTRs were developed
in,
(dCA1/dt) = (1/)*(CA0-CA1)-k*CA1
(dCA2/dt) = (1/)*(CA1-CA2)-k*CA2
(dCA3/dt) = (1/)*(CA2-CA3)-k*CA3

where the initial value of C A=1.8, CA1=0.4, CA2=0.2, CA3=0.1 and t = 0


while the values of const. k = 0.5,  = 2, h = 0.5 and final time is 2.9
Determine the solution of the ODEs using
(a) Euler’s method
(b) R-K fourth order

Department of Chemical Engineering, AISSMSCOE, Pune Page 11


Computer Aided Chemical Engineering-I: Lab Manual

ASSIGNMENT NO.: 4

NUMERICAL DIFFERENTIATION

Aim: To develop computer program for the numerical differentiation of a given chemical
engineering problem.

Theory: In numerical analysis, two different approaches are commonly used:

i. Finite difference
ii. Finite element methods.

In heat transfer problems, the finite difference method is used more often and will be
discussed here.

The finite difference method involves:

a. Establish nodal networks


b. Derive finite difference approximations for the governing equation at both interior
and exterior nodal points
c. Develop a system of simultaneous algebraic nodal equations
d. Solve the system of equations using numerical schemes

Methodology: Following problem is given,


Laplace equation

The Laplace equation comes under the category of elliptical differential equation and is given
when the function is independent of time i.e. steady state condition.

The Laplace equation in steady state for T(x,y) is given by

 2T  2T
+ =0
x 2 y 2

From the finite difference approximation we can write, Txx and Tyy as

Department of Chemical Engineering, AISSMSCOE, Pune Page 12


Computer Aided Chemical Engineering-I: Lab Manual

Ti +1, j − 2Ti , j + Ti −1, j


Txx = and
x 2

Ti , j +1 − 2Ti , j + Ti , j −1
Tyy =
y 2

The Laplace equation becomes,

Ti +1, j − 2Ti , j + Ti −1, j Ti , j +1 − 2Ti , j + Ti , j −1


+ =0
x 2 y 2

Problem Statement: A steel plate of 750 X 750 mm has its adjacent sides maintained at
temperature given in the figure below. What will be the steady state temperature at interior
point assuming a grid size of 250 mm.

Methodology:

The steel plate is drawn as follows,

Fig. 1 Heated Plate at steady state

Apply the formula for Laplace equation in finite difference form as :

T2 − 2T1 + 0 T4 − 2T1 + 0
2
+ =0
( 250 ) ( 250 ) 2

Department of Chemical Engineering, AISSMSCOE, Pune Page 13


Computer Aided Chemical Engineering-I: Lab Manual

which becomes :

-4T1 +T2+0T3+T4= 0

Similarly for T2, T3 and T4 we get :

T1 -4T2+T3+0T4= -100

0T1 +T2-4T3+T4= -200

T1 +0T2+T3-4T4= -100

The system of equations can be solved in Excel using matrix functions or MATLAB:

Department of Chemical Engineering, AISSMSCOE, Pune Page 14


Computer Aided Chemical Engineering-I: Lab Manual

ASSIGNMENT NO.: 5

ROOT-FINDING METHOD

Aim: To develop computer program for the determination of roots of a nonlinear equation.

Solution of non-linear algebraic equation

The solution of a non-linear algebraic equation is nothing but root finding method. Before the
advent of digital computers, there were several ways to solve for roots of algebraic and
transcendental equations. For some cases, the roots could be obtained by direct methods, as for
quadratic equations. Although there were equations like this that could be solved directly, there
were many more that could not. For example, even an apparently simple function such as f(x)
= e−x − x cannot be solved analytically. In such instances, the only alternative is an approximate
solution technique. One method to obtain an approximate solution is to plot the function and
determine where it crosses the x-axis. This point, which represents the x-value for which f(x)
= 0, is the root. Although graphical methods are useful for obtaining rough estimates of roots,
they are limited because of their lack of precision. An alternative approach is to use trial and
error. This “technique” consists of guessing a value of x and evaluating whether f(x) is zero. If
not (as is almost always the case), another guess is made, and f(x) is again evaluated to
determine whether the new value provides a better estimate of the root. The process is repeated
until a guess is obtained that results in an f(x) that is close to zero.

By definition, a function given by y = f(x) is algebraic if it can be expressed in the form

fn + fn−1 + · · · + f1 + f0 = 0

where fi = an ith-order polynomial in x. Polynomials are a simple class of non-linear algebraic


functions while other nonlinear functions can be transcendental, trigonometric,
exponential, logarithmic, and other, less familiar, functions.

The commonly used numerical methods for root-finding are:


i. Bisection Method
ii. Newton Raphson Method
iii. Regula False Method

Department of Chemical Engineering, AISSMSCOE, Pune Page 15


Computer Aided Chemical Engineering-I: Lab Manual

iv. Secant Method

Problem 1. The real equation of state of van der Waals is given as,

(p + a/v2) (v − b) = RT

where v = V/n is the molal volume and a and b are the empirical constants that depend on the
particular gas. A chemical engineering design project requires that you accurately estimate
the molal volume (v) of both carbon dioxide and oxygen for a given temperature and pressure
so that appropriate containment vessel can be selected. The following data are provided for
carbon dioxide:
R = 0.082054 L atm/(mol K)
a = 3.592
b = 0.04267
The design pressure of interest is 10 atm at a temperature of 500 K. Determine the molal
volume of the gas.

Methodology:

Newton Raphson Method


The computation of molal volume from the van der Waals equation can be accomplished using
any of the numerical methods for finding roots of equations, with

f(v) = (p + av2) (v−b) − RT

In this case, the derivative of f(v) is easy to determine and the Newton-Raphson method is
convenient and efficient to implement. The derivative of f(v) with respect to v is given by

f’(v) = p – a/v2 + 2ab/v3

The Newton-Raphson method is described by Eq. :

vi+1 = vi − f(vi) / f’(vi)

which can be used to estimate the root. For example, start with the initial guess of 24.61.

Department of Chemical Engineering, AISSMSCOE, Pune Page 16


Computer Aided Chemical Engineering-I: Lab Manual

ASSIGNMENT NO.: 6

DATA FITTING

Aim: To apply data-fitting to chemical engineering problem.

Introduction
Data fitting means to find a mathematical description for data. This mathematical description
should be “as close as possible” to the data. Obviously one has to define in a mathematical way
what is meant with “as close as possible”. Commonly the root mean squared error is used as a
measure for the deviation. To “fit” then means to find a minimum for the root mean squared
error.

To achieve this, a fit function f must be defined which generally contains adjustable parameters,
the fit parameters ai, i = 0 . . . n. Let’s consider the simple case of a set of data yk, k = 1 . . . M,
which are collected as a function of one independent variable x at the points xk. We would like
the fit function ‘f’ to describe these data in an approximate way as

yk ≈ f(a0, . . . an, xk) (1)

To find the parameters ai for the best approximation we have to minimize the appropriately
defined deviation. Instead of the root mean squared error we can minimize the sum over the
squared residuals
r = ∑ (yk − f(a0, . . . an, xk))2 (2)
which will yield the same results. The minimum is found by forcing the derivatives of r with
respect to all ai to be zero
∂r/∂a0 = 0, ∂r/∂a1 = 0, . . . , ∂r/∂an = 0 (3)
Whether and how these partial derivatives can be calculated depends on the detailed form of
the function f. It is obvious that a fit approximates the data the better the more parameters are
used.

Department of Chemical Engineering, AISSMSCOE, Pune Page 17


Computer Aided Chemical Engineering-I: Lab Manual

Problem Statement:
Fit a straight line to x and y values as given in table
x 1 2 3 4 5 6 7
y 0.5 2.5 2 4 3.5 6 5.5

Solve the above example by following methods.


(a) y=a0+a1x (linear) (b) y=a0+a1x+a2x2(quadratic)

(a) Line Fitting: y = a0 + a1 x


n=input('enter the value of n');
for i=1:n
x(i)=input('enter the value of x:');
y(i)=input('enter the value of y:');
end
sum0=0;
sum1=0;
sum2=0;
sum3=0;
for i=1:n
sum0=sum0+x(i);
sum1=sum1+y(i);
sum2=sum2+x(i)*y(i);
sum3=sum3+x(i)*x(i);
end
a=[n sum0;sum0 sum3];
b=[sum1;sum2];
c=inv(a)*(b);
disp (c)
p=c(1)
q=c(2)
disp('Output of linear model')
fprintf('y=%f*x+%f',p,q)

(b) Curve Fitting: y = a0 + a1 x + a2 x2

n=input('enter the value of n');


for i=1:n
x(i)=input('enter the value of x:');
y(i)=input('enter the value of y:');
end
sum0=0
sum1=0
sum2=0
sum3=0
sum4=0
sum5=0
sum6=0

Department of Chemical Engineering, AISSMSCOE, Pune Page 18


Computer Aided Chemical Engineering-I: Lab Manual

for i=1:n
sum0=sum0+x(i)
sum1=sum1+y(i)
sum2=sum2+x(i)*y(i)
sum3=sum3+x(i)*x(i)
sum4=sum4+((x(i)*x(i))*y(i))
sum5=sum5+(x(i)*x(i)*x(i))
sum6=sum6+(x(i)*x(i)*x(i)*x(i))
end
a=[n sum0 sum3;sum0 sum3 sum5;sum3 sum5 sum6]
b=[sum1;sum2;sum4]
c=inv(a)*(b)
disp (c)
p=c(1)
q=c(2)
r=c(3)
disp('Output of linear model')
fprintf('y=%f*x+%f*x*x+%f',p,q,r)

Department of Chemical Engineering, AISSMSCOE, Pune Page 19


Computer Aided Chemical Engineering-I: Lab Manual

ASSIGNMENT NO.: 7

PROCESS CALCULATION USING MS-EXCEL

Aim: To solve a chemical engineering process calculation problem using MS-Excel.

Introduction
STEADY STATE ANALYSIS OF A SYSTEM OF REACTORS
In quantitative term, the principle expressed as a mass balance that account for all sources and
links of material that pass in and out of a volume (I). over a finite period of time. This can
expressed as,
Accumulation = Input – Output.
The mass balance represents a book keeping exercise for the particular substance being
Modeled for the period of the computation, is the input are greater or less than output. The
mass of the substance within the volume increases. If the outputs are greater than the input, the
mass decreases. If inputs are equal to output zero accumulation and mass remain constant. For
this stable condition, or steady state equation (1) can be expressed as,
I/P = O/P
Employ the conservation of mass to determine steady state concentration of the system of
coupled reactors. Fig. shows problem setting where the computers are not only useful but are
a practical necessity because there are five inter connected or coupled reactors, five simulation
mas balance equation are needed characteristic of the system. For reactor (1), the rate of mass
flow in is,
5(10) +Q31*C3
and the rate of mass flow out is;
Q12*C1+Q15*C1
Because the system is at a steady state, the inflows of outflows must be equal,
5(10)+Q13.C3=Q12.C1.+Q15C1.
Substituting the values offlow rate from figure
-3C1 + 3C2 = 0
-C2 + 9C3 =160.
-3C2 – 8C3 + 11C4 – 2C5=0.
A numerical method can be used to solve these 5 eq n, the 5 unknown concentration are
:-

Department of Chemical Engineering, AISSMSCOE, Pune Page 20


Computer Aided Chemical Engineering-I: Lab Manual

{C}t=[11.51 11.51 19.06 17.00 11.51]


In addition matrix inverse can be completed. :-
A-1 = 0.16981 0.00629 0.01887 0 0
0.16981 0.33962 0.01887 0 0
0.01887 0.03774 0.11321 0 0
0.0603 0.07461 0.08748 0.091 0.045
0.16981 0.08962 0.01881 0 0.25
Each of the element aij signifies the change in concentration of reactor j. Thus the zero in
column 4 indicators that loading to a reactor 4 will have number impact on reactor 1, 2,3,4,5.
This is consist with the system configuration which indicate that flow out of reactor four does
not feedback in to any of the first three reactor will affect the entire system an indicated by lack
of zeros in the 1 st three column. Such information is of great utility for engineers who design 4
manage such system.

Fig. 1 System of reactors

Coefficient matrix: A

6 0 -1 0 0
-1 0 0 1 0
0 0 9 -1 0
0 2 8 1 -11

Department of Chemical Engineering, AISSMSCOE, Pune Page 21


Computer Aided Chemical Engineering-I: Lab Manual

-3 4 0 -1 0

matrix A inverse
0.169811 0.018868 0.018868 0 0
0.169811 0.268868 0.0188680 0 0.25
0.018868 0.113208 0.113208 0 0
0.169811 1.018868 0.018868 0 0
0.060034 0.223842 0.087479 -0.09091 0.045455

concentration matrix
50
0
160
0
0

solution vector
11.50943
11.50943
19.0566
11.50943
16.99828

Department of Chemical Engineering, AISSMSCOE, Pune Page 22


Computer Aided Chemical Engineering-I: Lab Manual

ASSIGNMENT NO.: 8

APPLICATION OF NEURAL NETWORKS

Aim: To study the applications of neural networks in chemical engineering.

Introduction

Traditional approaches of solving chemical engineering problems frequently have their


limitations, as for example in the modeling of highly complex and nonlinear systems.
Artificial neural networks (ANN) have proved to be able to solve complex tasks in a
number of practical applications in chemical engineering. We focus on certain kinds of
ANN that have proven themselves in solving real problems. Following are common
applications of ANN in chemical engineering:
1. Fault detection
2. Prediction of polymer quality
3. Data rectification
4. Modeling and control
The major advantages of ANN are that they can be highly nonlinear, second the structure
can be more complex and hence more representative, than most other empirical models,
third the structure does not have to be prespecified, and fourth, they are quite flexible
models.
An ANN forms a mapping F between and input space X and an output space Y, where we
can distinguish three different kinds of mappings:
1. Both the input and output spaces are comprised of continuous variables, a typical case
of process modeling;
2. The input space is comprised of continuous variables whereas the output space is
comprised of a finite set of discrete variables as in classification and fault detection;
3. Both the input space and the output space are comprised of discrete variables that are
mapped in so called associative nets (that will be ignored in this article).

Department of Chemical Engineering, AISSMSCOE, Pune Page 23


Computer Aided Chemical Engineering-I: Lab Manual

ARTIFICIAL NEURAL NETWORKS (ANN)

As the term artificial neural networks implies, early work in the field of neural networks
centered on modeling the behavior of neurons found in the human brain. Engineering
systems are considerably less complex than the brain; hence from an engineering
viewpoint ANN can be viewed as nonlinear empirical models that are especially useful in
representing input-output data, making predictions in time, classifying data, and
recognizing patterns.
The various type of ANN structures are:
1. Feedforward nets
2. Feedbackward nets
3. Recursive nets
4. Radial basis fimction nets

Fig. 1 Structure of Single Processing Node

Fig. 1 shows the basic structure of a single processing unit in an ANN which will be
referred to as a node in this work and is analogous to a single neuron in the human brain.
A node receives one or more input signals, Ii, which may come from other nodes or from
some outer source. Each input is weighted according to the value w i,j which is called a
weight. These weights are similar to the synaptic strength between two connected
neurons in the human brain. The weighted signals to the node are summed and the
resulting signal, called the activation, h, is sent to a transfer function, g, which can be any
type of mathematical function, but is usually taken to be a simple bounded differentiable
function such as the sigmoid (Fig. 2). If the function g is active over the entire input space,
it is termed a global transfer function in contrast with radial basis functions (to be
described subsequently) thatare local functions. The resulting output of the node Oj, may
then be sent to one or more nodes as an input or taken as the output of an ANN model.

Department of Chemical Engineering, AISSMSCOE, Pune Page 24


Computer Aided Chemical Engineering-I: Lab Manual

Fig. 2 Plot a sigmoid transfer function

A collection of nodes connected to each other forms the artificial neural network.
Cybenko [1987] and numerous subsequent articles have shown that various networks of
such functions can approximate any input-output relation to the desired degree of
accuracy (in the limit exactly). You can find numerous other architectures in the
literature. Hybrid nets, that is nets composed of different or similar ANN, or nets
connected to other types of models that are not ANN also exist.

Output Layer

Hidden Layer

Hidden Layer

Input Layer

Fig. 3 Structure of a layered neural network

A group of nodes called the input layer receives a signal from some external source. In
general, this input layer does not process the signal unless it needs scaling. Another group
of nodes, called the output layer, return signals to the external environment. The
remaining nodes in the network, are called hidden nodes because they do not receive
signals from or send a signal to an external source or location. The hidden nodes may be

Department of Chemical Engineering, AISSMSCOE, Pune Page 25


Computer Aided Chemical Engineering-I: Lab Manual

grouped into one or more hidden layers'. Each of tile arcs between two nodes (the lines
between the circles in Fig. 3) has a weight associated with it. Fig. 3 shows a layered
network in which the layers are fully connected from one layer to the next (input to
hidden, hidden to hidden, hidden to output). Although this type of connectivity is
frequently used, other patterns of connectivity are possible. Connections may be made
between nodes in nonadjacent layers or within the same layer, or feedback connections
from a node in one layer to a node in a previous layer can also be made. This layer type of
connection is called a recurrent connection to be discussed below and, depending on the
type of application for which the network is being used; such a connection may have a
time delay associated with it.
Another part of the jargon associated with ANN models relates to model identification.
Generally, there is no direct analytical method of calculating what the values of the
weights are if a network is to model a particular behavior of a process. Instead the
network must be trained on a set of data (called the training set) collected from the
process to be modeled. Training is just the procedure of estimating the values of the
weights and establishing thenetwork structure, and the algorithm used to do this is called
a "learning" algorithm. The learning algorithm is nothing more some type of optimization
algorithm. Once a network is trained, it provides a response with a few simple
calculations, one of the advantages of using an ANN instead of a first principles model in
cases for which the model equations have to be solved over and over again.
Case Study: FAULT DETECTION OF HEAT EXCHANGER OPERATION USING ANN
This example from Suewatann M [1993] demonstrates the use of a feedforward ANN to
detect faults in a heat exchanger. Fig. 4 is a sketch showing the input and output
measurements of an exchanger.

T2 F2
T1 T3
Heat Exchanger F3
F1

T4 F4

Fig. 4 Heat Exchanger at steady state

Department of Chemical Engineering, AISSMSCOE, Pune Page 26


Computer Aided Chemical Engineering-I: Lab Manual

The temperature and flow rate deviations from normal were deemed to be symptoms of
the physical causes of faults. The two physical causes considered faults here were tube
plugging and partial fouling in tile heat exchanger internals. The diagnostic ability of a
neural network is compared with Bayesian and KNN classifiers to detect die internal
faults. Rather than using data from an operating heat exchanger, the Simulation Sciences
code PROCESS was used to generate data fox- clean and fouled conditions fox a steady
state counter-current heat exchanger. To generate the data for both the clean and dirty
conditions, a data file for each faulty (and normal) condition was prepared. Information
about the thermodynamic properties of the streams, the fluid and exchanger physical
properties, the configuration of tile heat exchanger, the number of tubes, tile size of tile
tubes and shell, and the fouling layer thickness in the tube and shell sides (for fouled
conditions) was prespecified. Table 1 lists tile physical data and the normal parameters
for the heat exchanger:
Table 1 Prespecified data for the normally operating heat exchanger
Stream 1 Stream 2 Stream 3 Stream 4
Temperature, T(k) 533 977 708.2 599.8
Flow rate, F(kg/hr) 9080 4086 9080 4086
Pressure, P(kpa) 207 345 148 236

Tube side:
Feed: mixture of water: ethyl benzene: styrene of composition (weight percent)
55: 25:20
Number of tubes: 108; length: 4.88 In; outside tube diameter:
3.18 cm; thickness: 0.26 cm; tube arrangements: square tube pitch
3.97 cm; tube-side fouling layer thickness: 0
Shell side:
Feed: water
Inside diameter: 54 cm
Shell-side fouling layer thickness: 0 cm
In the study of fouling for the tube-side and the shell-side, the degree of fouling was
expressed as a function of the cross-sectional area which was also classified into 4 cases,
namely a decrease of 8%, 5%, 3%, and 1%, respectively. To make the simulated
measurements more realistic, two different levels of normally distributed noise were

Department of Chemical Engineering, AISSMSCOE, Pune Page 27


Computer Aided Chemical Engineering-I: Lab Manual

added to tile deterministic flows, pressure, and temperatures so that the coefficients of
variation of the noise were 0.02 and 0.01. Fig. 5 illustrates a typical feedforward ANN
used to classify tile respective faults. To train tile ANN, each measurements namely tile
temperatures of all four streams (T1, T2, T3, and T4), the two flow rates (F1 and F2), and
the pressure drops in the tube and shell size, for both the normal (clean) and faulty states
had to be linearly scaled to be between the range of- 1 and 1. The network was trained so
that 0.9 represented the normal state (yes) while 0.1 represented the faulty state (no).
For example, a target output pattern of 0.9 0.9 0.9 represented a pattern in which the heat
exchanger was clean. The target pattern formed a state in which there was one or more
totally-plugged tube was 0.1 0.9 0.9. The target output pattern of 0.9 0.1 0.9 represented
a state in which fouled tubes existed while a target output pattern of 0.9 0.9 0.1
represented a state in which fouling existed on the shell side. The training data set
contained 80 patterns each for the four different classes (a total of 320 training patterns).
Another set of 20 patterns for each class was used for testing the classification capability
of the ANN (a total of 80 patterns). NPSOL was the optimization code used in the training
of the ANN for testing the ANN, a threshold value of 0.5 for the output of an output node
was used as the discrimination criterion for classification. If the activation of an output
node was greater than 0.5, then that node was deemed activated and represented a faulty
state of the exchanger. If the node value was less than 0.5, then the node was deemed to
be not activated, and the fault was said not to occur. Table 2 lists the results for one set of
runs from the training and testing of the net. By way of comparison, the two traditional
classifiers, Bayesian and k-nearest neighbors, were also applied to the data sets. Table 2
lists the results. Multivariate hypothesis tests on the means of the measurements gave
much larger rates of misclassification. The conclusion is that ANN for this type of analysis
are no worse than traditional methods of classification, and may have some edge.
Table 2 Results for one set of runs from the training and testing of the net
Number of Bayes Procedure 5-NN procedure
totally Training Testing Training Testing
plugged % correct % correct % correct % correct
tubes
5 100 100 100 98.00
3 100 100 100 95.00
2 100 98.00 100 92.50
1 100 93.00 100 89.75

T1 T2 F1 F2 T3 T4 ∆Ptube ∆Psh
ell

Department of Chemical Engineering, AISSMSCOE, Pune Page 28


Computer Aided Chemical Engineering-I: Lab Manual

Input layer

12 hidden nodes

Output layer

Totally-plugged tubes Fouled tubes Fouled shell


(If no,Fig. 5A
output typical
=0.9, (Iffeedforward
no, output =0.9, ANN
(If no, output =0.9,
else, output=0.1) else, output=0.1) else, output=0.1)

Fig. 5 ANN for the Fault Detection Problem

Reference: David M. Himm elblau, Department of Chemical Engineering, Applications of


Artificial Neural Networks in Chemical Engineering, The University of Texas Austin, Texas
78731, U.S.A Korean Z Chem. Eng., 17(4), 373-392 (2000).

Department of Chemical Engineering, AISSMSCOE, Pune Page 29


Computer Aided Chemical Engineering-I: Lab Manual

ASSIGNMENT NO.: 9

NON-LINEAR OPTIMIZATION METHODS

Aim: To understand and apply non-linear optimization methods to chemical engineering


problem.

Introduction

Optimization is a process that finds a best, or optimal, solution your model. Not every
spreadsheet model requires optimization; however, the technique is very important when you
have model variables that you can control (e.g., spending) and you want a maximum or
minimum goal that relies on those variables

1. Nonlinear optimization

It is the process of solving a system of equalities and inequalities, collectively termed


constraints, over a set of unknown real variables, along with an objective function to be
maximized or minimized, where some of the constraints or the objective function is nonlinear.

2. Linear optimization

` These problems involve the optimization of a linear objective function, subject to linear
equality and inequality constraints

Put very informally, Linear optimization is about trying to get the best outcome (e.g. maximum
profit, least effort, etc.) given some list of constraints (e.g. only working 30 hours a week, not
doing anything illegal, etc.), using a linear mathematical model.

Following are some of the problems of optimization solved using MATLAB.

The command linprog

The command linprog from the MATLAB optimization toolbox implements the
simplex algorithm to solve a linear programming problem in the form:

min f * x

Subjected to A * x ≤ b

Department of Chemical Engineering, AISSMSCOE, Pune Page 30


Computer Aided Chemical Engineering-I: Lab Manual

where f is any vector and the matrix A and vector b define the linear constraints.

Problem Statement 1: The problem is translated into the format:

max(x,y) 143x+60y min(x,y) -143x-60y

Subjected to Subjected to

x + y ≤ 75

110x+30y ≤ 4000

20x+210y ≤ 1500

x ≥0 , y≥0

1 1 75
110 30 x 4000
20 210 [y] ≤ 1500
1 0 0
[ 0 1 ] [ 0 ]
Observe the switching of signs to turn the max into a min and to deal with the ≥ constraints.
Now we are ready to solve the problem. First we set up the vectors and matrices:

>> f = [−143 − 60]

>> A = [120 210; 110 30; 1 1; −1 0; 0 − 1]

>> b = [15000; 4000; 75; 0; 0]

The optimization toolbox has the command linprog:

>>linprog(f, A, b) % optimize

Optimization terminated.

ans=

21.875

53.173

The latest versions of MATLAB have the command simlp, which is very much like linprog.

Nonlinear optimization:

Department of Chemical Engineering, AISSMSCOE, Pune Page 31


Computer Aided Chemical Engineering-I: Lab Manual

Here we solve a unconstrained minimization example.

Problem Statement 2:

minimize
f(x)ex1 (4x1 2 + 2x2 2 + 4x1 x2 + 2x2 + 1)
x

To solve this two-dimensional problem, write an M-file that returns the function value. Then,
invoke the unconstrained minimization routine “fminunc”.

Step 1: Write an M-file objfun.m.function f = objfun(x)

f = exp(x(1))*(4*x(1)^2+2*x(2)^2+4*x(1)*x(2)+2*x(2)+1);

Step 2: Invoke one of the unconstrained optimization routines.x0 = [-1,1]; % Starting guess

options = optimset('LargeScale','off');

[x,fval,exitflag,output] = fminunc(@objfun,x0,options);

After 40 function evaluations, this produces the solution

x= 0.5000 -1.0000

The function at the solution x is returned in fval:

fval = 1.3030e-10

The exitflag tells whether the algorithm converged. An exitflag > 0 means a local minimum
was found: exitflag = 1

The algorithm used was: 'medium-scale: Quasi-Newton line search'

Optionsare a structure that contains values for termination tolerances and algorithm choices.
An options structure can be created using the optimset function:

Option = optimset('LargeScale','off');

In this example, we have turned off the default selection of the large-scale algorithm and so the
medium-scale algorithm is used. Other options include controlling the amount of command
line display during the optimization iteration, the tolerances for the termination criteria,
whether a user-supplied gradient or Jacobian is to be used, and the maximum number of
iterations or function evaluations.

ASSIGNMENT NO.: 10

Department of Chemical Engineering, AISSMSCOE, Pune Page 32


Computer Aided Chemical Engineering-I: Lab Manual

DESIGN OF ALGORITHMS

Introduction

Algorithm design is a specific method to create a mathematical process in solving


problems. Applied algorithm design is Algorithm engineering. Algorithm design is identified
and incorporated into many solution theories of operation research, such as dynamic
programming and divide-and-conquer. Techniques for designing and implementing algorithm
designs are algorithm design patterns, such as template method patterns and decorator patterns,
and uses of data structures, and name and sort lists. Some current day uses of algorithm design
can be found in internet retrieval processes of web crawling packet routing and caching.

Mainframe programming languages such as Algol (for Algorithmic language), Fortran,


Cobol, pl/i, sail, and Snobol are computing tools to implement an "algorithm design"... but, an
"algorithm design" (a/d) is not a language. An a/d can be a hand written process, eg. set of
equations, a series of mechanical processes done by hand, an analog piece of equipment, or a
digital process and/or processor.

Designing the right algorithm for a given application is a difficult job. It requires a
major creative act, taking a problem and pulling a solution out of the other. This is much more
difficult than taking someone else's idea and modifying it or tweaking it to make it a little better.
The space of choices you can make in algorithm design is enormous, enough to leave you
plenty of freedom to hang yourself. However, being a successful algorithm designer requires
more than book knowledge; it requires a certain attitude, the right problem-solving approach.

CASE STUDY: Genetic Algorithm

Genetic algorithms are search techniques based on the mechanics of natural selection which
combine a “survival of the fittest” approach with some randomization and/or mutation. The
technique can be summarized as follows:

1. “Individuals” are generated through random selection of the parameter space for each control
factor, and a “population” is then produced from the set of individuals.

Department of Chemical Engineering, AISSMSCOE, Pune Page 33


Computer Aided Chemical Engineering-I: Lab Manual

2. A model (which may be analytical or multi-dimensional) is used to evaluate the fitness of


each individual.

3. The fittest individuals are allowed to “reproduce,” resulting in a new “generation” through
combining the characteristics from two sets of individuals. “Mutations” are also allowed
through random changes to a small set of the population.

4. The fitness criteria thin out the population by “killing off” less suitable solutions. The
characteristics of the individuals tend to converge to the most fit solution over successive
generations.

A pictorial description of the above four steps is presented in Fig. 1.

As described above, GAs is search techniques based on the concepts of natural evolution and
thus their principles are directly analogous to natural behavior. GAs works with a population
of individuals, each of which represents a candidate solution to a given optimization problem.
Just as organisms in nature compete for resources, a population’s individuals are assigned a
fitness based on a defined objective, or merit, function. Individuals with higher fitness prove
to be more effective, and hence have a higher probability of survival and reproduction. Thus,
the most fit parents produce new individuals, or children, which share some of their features
with each of the parents. The set of children form a new generation, while the less fit members
of the population tend to “die off” since they are less likely to be chosen for reproduction. The
new generation of individuals is likely to contain more of the good characteristics possessed
by fit members of previous generations. This process continually improves the average fitness
of a population, eventually leading to an optimum, or most fit, individual.

There are a number of characteristics that an optimization scheme should possess in order for
it to be an “ideal” search technique for use with multi-dimensional engine modeling, for
example. In particular, a scheme should be able to handle:

1. Multi-modal surfaces (i.e., many local extrema with only one global maximum or minimum)

2. Ill-behaved surfaces (i.e., discontinuous or noisy)

3. High-dimensionality and high parameter resolution

In addition, a few questions pertaining specifically to genetic algorithm search techniques must
be addressed, including:

Department of Chemical Engineering, AISSMSCOE, Pune Page 34


Computer Aided Chemical Engineering-I: Lab Manual

1. How does the initial (random) population affect convergence?

2. How many individuals should be included in a population?

3. How many generations until convergence?

Fig. 1 Illustration of a Simple Genetic Algorithm

This includes,

1) Production of the initial population,

2) and 3)Reproduction and crossover to form new generations,

4) Achievement of the fittest individual

The following describes the key components in the present search technique. Each section
includes an overview of the component, followed by a description of its implementation in the
gen4 code.

Read necessary parameters from input ga input file

Initialize population

Determine merit values for population


Department of Chemical Engineering, AISSMSCOE, Pune Page 35
Computer Aided Chemical Engineering-I: Lab Manual

Perform tournament
SelectionSeleselection

Generation Loop Population Loop Perform crossover

Create new generation

Check convergence of population

Write restart file

End

Fig. 2 Flowchart of the GA optimization code.

Department of Chemical Engineering, AISSMSCOE, Pune Page 36

You might also like