Sunday, November 28, 2010

MATLAB APPLICATION IN CHEMICAL ENGINEERING

MATLAB is a powerful code-based mathematical and engineering calculation
program. It performs all calculations using matrices and vectors in a logical programming
environment. This guide is a brief introduction to MATLAB in chemical engineering, and
in no way attempts to be a comprehensive MATLAB learning resource. This guide is a
starting point for the new MATLAB user, and as such no prior MATLAB experience is
necessary. Further help can be found in the MATLAB help files or at Mathworks website
at www.mathworks.com and in the help section at
http://www.mathworks.com/access/helpdesk/help/techdoc/matlab.shtml
Section I: How MATLAB works
Most MATLAB commands can be run from the command window (shown below,
on the right hand side of the interface). MATLAB commands can also be entered into a
text file labeled with the ‘.m’ extension. These files are known as ‘m-files’. These
commands can be broken down into scripts and programming. Scripts can be thought of
as commands that instruct MATLAB to execute a particular function or pre-made
program, and programming can be thought of as the raw code required to construct
functions and programs within MATLAB. Generally, all programming must be contained
within a file used by MATLAB (called an m-file), but script can be entered either in an
m-file or directly into the command window. An image of the MATLAB interface is
shown below







MATLAB contains many ready-made programs or functions that are conveniently
arranged into different toolboxes. When using MATLAB, these toolboxes and their
functions can be called upon and executed in any MATLAB script. In the above image,
the toolbox selection or launch pad is shown (at the left hand side of the interface).
Basic MATLAB: The language
MATLAB uses a language that is somewhat similar to that of Maple1. The scripts
or calling functions have a particular name and argument that must be entered into the
function execution call. For example, to plot the sine function in MATLAB between 0
and 6 using the fplot command, the following code can be entered directly into the
command window, or into an m-file:


(One can define the function sin(x) in an m-file and replace the fplot command to be
fplot(‘filename’,[0,6]))
Before going much further, an understanding of the structure of a MATLAB
simulation or execution must be developed.
M-files
M-files contain programming, scripts, equations or data that are called upon
during an execution. If the m-file is a function definition, then the most important part of
this type of m-file is the first line. The first line must contain the function definition so
that MATLAB can find those m-files that are called upon. These types of m-files are
called function m-files or function files. The code used to define the function file is as
follows:

‘file_name’ is simply the name of the m-file (the filename must be the same in the
definition and the file-name), z is the dependant variable, and x and y are the independent
variables. (Of course, one can have less or more independent variables depending upon
the complexity of the problem and the equations involved.) The next few lines of script in
the m-file can define the function or functions and label any required variables. The
following is an example of an m-file used to plot the natural logarithm2 function.
To produce a plot of this function, the following code is entered into the command
window:
This yields a plot of ln(x) between x= 1 and x= 5.
2 MATLAB uses ‘log’ as the natural logarithm function, and ‘log10’ as logarithm base ten.

 to be continued...

NUMERICAL METHODS IN CHEMICAL ENGINEERING


Course Description
Numerical methods for solving problems arising in heat and mass transfer, fluid mechanics, chemical reaction engineering, and molecular simulation. Topics: numerical linear algebra, solution of nonlinear algebraic equations and ordinary differential equations, solution of partial differential equations (e.g. Navier-Stokes), numerical methods in molecular simulation (dynamics, geometry optimization). All methods are presented within the context of chemical engineering problems. Familiarity with structured programming is assumed. The examples will use MATLAB®.

EXPRESSING SYSTEMS OF LINEAR ALGEBRAIC EQUATIONS AS: Ax=b

We wish to solve systems of simultaneous linear algebraic equations of the general form:


a11x1 + a12x2 + … + a1nxn = b1

a21x1 + a22x2 + … + a2nxn = b2

::

::

an1x1 +an2x2 + … + annxn = bn (1.1.1-1)

Where we have N equations for the N unknowns x1, x2, …, xn.

As a particular example, consider the following set of these three equations (N=3) for the three unknowns x1, x2, x3:

x1 + x2 + x3 = 4

2x1 + x2 + 3x3 = 7

3x1 + x2 +6x3 = 2 (1.1.1-2)

aij = constant coefficient (usually real) multiplying unknown xj in equation #i.

Bi = constant “right-hand-side” coefficient for equation #i.

For the system (1.1.1-2) above,

a11 = 1 a12 = 1 a13 = 1 b1 = 4

a21 = 2 a22 = 1 a23 = 3 b2 = 7

a31 = 3 a32 = 1 a33 = 6 b3 = 2

It is common to write linear systems in matrix/vector for as:


Ax=b (1.1.1-3)

Where the vector of unknowns x is written as:

x = (1.1.1-4) n::21xxx

The vector of right-hand-side coefficients b is written:

b = (1.1.1-5) n::21bbb

The matrix of coefficients A is written in a form with N rows and N columns,

A = (1.1.1-6) nna ...aaa: : : :: : : :a ...aaaa ...aaa n3 n2 n12n 23 22 211n 13 12 11

We see that row ‘i’ contains the values ai1, ai2, …, aiN that are the coefficients multiplying each unknown x1, x2, …, xN in equation #i.

Rows �� equations Columns �� coefficients multiplying a specific unknown in each equation.

aij = element of A in ith row and jth column

= coefficient multiplying xj in equation #i.
 
After we will write the coefficients in matrix form explicitly, so that we may


write Ax=bas:

nna ...aaa: : : :: : : :a ...aaaa ...aaa n3 n2 n12n 23 22 211n 13 12 11N21x::]xx = (1.1.1-7) n::21bbb

For the example system (1.1.1-2):

x1 + x2 + x3 = 4

2x1 + x2 + 3x3 = 7

3x1 + x2 +6x3 = 2 (1.1.1-2, repeated)

We have:

A = 6 1 33 1 21 1 1b = (1.1.1-8) 



274

As we will represent our linear systems as matrices “acting on” vectors, some review of basic vector notation is required.
For full lecture on this course and lecture notes, email us at millenniumtutors@yahoo.com

Second Module
http://clickserve.cc-dt.com/link/tplclick?lid=41000000011066022&pubid=21000000000269318

1.2.3 Pivoting Techniques in Gaussian Elimination


Let us consider again the 1st row operation in Gaussian Elimination, where we start with the original augmented matrix of the system. to get the full articles, email us at millenniumtutors@yahoo.com

Analyst