0% found this document useful (0 votes)
26 views33 pages

Lect-1 - P1 - Computer Applications

Chemical engineering computer applications chemiCad

Uploaded by

ali.basaleh.2014
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)
26 views33 pages

Lect-1 - P1 - Computer Applications

Chemical engineering computer applications chemiCad

Uploaded by

ali.basaleh.2014
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/ 33

Department of Chemical Engineering

Faculty of Engineering & Petroleum


Hadhramout University

1
coding and simulation tools for the solution of
chemical and process engineering problems
including MATLAB coding

 Introduction to MATLAB
o Matrices and Factors Operation
o Functions and Plots
o Iterations and Conditions
 Identify how to write algorithms and Matlab codes to solve chemical
engineering related problems, and the required data and inputs to
simulators.

2
Introduction
MATLAB (MATrix LABoratory) is an interactive software system for
numerical computations and graphics.

• MATLAB is especially designed for matrix computations, solving


systems of linear and nonlinear equations, integration of ordinary
and partial differential equations, and many others.

• MATLAB widely used in the engineering. It has many features and it


could take years to learn all of its capabilities(skills).

• MATLAB offers (provide) a powerful programming language,


excellent graphics, and a wide range of expert knowledge.
3
How is MATLAB used in chemical engineering?

MATLAB and Simulink for the Chemicals and Petrochemicals


Industry. Process engineers use MATLAB and Simulink to
analyze real-time sensor data, implement control
strategies, and create predictive maintenance systems
based on big data and machine learning.

4
 Getting Started
Start Matlab by double clicking the icon on the desktop, or
from the start menu. To use Matlab you can simply enter
commands after the prompt (the >> is the Matlab prompt).

Figure 1 below shows the default frame with the three


standard Matlab windows. 5
The command window is the active window
immediately appears after launching Matlab.
The workspace window lets you examine
what you have stored in your workspace.
The Command history window lets you
recall previously entered commands.
6
7
MATLAB is a high-performance language for technical
computing. It integrates computation, visualization, and
programming in an easy-to-use environment where problems
and solutions are expressed in familiar mathematical notation.
Typical uses include:
• Math and computation.
• Algorithm development.
• Modeling, simulation, and prototyping.
• Data analysis, exploration, and visualization.
• Scientific and engineering graphics.
• Application development, including Graphical User Interface
building.
8
o Matrices and Factors Operation

• Entering Matrices
You can enter matrices into MATLAB in several different ways:
• Enter an explicit list of elements.
• Load matrices from external data files.
• Generate matrices using built-in functions.
• Create matrices with your own functions in M-files.

Start by entering Dürer’s matrix as a list of its elements. You


have only to follow a few basic conventions:
• Separate the elements of a row with blanks or commas.
9
• Use a semicolon ( ; ) to indicate the end of each row.
• Surround the entire list of elements with square
brackets, [ ].
To enter Dürer’s matrix, simply type:
A = [16 3 2 13; 5 10 11 8; 9 6 7 12; 4 15 14 1]
 Matrix Operation
 Define row matrix A= [1 2 3 4 5]
• Type the following command
» A=[1 2 3 4 5]

A=12345 10
Example 9-1

Define Colum matrix

11
Solution
Type the following command

12
 Assessing the matrix element in the format of (row, column);
for example : C=B(1,4) would give 4 as an answer.

Example 9-2
Define Colum matrix

» B=[1 2 3 4 5]

Find:
C=B(1,4) 13
14
o Entering matrices into Matlab is the same as entering a vector,
except each row of elements is separated by a semicolon (;) or a
return:
o >>B = [1 2 3 4; 5 6 7 8; 9 10 11 12]
B=
1 2 3 4
5 6 7 8
9 10 11 12

15
o The special character prime ' denotes the transpose of a matrix e.g.

16
o Addition and subtraction of matrices are denoted by + and -. This operations
are defined whenever the matrices have the same dimensions.

For example: If A and B are matrices, then Matlab can compute A+B and A-B
when these operations are defined.

17
o Matrices can be joined together by treating them as elements of vectors:

18
o Matrix operations simply act identically on each element of an array. We have
already seen some vector operations, namely + and - , which are defined for
vectors the same as for matrices. But the operators * , / and ^ have different
matrix interpretations.

19
o Matrix division: To recognize how the two operator / and \ work

20
o Matrix Inverse: The function inv is used to compute the inverse of a matrix.
Let, for instance, the matrix A be defined as follows:

21
 Maths operators

22
o Square root ( )

• >> r = sqrt(9)
value of r has been replaced by 3
23
One can use Matlab like a calculator without specifying
variables. Matlab has all the standard mathematical operations.
Try type:
Example 9-3

24
Solution:

25
Example 9-4
The volume of a circular cylinder of height h and radius r is given by
V = πr² h. A particular cylindrical tank is 15 m tall and has a radius of
8 m. We want to construct another cylindrical tank with a volume
20 percent greater (20% V)but having the same height. How large
must its radius be?

Solution :

26
Solution :
we can use the MATLAB

27
• Matrix Division and Linear Algebraic Equations

You can use the left division operator (\) in MATLAB to solve sets
of linear algebraic equations. For example, consider the set

To solve such sets in MATLAB you must create two arrays; we will call them A and
B. The array A has as many rows as there are equations, and as many columns as
there are variables. The rows of A must contain the coefficients of x, y, and z in
that order.
28
29
• The Matrix Inverse Method

Solve the following equations, using the matrix inverse.

30
HW#1
Use MATLAB to compute the following expressions.

1. 3
27 + 32(0.2) Ans: = 5

(2)
8
2. 4 − 12 − Ans: = 3
4×2
2
3. 8(3) + + 5 Ans: = 514.9
3
4. Ans. =

5. Ans. =
31
6. A= [1 2 3 7; 0 2 4 5; 10 1 2] B= [1 2 3 7; 0 2 4 5; 10 1 2]

Find:
(1) A +B
(2) X=A’
(3) C = X/B
(4) Z=B(2,3)

7. The ideal gas law relates the pressure P, volume V, absolute temperature
T, and amount of gas n. The law is where R is the gas constant. P V= nRT
Calculate molar volume of gas.
Given data:
Pressure P =2.2 atm
Temperature T=15 ᴼC
R= 0.082 Lit atm/mol K 32
8. Suppose x takes on the values x = 1, 1.2, 1.4, . . . , 5. Use
MATLAB to compute the array y that results from the function y
= 7 sin(4x). Use MATLAB to determine how many elements are
in the array y, and the value of the third element in the array y.

9. Use MATLAB to solve the following set of equations.

33

You might also like