Download as pdf or txt
Download as pdf or txt
You are on page 1of 27

3/17/2022

C.W.2

where;
P= 0.95; T= 300; R=0.08206; a= 6.49; b=0.0562

Working on Array Elements

2
3/17/2022

From the command windows in MATLAB

We can define a array and matrix using the


following syntax

4
3/17/2022

From the command windows in MATLAB

From the command windows in MATLAB

6
3/17/2022

From the command windows in MATLAB

From the command windows in MATLAB

8
3/17/2022

From the command windows in MATLAB

Changing value of an element

From the command windows in MATLAB


Changing value of an element

10
3/17/2022

From the command windows in MATLAB

11

THE COLON OPERATOR

The colon operator is extremely powerful, and provides a very


efficient way of handling matrices, e.g., if Z is the matrix
defined by:

This is how it is introduced in MATLAB:


>> z=[1 3 5; 7 9 11; 13 15 17]
z=
1 3 5
7 9 11
13 15 17
6

12
3/17/2022

THE COLON OPERATOR

Let us evaluate some expressions containing colon (range)


notation.
>> z(:,1) this is equivalent to
ans=
1
7
13
>> z(1,:) this is equivalent to
ans=
1 3 5
>> z(1:2,1:2) this is equivalent to
ans=
1 3
7 9
13

THE COLON OPERATOR

>> Column_Vect=Z(:) >> Sub_Z=Z(:,[1,2])


Column_Vect= Sub_Z=
1 1 3
7 7 9
13 13 15
3
9
15
5
11
17

14
3/17/2022

ARRAY (ELEMENT-BY-ELEMENT) OPERATIONS ON


MATRICES

15

ARRAY (ELEMENT-BY-ELEMENT)
OPERATIONS ON MATRICES
Example

Consider the following two matrices A & B:

A.*B is an element-wise (i.e., element by element)


multiplication of A & B. That means C elements are created as
follows:

16
3/17/2022

ARRAY (ELEMENT-BY-ELEMENT)
OPERATIONS ON MATRICES

Using MATLAB;
>> A=[1 2; 3 4]
A=
1 2
3 4
>> B=[5 6; 7 8]
B=
5 6
7 8
>> C=A.*B
C=
5 12
21 32
17

ARRAY (ELEMENT-BY-ELEMENT)
OPERATIONS ON MATRICES

Matrix addition and subtraction


are defined based on an element-by-element array operation.

Using MATLAB;
>> E=A+B
E=
6 8
10 12

>> F=A-B
F=
-4 -4
-4 -4
9

18
3/17/2022

ARRAY (ELEMENT-BY-ELEMENT)
OPERATIONS ON MATRICES

The matrix multiplication A*B


for A and B requires that the number of columns of A must
equal the number of rows of B; otherwise the matrix
multiplication cannot be carried out.

19

ARRAY (ELEMENT-BY-ELEMENT)
OPERATIONS ON MATRICES

Using MATLAB for the same previous Example,

>> D=A*B
D=
19 22
43 50
10

20
3/17/2022

ARRAY (ELEMENT-BY-ELEMENT)
OPERATIONS ON MATRICES
Example 2
Consider the following two matrices A & B:

Using MATLAB
>> A[1 2, 3 4]; B=[2;3]; D=A*B
D=
8
18

21

ARRAY (ELEMENT-BY-ELEMENT)
OPERATIONS ON MATRICES
Matrix Exponentiation
The matrix operation A2 means A × A, where A must be a
square matrix. The operator ^ is used for matrix
exponentiation.
Example 3
Using MATLAB
>> A[1 2, 3 4]
A 1 2
3 4
>> A*A
>> A^2 ans=
ans= 7 10
7 10 15 22
15 22 11

22
3/17/2022

OPERATORS USED IN MATRIX


MATHEMATICS

AT → A’
A×A → A*B
A÷B → A/B
AX → A^X SQUAR MATRIX
A-1B → A\X

23

TRANSPOSE

12

24
3/17/2022

TRANSPOSE

A
+ Shift Key
+ Quotation mark key

25

SOME MATRIX ALGEBRA FUNCTIONS

dot ( )
cross ( )
inv ( )
det ( )

13

26
3/17/2022

DOT PRODUCTS

[ 1 2 3]

[ 4 10 18 ]

32!!
Scalar value

27

CROSS PRODUCTS

14

28
3/17/2022

IN MATLAB

29

MATRIX POWERS

15

30
3/17/2022

Solution of a System
of Linear Equations
Dr. Emile M. Al-Mayah
Biochemical Engineering Department
Al-Khwarizmi College of Engineering
University of Baghdad

31

Solution of a System of Linear Equations

 Using MATLAB to solve a systems with linear


equations.
 Review the basic concepts and properties of the
linear equation systems.
 Using MATLAB commands to Solve typical
biochemical engineering problems that are
formulated with a system of linear equations.

16

32
3/17/2022

SOLUTIONS TO SYSTEMS OF LINEAR EQUATIONS

AX=B

X=A-1B

33

USING MATRIX NOMENCLATURE

17

34
3/17/2022

SOLUTIONS TO SYSTEMS OF LINEAR EQUATIONS

We can solve this problem using the matrix


inverse approach.

35

MATRIX LEFT DIVISION

• Matrix left division:


A\B is more efficient alternatives.
• It also has less round off error.
• A related function are rref(A) for
calculating the reduced row
echelon from of A.

18

36
3/17/2022

MATRIX LEFT DIVISION

37

EXAMPLE CALCULATING THE CENTER OF


MASS (CENTER OF GRAVITY)

19

38
3/17/2022

EXAMPLE CALCULATING THE CENTER OF


MASS

39

IN THIS EXAMPLE…

20

40
3/17/2022

INPUT AND OUTPUT

41

HAND EXAMPLE

21

42
3/17/2022

WE KNOW THAT…

43

WE KNOW THAT…

22

44
3/17/2022

WE KNOW THAT…

45

WE KNOW THAT…

23

46
3/17/2022

WE KNOW THAT…

47

Biochemical Engineering problems of linear equation systems and


the relevant MATLAB commands

Example 3 the liquid blending problem


Suppose a customer requests a blended product of 40 liters, in
which the volume fraction (%) of each component (A, B, C, D,
and E) should be 25, 18, 23, 18, and 16, respectively. Assuming
that the density is unchanged, determine the volume usage of
each tank to meet the specification.
Table 1.1 Volume fraction of components in each tank.
Volume fraction of each component (%)
Tank
number
A B C D E
1 55.8 7.8 16.4 11.7 8.3
2 20.4 52.1 11.5 9.2 6.8
3 17.1 12.3 46.1 14.1 10.4
4 18.5 13.9 11.5 47.0 9.1
5 19.2 18.5 21.3 10.4 30.6
24

48
3/17/2022

Example 2 (continue)

Mass balance of component A:


55.8V1 + 20.4V2 + 17.1V3 + 18.5V4 + 19.2V5 = 25×40 ...(1)

Mass balance of component B:


7.8V1 + 52.1 V2 + 12.3 V3 + 13.9 V4 + 18.5 V5 = 18×40 …(2)

Mass balance of component C:


16.4V1 + 11.5 V2 + 46.1 V3 + 11.5 V4 + 21.3 V5 = 23×40 …(3)

Mass balance of component D:


11.7V1 + 9.2 V2 + 14.1 V3 + 47.0 V4 + 10.4 V5 = 18×40 …(4)

Mass balance of component E:


8.3V1 + 6.8 V2 + 10.4 V3 + 9.1 V4 + 30.6 V5 = 16×40 …(5)

49

 55.8 20.4 17.1 18.5 19.2   V1   1000 


 7.8 52.1 12.3 13.9 18.5   V   720 
  2  
 16.4 11.5 46.1 11.5 21.3   V3    920  (a)
    
 11.7 9.2 14.1 47.0 10.4   V4   720 
 8.3 6.8 10.4 9.1 30.6   V5   640 
     

A x  b (b)

25

50
3/17/2022

>> A= [ 55.8 20.4 17.1 18.5 19.2


7.8 52.1 12.3 13.9 18.5
16.4 11.5 46.1 11.5 21.3
11.7 9.2 14.1 47.0 10.4
8.3 6.8 10.4 9.1 30.6]; % matrix A
>> b=[1000 720 920 720 640]'; % vector b (column vector)
>> x =A\b % find the solution
x=
6.8376
4.1795
8.6398
7.3268
13.0163

51

H.W.1
Composition analysis of a distillation column system

The following Figure schematically illustrates a


distillation column system that is used to separate the
following four components: para-xylene, styrene,
toluene, and benzene (Cutlip and Shacham, 1999).
Based on the required composition of each exit stream
shown in this figure, calculate (a) the molar flow rates
of D2, D3, B2, and B3, and (b) the molar flow rates and
compositions of streams of D1 and B1.

26

52
3/17/2022

H.W.1

53

27

You might also like