Вы находитесь на странице: 1из 28

TECHNOLOGICAL INSTITUTE OF THE PHILIPPINES

363 P. Casal St., Quiapo, Manila

CHEP 530D1
COMPUTER APPLICATIONS
IN
CHEMICAL ENGINEERING

Crispulo G. Maranan
Instructor

Bautista, Keziah Lynn S.


No. 1
Familiarization with Matlab Environment,
Built-in Functions, Matrices and Plotting

Laboratory Exercise
November 9, 2013

Laboratory Exercise No. 1


Familiarization with Matlab Environment, Built-in Functions, Matrices and Plotting
1. Objective(s):
The activity aims to familiarize the students with matlab environment, built-in functions, matrices and
plotting.
2. Intended Learning Outcomes (ILOs):
The students shall be able to:
2.1 get acquainted with matlab environment and its various features.
2.2 understand the built-in functions of matlab.
2.3 Operate on the matrices.
2.4 Plot different graphs using matlab.
3. Discussion:
Matlab is a powerful language for technical computing. Its basic data element is matrix (array).It
can be used for math computations, modeling and simulations, data analysis and processing,
visualization and graphics, and algorithm development.
The standard Matlab program has tools (functions) that can be used to solve common problems.
The array is a fundamental form that Matlab uses to store and manipulate data. An array is a list
of numbers arrange in rows or in columns. The simplest array (one-dimensional) is a row, or a column of
numbers. A more complex array (two-dimensional) is a collection of numbers arranged in rows and
columns. One use of array is to store information and data, as in a table. In science and engineering,
one-dimensional arrays frequently represent vectors and two-dimensional arrays represent matrices.
Once variables are created in Matlab they can be used in a wide variety of mathematical
operations. Matlab is designed to carry out advanced array operations that have many applications in
science and engineering. Addition and subtraction are simple operations. The other basic operations,
multiplication, division and exponentiation can be done in Matlab in two different ways. One way, which
uses the standard symbols (*,/ and ^), follows the rules of linear algebra. The second way, which is called
element-by-element operations, uses the symbols .*,./ and .^ ( a period is typed in front of the standard
operation symbol).In both types of calculations, Matlab has left division operator (.\ or \).
4. Resources:
Matlab
5. Procedure:
1.Identify the different matlab windows and write its corresponding purpose.
2.Note the different symbols used in the command window and write its corresponding use.
3.Use matlab as a calculator and show the results in the accompanying table.
4.Note the different built-in functions and show the results in the accompanying table.
5.Evaluate the results after pressing the enter key for the assignment operator (=).
6.Evaluate the results after pressing the enter key for the creation of vectors (row vector and column
vector) from a known list of numbers, with constant spacing by specifying the first term, the spacing, and
the last term, with constant spacing by specifying the first and last terms,and the number of terms
7.Evaluate the results after pressing the enter key for the creation of two-dimensional array (matrix).
Bautista, Keziah Lynn S.
No. 1
Familiarization with Matlab Environment,
Built-in Functions, Matrices and Plotting

Laboratory Exercise
November 9, 2013

8.Evaluate the results after pressing the enter key using colon (:) in addressing arrays.
9. Identify the different built-in functions for handling array and indicate its description and give an
example.
10.Evaluate the results after pressing the enter key that involves strings and strings as variables.
11. Evaluate the results after pressing the enter key that involves the operations of matrices.
12.Evaluate the values of x, y and z of the three equations three unknowns :
4x 2y + 6z = 8
2x + 8y + 2z = 4
6x + 10y + 3z = 0
13.Evaluate the results after pressing the enter key that involves element-element operations.
14.Identify the different built-in functions for analyzing arrays and indicate its description and give an
example.

Course:
Group No.:
Bautista, Keziah Lynn S.
No. 1
Familiarization with Matlab Environment,
Built-in Functions, Matrices and Plotting

Laboratory Exercise No.:1


Section:CH51FA1
Laboratory Exercise
November 9, 2013

Group Members:

6. Data and Results:


1.
Window
1.Command Window

2.Figure Window

3.Editor Window

4.Help Window
5.Launch Pad Window
6.Command History
7.Workspace Window
8.Current Directory

Date Performed: November 9, 2013


Date Submitted: November 11, 2013
Instructor:Engr. Crispulo Maranan

Purpose
Inputs the commands to be use. It is used to
execute commands or aliases directly in the
Visual
Studio
integrated
development
environment (IDE). You can execute both menu
commands and commands that do not appear on
any menu. To display the Command window,
choose Other Windows from the View menu, and
select Command Window.
It is directed to a window that is separate from
the Command Window. This window is referred
to as a figure. The characteristics of this window
are controlled by your computer's windowing
system and MATLAB figure properties.
It is to create your own custom editor window
that can float free or be docked as a tab, just like
the native windows in the Unity interface. Editor
windows are typically opened using a menu item.
Helps you about the commands and other terms
to be used.
Access help, tools, demos and documentation
Compiles the history of the commands
It consist of common mathematical figures,
graphs, etc.
The directory (folder) that MATLAB is currently
working in. This is where anything you save will
go by default, and it will also influence what files
MATLAB can see. You won't be able to run a
script that you saved that you saved in a di
erent directory.

2.
Bautista, Keziah Lynn S.
No. 1
Familiarization with Matlab Environment,
Built-in Functions, Matrices and Plotting

Laboratory Exercise
November 9, 2013

Symbol
>>

;
%
clc

Purpose
Relational operators perform element-byelement comparisons between two arrays. They
return a logical array of the same size, with
elements set to logical 1 (true) where the
relation is true, and elements set to logical
0(false) where it is not.
Used inside brackets to end rows. sssUsed
after an expression or statement to suppress
printing or to separate statements.
Percentage. Used to indicate that the number
preceding it should be understood as a
proportion multiplied by 100
It clears all input and output from the Command
Window display, giving you a "clean screen."
After using clc, you cannot use the scroll bar to
see the history of functions, but you still can use
the up arrow key, , to recall statements from
the command history.

3.
Mathematical Expression
>> 8 + 5/9
>> (8 + 5)/9
>> 8^5/9
>>29^1/5 + 35^0.7

Result
8.5556
1.4444
3.6409e+03
17.8461

4.
Built-in Function
>>sqrt(144)
>>exp(7)
>>abs(-99)
>>log(100000)
>>log10(100000)
>>factorial(10)
>>sin(pi/4)
>>round(19/6)
>>rem(16,5)
>>sign(-19)

Result
12
1.0966e+03
99
11.5129
5
3658800
0.7071
3
1
-1

5.
>>x= 10
>>x=4*x -15
>>a = 10
>>B= 9
>>C= (a B) +50 a/B *16
Bautista, Keziah Lynn S.
No. 1
Familiarization with Matlab Environment,
Built-in Functions, Matrices and Plotting

10
25
10
9
33.2222
Laboratory Exercise
November 9, 2013

>>a=10,B=9; C= (a B) +50 a/B *16


>>x = 0.99;
>>E = sin(x)^3 + cos(x)^4
6.
>>yr = [ 2001 2002 2003 2004 2005]

33.2222
0.9900
0.6750
yr =
Columns 1 through 2
2001

2002

Columns 3 through 4
2003

2004

Column 5
2005
>>yr = [ 256; 299; 350; 402; 503]

yr =

>>y = [1:2:15]

256
299
350
402
503
y=
Columns 1 through 5
1

Columns 6 through 8
>>y = [1.5:0.1;2.0]
>>y=[-5:15]

11 13 15
2
y=
Columns 1 through 5
-5 -4 -3 -2 -1
Columns 6 through 10
0

Columns 11 through 15
Bautista, Keziah Lynn S.
No. 1
Familiarization with Matlab Environment,
Built-in Functions, Matrices and Plotting

Laboratory Exercise
November 9, 2013

Columns 16 through 20
10 11 12 13 14
Column 21
>>b = [21:-3:6]

15
b=
Columns 1 through 5
21 18 15 12

Column 6
>>a = linspace(0,8,6)

6
a=
Columns 1 through 3
0 1.6000 3.2000
Columns 4 through 6

>>b=linspace(30,10,11)

4.8000 6.4000 8.0000


b=
Columns 1 through 5
30 28 26 24 22
Columns 6 through 10
20 18 16 14 12
Column 11

>>c=linspace(49.5,0.5)

10
c=
Columns 1 through 3

Bautista, Keziah Lynn S.


No. 1
Familiarization with Matlab Environment,
Built-in Functions, Matrices and Plotting

Laboratory Exercise
November 9, 2013

49.5000 49.0051 48.5101


Columns 4 through 6
48.0152 47.5202 47.0253
Columns 7 through 9
46.5303 46.0354 45.5404
Columns 10 through 12
45.0455 44.5505 44.0556
Columns 13 through 15
43.5606 43.0657 42.5707
Columns 16 through 18
42.0758 41.5808 41.0859
Columns 19 through 21
40.5909 40.0960 39.6010
Columns 22 through 24
39.1061 38.6111 38.1162
Columns 25 through 27
37.6212 37.1263 36.6313
Columns 28 through 30
36.1364 35.6414 35.1465
Columns 31 through 33
34.6515 34.1566 33.6616
Columns 34 through 36
33.1667 32.6717 32.1768
Bautista, Keziah Lynn S.
No. 1
Familiarization with Matlab Environment,
Built-in Functions, Matrices and Plotting

Laboratory Exercise
November 9, 2013

Columns 37 through 39
31.6818 31.1869 30.6919
Columns 40 through 42
30.1970 29.7020 29.2071
Columns 43 through 45
28.7121 28.2172 27.7222
Columns 46 through 48
27.2273 26.7323 26.2374
Columns 49 through 51
25.7424 25.2475 24.7525
Columns 52 through 54
24.2576 23.7626 23.2677
Columns 55 through 57
22.7727 22.2778 21.7828
Columns 58 through 60
21.2879 20.7929 20.2980
Columns 61 through 63
19.8030 19.3081 18.8131
Columns 64 through 66
18.3182 17.8232 17.3283
Columns 67 through 69
16.8333 16.3384 15.8434
Bautista, Keziah Lynn S.
No. 1
Familiarization with Matlab Environment,
Built-in Functions, Matrices and Plotting

Laboratory Exercise
November 9, 2013

Columns 70 through 72
15.3485 14.8535 14.3586
Columns 73 through 75
13.8636 13.3687 12.8737
Columns 76 through 78
12.3788 11.8838 11.3889
Columns 79 through 81
10.8939 10.3990 9.9040
Columns 82 through 84
9.4091 8.9141 8.4192
Columns 85 through 87
7.9242 7.4293 6.9343
Columns 88 through 90
6.4394 5.9444 5.4495
Columns 91 through 93
4.9545 4.4596 3.9646
Columns 94 through 96
3.4697 2.9747 2.4798
Columns 97 through 99
1.9848 1.4899 0.9949
Column 100
0.5000

Bautista, Keziah Lynn S.


No. 1
Familiarization with Matlab Environment,
Built-in Functions, Matrices and Plotting

Laboratory Exercise
November 9, 2013

10

7.
>>a = [2 35 6;5 67 88;22 56 89]

>>b = [23 56 78 73 68
35 98 54 32 15
99 34 23 12 2]
>>cd = 9 ;e 6;h=8;
>>Ram=[e, cd*h,cos(pi/3);h^2,sqrt(h*h/cd),15]
>>Z= [1:2:11;0.0:5:25;linspace(10,60,6)]

a=
2 35 6
5 67 88
22 56 89
b=
23 56
35 98
99 34
Ram =
6.0000
64.0000
Z=

78 73 68
54 32 15
23 12 2
72.0000 0.5000
2.6667 15.0000

Columns 1 through 5
1 3 5 7 9
0 5 10 15 20
10 20 30 40 50
Column 6

>>zr=zeros(4,6)

11
25
60
zr =
Columns 1 through 5
0
0
0
0

0
0
0
0

0
0
0
0

0
0
0
0

0
0
0
0

Column 6
0
Bautista, Keziah Lynn S.
No. 1
Familiarization with Matlab Environment,
Built-in Functions, Matrices and Plotting

Laboratory Exercise
November 9, 2013

11

>>on=ones(3,4)

0
0
0
on =
1
1
1

1
1
1

>>we=eye(5)

1 1
1 1
1 1
we =
1
0
0
0
0
aa =

0
1
0
0
0

0
0
1
0
0

0
0
0
1
0

4
bb =

4
B=

3
8
2
C=

6
7
7

7
6
9

8
4
3

3
8
2

6
7
7

7
6
9

8
4
3

>>aa=[4 8 9]
>>bb= aa

>>B=[3 6 7 8; 8 7 6 4;2 7 9 3]
>>C=B

>>D=[ 3 5 6 8 23 67]
>>E=D(3)

0
0
0
0
1

D=
Columns 1 through 5
3

8 23

Column 6
67
E=
>>D(2)=69
Bautista, Keziah Lynn S.
No. 1
Familiarization with Matlab Environment,
Built-in Functions, Matrices and Plotting

6
D=
Laboratory Exercise
November 9, 2013

12

Columns 1 through 5
3 69

8 23

Column 6
>>D(2) + D(5)
>>D(3)^3 + D(4)^4
>>M=[3 11 6 5;4 7 10 2;13 9 0 8]

67
92
4312
M=

>>M(2,3)=18

3 11 6
4 7 10
13 9 0
M=

>>M(3,2)-M(4,1)

3 11 6 5
4 7 18 2
13 9 0 8
Index exceeds matrix dimensions.

8.
>> v=[23 56 34 45 67 54 23 12 21]
>>w=v(2:6)

5
2
8

v=
Columns 1 through 5
23 56 34 45 67
Columns 6 through 9
54 23 12 21
w=

>>Q=[1 3 4 5 6 8 ;4 6 7 8 2 1;1 1 4 6 8 9;
23 56 7 8 34 2; 21 45 67 83 2 3]

56 34 45 67 54
Q=
Columns 1 through 5
1
4
1
23
21

Bautista, Keziah Lynn S.


No. 1
Familiarization with Matlab Environment,
Built-in Functions, Matrices and Plotting

3
6
1
56
45

4
7
4

5
8
6

6
2
8
7 8 34
67 83 2
Laboratory Exercise

November 9, 2013

13

Column 6

>>R=Q(:,3)

8
1
9
2
3
R=

>>S=Q(2,:)

4
7
4
7
67
S=
Columns 1 through 5
4

Column 6
>>T=Q(2:4,:)

1
T=
Columns 1 through 5
4 6 7 8 2
1 1 4 6 8
23 56 7 8 34
Column 6

>>U=Q(1:3,2:4)

1
9
2
U=

>>V=4:3:34

3
6
1
V=

4
7
4

5
8
6

Columns 1 through 5
Bautista, Keziah Lynn S.
No. 1
Familiarization with Matlab Environment,
Built-in Functions, Matrices and Plotting

Laboratory Exercise
November 9, 2013

14

7 10 13 16

Columns 6 through 10
19 22 25 28 31
Column 11
>>A=[10:-1:4;ones(1,7);2:2:14;zeros(1,7)]

34
A=
Columns 1 through 5
10 9 8 7 6
1 1 1 1 1
2 4 6 8 10
0 0 0 0 0
Columns 6 through 7
5
1
12
0
B=

>>B=A([1,3],[1,3,5:7])

4
1
14
0

10 8 6 5 4
2 6 10 12 14
9.
Function
length(A)

Description
Designate the number
column

of

size(A)

Number of row and number of


column.

reshape(A,m,n)

B = reshape(A,m,n) returns the


m-by-n matrix B whose
elements are taken columnwise

Bautista, Keziah Lynn S.


No. 1
Familiarization with Matlab Environment,
Built-in Functions, Matrices and Plotting

Example
10 9 8 7 6 5 4
1 1 1 1 1 1 1
2 4 6 8 10 12 14
0 0 0 0 0 0 0
Ans
=7
10 9 8 7 6 5 4
1 1 1 1 1 1 1
2 4 6 8 10 12 14
0 0 0 0 0 0 0
Ans
=4x7
Reshape a 3-by-4 matrix into a
2-by-6 matrix:

Laboratory Exercise
November 9, 2013

15

from A. An error results if A does A =


not have m*n elements.
1 4 7 10
2 5 8 11
3 6 9 12
B = reshape(A,2,6)

diag(v)

Diag(A)

B=
1 3 5 7 9 11
2 4 6 8 10 12
Diagonal
matrices
and 23 0 0 0 0 0 0 0
diagonals of a matrix.
0
0 56 0 0 0 0 0 0
0
0 0 34 0 0 0 0 0
0
0 0 0 45 0 0 0 0
0
0 0 0 0 67 0 0 0 0
0 0 0 0 0 54 0 0
0
0 0 0 0 0 0 23 0
0
0 0 0 0 0 0 0 12
0
0 0 0 0 0 0 0 0
21
Diagonal of matrices and 10 9 8 7 6 5 4
diagonal of matrix.
1 1 1 1 1 1 1
2 4 6 8 10 12 14
0 0 0 0 0 0 0
Ans
= 10
1
6
0
where: A is a matrix and v is a vector

10.
>> b = Matlab Programming
>>c= My name is Richard Schooling
>>c(5)
>>c(12:18)

Bautista, Keziah Lynn S.


No. 1
Familiarization with Matlab Environment,
Built-in Functions, Matrices and Plotting

No result
No result
47.5202
Columns 1 through 5
44.0556 43.5606 43.0657 42.5707 42.0758
Columns 6 through 7
Laboratory Exercise
November 9, 2013

16

>>Info=char(Student
Schooling,Grade:,A+)
11.
>>VecA=[ 8 6 7];VecB=[2 3 6];
>>VecC= VecA + VecB

41.5808 41.0859
Name:,Richard No result

>>A=[3 -5 7;7 8 3];B=[2 4 5; 1 2 2];


>>C= A - B
>>D= A + B

>>A=[2 3 4; 5 4 7; 3 6 9; 5 3 1];
>>B=[3 4 ; 3 2 ; 7 8];
>>C=A*B

>>D=B*A
>>F=[6 7; 4 3]; G=[1 2; 4 5];
>>H=F*G
>>I=G*F

VecC =
10
C=

9 13

1 -9
6 6
D=

2
1

5 -1 12
8 10 5
C=
43 46
76 84
90 96
31 34
Inner matrix dimensions must agree.
H=
34 47
16 23
I=
14 13
44 43

>>AV=[ 2 5 7];BV=[3;4;1];
>>AV*BV
>>BV*AV

>>A=[2 6 7 9; 3 2 1 4; 4 6 3 1]; b=2;


>>b*A

>>A*b

Bautista, Keziah Lynn S.


No. 1
Familiarization with Matlab Environment,
Built-in Functions, Matrices and Plotting

33
ans =
6 15 21
8 20 28
2 5 7
ans =
4 12 14 18
6 4 2 8
8 12 6 2
ans =

Laboratory Exercise
November 9, 2013

17

>>D=5*A

>>A=[3 -2 5; 3 2 6;7 4 2];


>>B=inv(A)

4 12 14 18
6 4 2 8
8 12 6 2
D=
10 30 35 45
15 10 5 20
20 30 15 5
B=

>>A*B

0.1408 -0.1690 0.1549


-0.2535 0.2042 0.0211
0.0141 0.1831 -0.0845
ans =

>>A*A^-1

1.0000
0 0.0000
-0.0000 1.0000
0
-0.0000 0.0000 1.0000
ans =
1.0000
0 0.0000
-0.0000 1.0000
0
-0.0000 0.0000 1.0000

12.
>>A = [4 -2 6;2 8 2;6 10 3];
>>B= [8;4;0];
>>X = A\B

X=

>>Xb=inv(A)*B

-1.8049
0.2927
2.6341
Xb =

>>C=[4 2 6;-2 8 10;6 2 3]

-1.8049
0.2927
2.6341
C=
2 6
8 10
2 3

>>D=[8 4 0]

4
-2
6
D=

>>Xc=D/C

8
Xc =

-1.8049 0.2927 2.6341


Bautista, Keziah Lynn S.
No. 1
Familiarization with Matlab Environment,
Built-in Functions, Matrices and Plotting

Laboratory Exercise
November 9, 2013

18

13.
>>A=[3 6 8; 3 5 6]

A=
6
5

8
6

>>B=[2 4 3; 6 3 4]

3
3
B=

4
3

3
4

>>C=A.*B

2
6
C=

>>D=A./B

6 24 24
18 15 24
D=

>>E=B.^B

1.5000 1.5000 2.6667


0.5000 1.6667 1.5000
E=
Columns 1 through 2
4
46656

256
27

Column 3

>>F=A*B
>>x=[1:8]

27
256
Inner matrix dimensions must agree.
x=
Columns 1 through 5
1

Columns 6 through 8
6
>>y=x.^2 + 5*x

y=
Columns 1 through 5
6 14 24 36 50
Columns 6 through 8

Bautista, Keziah Lynn S.


No. 1
Familiarization with Matlab Environment,
Built-in Functions, Matrices and Plotting

Laboratory Exercise
November 9, 2013

19

>>x=[1:2:15]

66 84 104
x=
Columns 1 through 5
1

Columns 6 through 8
>>y=(x.^3 + 5*x)./(4*x.^2 10)

11 13 15
y=
Columns 1 through 3
-1.0000 1.6154 1.6667
Columns 4 through 6
2.0323 2.4650 2.9241
Columns 7 through 8

>>

3.3964 3.8764
x=
Columns 1 through 3
0 0.5236 1.0472
Columns 4 through 6
1.5708 2.0944 2.6180
Column 7

>>y=cos(x)

3.1416
y=
Columns 1 through 3
1.0000 0.8660 0.5000
Columns 4 through 6

Bautista, Keziah Lynn S.


No. 1
Familiarization with Matlab Environment,
Built-in Functions, Matrices and Plotting

Laboratory Exercise
November 9, 2013

20

0.0000 -0.5000 -0.8660


Column 7
-1.0000
14.
Function
mean(A)

Description
Example
It returns the mean values of A = [1 2 3; 3 3 6; 4 6 8; 4 7 7];
the elements along different
dimensions of an array.
mean(A)
ans =
3.0000 4.500 6.0000
mean(A,2)
ans =
2.0000
4.0000
6.0000
6.0000

C=max(A)

It returns the largest elements Return the maximum of a 2-by-3


along different dimensions of an matrix from each column:
array.
X = [2 8 4; 7 3 9];
max(X,[],1)
ans =
7 8 9
Return the maximum from each
row:
max(X,[],2)
ans =
8
9
Compare each element of X to a
scalar:
max(X,5)

Bautista, Keziah Lynn S.


No. 1
Familiarization with Matlab Environment,
Built-in Functions, Matrices and Plotting

Laboratory Exercise
November 9, 2013

21

ans =
5
7
(d,n)=max(A)
min(A)

8
5

5
9

It returns the smallest elements Return the minimum of a 2-by-3


along different dimensions of an matrix from each column:
array.
X = [2 8 4; 7 3 9];
min(X,[],1)
ans =
2 3 4
Return the minimum from each
row:
min(X,[],2)
ans =
2
3
Compare each element of X to a
scalar:
min(X,5)
ans =
2
5

(d,n)=min(A)
sum(A)

sort(A)

5
3

4
5

It returns the sum of the Create a 3-by-3 matrix.


elements of A along the first A = [1 3 2; 4 2 5; 6 1 4]
array dimension whose size A =
does not equal 1
1 3 2
4 2 5
6 1 4
Compute the sum of
elements in each row.
S = sum(A,2)
S=
6
11
11
It sorts the elements along Sort horizontal vector A:
different dimensions of an array, A = [78 23 10 100 45 5 6];
and arranges those elements in

Bautista, Keziah Lynn S.


No. 1
Familiarization with Matlab Environment,
Built-in Functions, Matrices and Plotting

Laboratory Exercise
November 9, 2013

22

the

ascending order.
median(A)

It returns the median value of A.

sort(A)
ans =
5 6 10 23 45 78 100
Define a 4-by-3 matrix.
A = [0 1 1; 2 3 2; 1 3 2; 4 2 2]
A=
0 1 1
2 3 2
1 3 2
4 2 2
Find the median value of each
column.
M = median(A)
M=
1.5000 2.5000 2.0000
For each column, the median
value is the mean of the middle
two numbers in sorted order.
For matrix X
X=
1 5 9
7 15 22
s = std(X,0,1)
s=
4.2426 7.0711 9.1924
s = std(X,0,2)
s=
4.000
7.5056

std(A)

It is a function of X, where X is a
vector, returns the standard
deviation using (1) above. The
result s is the square root of an
unbiased estimator of the
variance of the population from
which X is drawn, as long as X
consists
of
independent,
identically distributed samples.

det(A)

It returns the determinant of the The statement A = [1 2 3; 4 5 6; 7


square matrix X.
8 9]
Produces
A=
1

This happens to be a singular


Bautista, Keziah Lynn S.
No. 1
Familiarization with Matlab Environment,
Built-in Functions, Matrices and Plotting

Laboratory Exercise
November 9, 2013

23

matrix, so det(A) produces a very


small number.
Changing A(3,3) with A(3,3) =
0 turns A into a nonsingular
matrix. Now d =
det(A) produces d = 27 The
statement A = [1 2 3; 4 5 6; 7 8
9]produces
A=
1

This happens to be a singular


matrix, so det(A) produces a very
small number. Changing A(3,3)
with A(3,3) = 0 turns A into a
nonsingular matrix. Now d =
det(A) produces d = 27.
dot(a,b)

cross(a,b)

It returns the scalar product of


the vectors A and B. A and B
must be vectors of the same
length. When A and B are both
column vectors, dot(A,B) is the
same as A'*B.
It returns the cross product of
the vectors A and B. That is, C =
A x B. A and B must be 3element vectors. If A and B are
multidimensional arrays, cross
returns the cross product of A
and B along the first dimension
of length 3.

Bautista, Keziah Lynn S.


No. 1
Familiarization with Matlab Environment,
Built-in Functions, Matrices and Plotting

The dot product of two vectors is


calculated as shown:
a = [1 2 3]; b = [4 5 6];
c = dot(a,b)
c = 32
The cross and dot products of
two vectors are calculated as
shown:
a = [1 2 3];
b = [4 5 6];
c = cross(a,b)
c=
-3 6 -3
Laboratory Exercise

November 9, 2013

24

inv(A)

d = dot(a,b)
d=
32
It returns the inverse of the Here
is
an
example
square matrix X. A warning demonstrating the difference
message is printed if X is badly between solving a linear system
scaled or nearly singular.
by inverting the matrix with
inv(A)*b and solving it directly
with A\b. A random matrix A of
order 500 is constructed so that
its condition number, cond(A), is
1.e10, and its norm, norm(A), is1.
The exact solution x is a random
vector of length 500 and the
right-hand side is b = A*x. Thus
the system of linear equations is
badly conditioned, but consistent.
On a 300 MHz, laptop computer
the statements
n = 500;
Q = orth(randn(n,n));
d = logspace(0,-10,n);
A = Q*diag(d)*Q';
x = randn(n,1);
b = A*x;
tic, y = inv(A)*b; toc
err = norm(y-x)
res = norm(A*y-b)
produce
elapsed_time =
1.4320
err =
7.3260e-006
res =
4.7511e-007
while the statements
tic, z = A\b, toc
err = norm(z-x)
res = norm(A*z-b)
produce
elapsed_time =
0.6410
err =
7.1209e-006
res =

Bautista, Keziah Lynn S.


No. 1
Familiarization with Matlab Environment,
Built-in Functions, Matrices and Plotting

Laboratory Exercise
November 9, 2013

25

4.4509e-015
It takes almost two and one half
times as long to compute the
solution with y = inv(A)*b as with
z = A\b. Both produce computed
solutions with about the same
error, 1.e-6, reflecting the
condition number of the matrix.
But the size of the residuals,
obtained by plugging the
computed solution back into the
original equations, differs by
several orders of magnitude. The
direct solution produces residuals
on the order of the machine
accuracy, even though the
system is badly conditioned.
The behavior of this example is
typical. Using A\b instead of
inv(A)*b is two to three times as
fast and produces residuals on
the order of machine accuracy,
relative to the magnitude of the
data.

7. Conclusion:
I therefore conclude that Matlab can be used as an engineering devise in solving common mathematical
problems such as mathematical computations, modelings, graphs, etc.
8. Further Readings:
Ferraris, G. and Manenti, F. (2010). Interpolation and regression models for the chemical engineer:
solving numerical problems. Germany: Wiley-VCH Verlag
Filo, O. (2010). Information processing by biochemical systems: neural network type
configurations.
New Jersey: Wiley.
Gopal, S. (2009). Bioinformatics: a computing perspective. India: McGraw-Hill Science/Engineering
Math.
Jaluria, Y. (2012). Computer methods for engineering with MATLAB applications (2nd ed.). Boca,
Raton,Florida: CRC Press.
Knopf, F. C. (2012). Modeling, analysis and optimization of process and energy systems.Hoboken,
New Jersey: John Wiley and Sons.
Velten, K. (2009). Mathematical modeling and simulation: introduction for scientists and engineers.
Singapore: Wiley-VCH.
Bautista, Keziah Lynn S.
No. 1
Familiarization with Matlab Environment,
Built-in Functions, Matrices and Plotting

Laboratory Exercise
November 9, 2013

26

9. Assessment (Rubric for Laboratory Performance):


TECHNOLOGICAL INSTITUTE OF THE PHILIPPINES
RUBRIC FOR MODERN TOOL USAGE
(Engineering Programs)
Student Outcome (e): Use the techniques, skills, and modern engineering tools necessary for
engineering practice in complex engineering activities.
Program: Chemical Engineering Course: CHE 530D1 Section: _______ ____Sem SY ________
Performance Unsatisfactory Developing
Satisfactory
Very Satisfactory
Score
Indicators
1
2
3
4
1. Apply
Fails to identify Identifies
Identifies
Recognizes the
appropriate any modern
modern
modern
benefits and
techniques, techniques to
techniques
techniques and constraints of modern
skills, and
perform
but fails to
is able to apply engineering tools and
modern
disciplineapply these
these in
shows intention to
tools to
specific
in performing performing
apply them for
perform a
engineering
disciplinedisciplineengineering practice.
disciplinetask.
specific
specific
specific
engineering
engineering
engineering
task.
task.
task.
2. Demonstrat Fails to apply
Attempts to
Shows ability to Shows ability to apply
e skills in
any modern
apply
apply
the most appropriate
applying
tools to solve
modern tools fundamental
and effective modern
different
engineering
but has
procedures in
tools to solve
techniques
problems.
difficulties to using modern
engineering problems.
and modern
solve
tools when
tools to
engineering
solving
solve
problems.
engineering
Bautista, Keziah Lynn S.
No. 1
Familiarization with Matlab Environment,
Built-in Functions, Matrices and Plotting

Laboratory Exercise
November 9, 2013

27

engineering
problems.
3. Recognize
the benefits
and
constraints
of modern
engineering
tools.

Evaluated by:

problems.
Does not
recognize the
benefits and
constraints of
modern
engineering
tools.

Recognizes
some
benefits and
constraints of
modern
engineering
tools.

Recognizes the
benefits and
constraints of
modern
engineering
tools and
shows intention
to apply them
for engineering
practice.

Recognizes the need


for benefits and
constraints of modern
engineering tools and
makes good use of
them for engineering
practice.

Total Score
Mean Score = (Total Score / 3)
Percentage Rating = (Total Score / 12) x 100%
______________________________________
_______________
Printed Name and Signature of Faculty Member
Date

Bautista, Keziah Lynn S.


No. 1
Familiarization with Matlab Environment,
Built-in Functions, Matrices and Plotting

Laboratory Exercise
November 9, 2013

28

Вам также может понравиться