Upload
keziah-lynn-bautista
View
25
Download
1
Tags:
Embed Size (px)
DESCRIPTION
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 \).
Citation preview
TECHNOLOGICAL INSTITUTE OF THE PHILIPPINES363 P. Casal St., Quiapo, Manila
CHEP 530D1
COMPUTER APPLICATIONS IN
CHEMICAL ENGINEERING
Crispulo G. MarananInstructor
Laboratory Exercise No. 1Familiarization with Matlab Environment, Built-in Functions, Matrices and Plotting
Bautista, Keziah Lynn S. Laboratory Exercise No. 1Familiarization with Matlab Environment, November 9, 2013Built-in Functions, Matrices and Plotting
1
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 terms7.Evaluate the results after pressing the enter key for the creation of two-dimensional array (matrix).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 :
Bautista, Keziah Lynn S. Laboratory Exercise No. 1Familiarization with Matlab Environment, November 9, 2013Built-in Functions, Matrices and Plotting
2
4x – 2y + 6z = 82x + 8y + 2z = 46x + 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: Laboratory Exercise No.:1Group No.: Section:CH51FA1Group Members: Date Performed: November 9, 2013
Date Submitted: November 11, 2013Instructor:Engr. Crispulo Maranan
6. Data and Results:1.
Window Purpose1.Command Window Inputs the commands to be use. It is used to
execute commands or aliases directly in the
Bautista, Keziah Lynn S. Laboratory Exercise No. 1Familiarization with Matlab Environment, November 9, 2013Built-in Functions, Matrices and Plotting
3
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.
2.Figure 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.
3.Editor Window 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.
4.Help Window Helps you about the commands and other terms to be used.
5.Launch Pad Window Access help, tools, demos and documentation6.Command History Compiles the history of the commands7.Workspace Window It consist of common mathematical figures,
graphs, etc.8.Current Directory 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 dierent directory.
2.Symbol Purpose>> Relational operators perform element-by-
element 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
Bautista, Keziah Lynn S. Laboratory Exercise No. 1Familiarization with Matlab Environment, November 9, 2013Built-in Functions, Matrices and Plotting
4
proportion multiplied by 100clc 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 Result>> 8 + 5/9 8.5556>> (8 + 5)/9 1.4444>> 8^5/9 3.6409e+03>>29^1/5 + 35^0.7 17.8461
4.Built-in Function Result>>sqrt(144) 12>>exp(7) 1.0966e+03>>abs(-99) 99>>log(100000) 11.5129>>log10(100000) 5>>factorial(10) 3658800>>sin(pi/4) 0.7071>>round(19/6) 3>>rem(16,5) 1>>sign(-19) -1
5.>>x= 10 10>>x=4*x -15 25>>a = 10 10>>B= 9 9>>C= (a –B) +50 – a/B *16 33.2222>>a=10,B=9; C= (a –B) +50 – a/B *16 33.2222>>x = 0.99; 0.9900>>E = sin(x)^3 + cos(x)^4 0.6750
6.>>yr = [ 2001 2002 2003 2004 2005] yr =
Columns 1 through 2
2001 2002
Columns 3 through 4
2003 2004
Column 5
Bautista, Keziah Lynn S. Laboratory Exercise No. 1Familiarization with Matlab Environment, November 9, 2013Built-in Functions, Matrices and Plotting
5
2005>>yr = [ 256; 299; 350; 402; 503] yr =
256 299 350 402 503
>>y = [1:2:15] y =
Columns 1 through 5
1 3 5 7 9
Columns 6 through 8
11 13 15>>y = [1.5:0.1;2.0] 2>>y=[-5:15] y =
Columns 1 through 5
-5 -4 -3 -2 -1
Columns 6 through 10
0 1 2 3 4
Columns 11 through 15
5 6 7 8 9
Columns 16 through 20
10 11 12 13 14
Column 21
15>>b = [21:-3:6] b =
Columns 1 through 5
21 18 15 12 9
Column 6
Bautista, Keziah Lynn S. Laboratory Exercise No. 1Familiarization with Matlab Environment, November 9, 2013Built-in Functions, Matrices and Plotting
6
6>>a = linspace(0,8,6) a =
Columns 1 through 3
0 1.6000 3.2000
Columns 4 through 6
4.8000 6.4000 8.0000>>b=linspace(30,10,11) b =
Columns 1 through 5
30 28 26 24 22
Columns 6 through 10
20 18 16 14 12
Column 11
10>>c=linspace(49.5,0.5) c =
Columns 1 through 3
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
Bautista, Keziah Lynn S. Laboratory Exercise No. 1Familiarization with Matlab Environment, November 9, 2013Built-in Functions, Matrices and Plotting
7
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
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
Bautista, Keziah Lynn S. Laboratory Exercise No. 1Familiarization with Matlab Environment, November 9, 2013Built-in Functions, Matrices and Plotting
8
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
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
Bautista, Keziah Lynn S. Laboratory Exercise No. 1Familiarization with Matlab Environment, November 9, 2013Built-in Functions, Matrices and Plotting
9
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
7.>>a = [2 35 6;5 67 88;22 56 89] a =
2 35 6 5 67 88 22 56 89
>>b = [23 56 78 73 6835 98 54 32 1599 34 23 12 2]
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]
Ram = 6.0000 72.0000 0.5000 64.0000 2.6667 15.0000
>>Z= [1:2:11;0.0:5:25;linspace(10,60,6)] Z =
Columns 1 through 5
1 3 5 7 9 0 5 10 15 20 10 20 30 40 50
Column 6
Bautista, Keziah Lynn S. Laboratory Exercise No. 1Familiarization with Matlab Environment, November 9, 2013Built-in Functions, Matrices and Plotting
10
11 25 60
>>zr=zeros(4,6) 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 0 0 0
>>on=ones(3,4) on =
1 1 1 1 1 1 1 1 1 1 1 1
>>we=eye(5) we =
1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1
>>aa=[4 8 9]>>bb= aa’
aa =
4 8 9bb =
4 8 9>>B=[3 6 7 8; 8 7 6 4;2 7 9 3]>>C=B’
B =
3 6 7 8 8 7 6 4 2 7 9 3C =
3 6 7 8 8 7 6 4 2 7 9 3
>>D=[ 3 5 6 8 23 67] D =
Bautista, Keziah Lynn S. Laboratory Exercise No. 1Familiarization with Matlab Environment, November 9, 2013Built-in Functions, Matrices and Plotting
11
>>E=D(3) Columns 1 through 5
3 5 6 8 23
Column 6
67E =
6>>D(2)=69 D =
Columns 1 through 5
3 69 6 8 23
Column 6
67>>D(2) + D(5) 92>>D(3)^3 + D(4)^4 4312>>M=[3 11 6 5;4 7 10 2;13 9 0 8] M =
3 11 6 5 4 7 10 2 13 9 0 8
>>M(2,3)=18 M =
3 11 6 5 4 7 18 2 13 9 0 8
>>M(3,2)-M(4,1) Index exceeds matrix dimensions.
8.>> v=[23 56 34 45 67 54 23 12 21]>>w=v(2:6)
v =
Columns 1 through 5
23 56 34 45 67
Columns 6 through 9
54 23 12 21w =
56 34 45 67 54>>Q=[1 3 4 5 6 8 ;4 6 7 8 2 1;1 1 4 6 8 9; Q =
Bautista, Keziah Lynn S. Laboratory Exercise No. 1Familiarization with Matlab Environment, November 9, 2013Built-in Functions, Matrices and Plotting
12
23 56 7 8 34 2; 21 45 67 83 2 3] Columns 1 through 5
1 3 4 5 6 4 6 7 8 2 1 1 4 6 8 23 56 7 8 34 21 45 67 83 2
Column 6
8 1 9 2 3
>>R=Q(:,3) R =
4 7 4 7 67
>>S=Q(2,:) S =
Columns 1 through 5
4 6 7 8 2
Column 6
1>>T=Q(2:4,:) T =
Columns 1 through 5
4 6 7 8 2 1 1 4 6 8 23 56 7 8 34
Column 6
1 9 2
>>U=Q(1:3,2:4) U =
3 4 5
Bautista, Keziah Lynn S. Laboratory Exercise No. 1Familiarization with Matlab Environment, November 9, 2013Built-in Functions, Matrices and Plotting
13
6 7 8 1 4 6
>>V=4:3:34 V =
Columns 1 through 5
4 7 10 13 16
Columns 6 through 10
19 22 25 28 31
Column 11
34>>A=[10:-1:4;ones(1,7);2:2:14;zeros(1,7)] 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 4 1 1 12 14 0 0
>>B=A([1,3],[1,3,5:7]) B =
10 8 6 5 4 2 6 10 12 14
9.Function Description Example
length(A) Designate the number of column
10 9 8 7 6 5 41 1 1 1 1 1 12 4 6 8 10 12 140 0 0 0 0 0 0Ans =7
size(A) Number of row and number of column.
10 9 8 7 6 5 41 1 1 1 1 1 12 4 6 8 10 12 140 0 0 0 0 0 0Ans = 4 x 7
Bautista, Keziah Lynn S. Laboratory Exercise No. 1Familiarization with Matlab Environment, November 9, 2013Built-in Functions, Matrices and Plotting
14
reshape(A,m,n) B = reshape(A,m,n) returns the m-by-n matrix B whose elements are taken columnwise from A. An error results if A does not have m*n elements.
Reshape a 3-by-4 matrix into a 2-by-6 matrix:
A = 1 4 7 10 2 5 8 11 3 6 9 12 B = reshape(A,2,6) B = 1 3 5 7 9 11 2 4 6 8 10 12
diag(v) Diagonal matrices and diagonals of a matrix.
23 0 0 0 0 0 0 0 00 56 0 0 0 0 0 0 00 0 34 0 0 0 0 0 00 0 0 45 0 0 0 0 00 0 0 0 67 0 0 0 00 0 0 0 0 54 0 0 00 0 0 0 0 0 23 0 00 0 0 0 0 0 0 12 00 0 0 0 0 0 0 0 21
Diag(A) Diagonal of matrices and diagonal of matrix.
10 9 8 7 6 5 41 1 1 1 1 1 12 4 6 8 10 12 140 0 0 0 0 0 0Ans = 10 1 6 0
where: A is a matrix and v is a vector
10.>> b = ‘Matlab Programming’ No result>>c= ‘ My name is Richard Schooling’ No result>>c(5) 47.5202>>c(12:18) Columns 1 through 5
44.0556 43.5606 43.0657 42.5707 42.0758
Bautista, Keziah Lynn S. Laboratory Exercise No. 1Familiarization with Matlab Environment, November 9, 2013Built-in Functions, Matrices and Plotting
15
Columns 6 through 741.5808 41.0859
>>Info=char(‘Student Name:’,’Richard Schooling’,’Grade:’,’A+’)
No result
11.>>VecA=[ 8 6 7];VecB=[2 3 6];>>VecC= VecA + VecB
VecC =
10 9 13>>A=[3 -5 7;7 8 3];B=[2 4 5; 1 2 2];>>C= A - B
C =
1 -9 2 6 6 1
>>D= A + B D =
5 -1 12 8 10 5
>>A=[2 3 4; 5 4 7; 3 6 9; 5 3 1];>>B=[3 4 ; 3 2 ; 7 8];>>C=A*B
C =
43 46 76 84 90 96 31 34
>>D=B*A Inner matrix dimensions must agree.>>F=[6 7; 4 3]; G=[1 2; 4 5];>>H=F*G
H =
34 47 16 23
>>I=G*F I =
14 13 44 43
>>AV=[ 2 5 7];BV=[3;4;1];>>AV*BV
33
>>BV*AV ans =
6 15 21 8 20 28 2 5 7
>>A=[2 6 7 9; 3 2 1 4; 4 6 3 1]; b=2;>>b*A
ans =
4 12 14 18 6 4 2 8 8 12 6 2
>>A*b ans =
4 12 14 18 6 4 2 8 8 12 6 2
Bautista, Keziah Lynn S. Laboratory Exercise No. 1Familiarization with Matlab Environment, November 9, 2013Built-in Functions, Matrices and Plotting
16
>>D=5*A D =
10 30 35 45 15 10 5 20 20 30 15 5
>>A=[3 -2 5; 3 2 6;7 4 2];>>B=inv(A)
B =
0.1408 -0.1690 0.1549 -0.2535 0.2042 0.0211 0.0141 0.1831 -0.0845
>>A*B ans =
1.0000 0 0.0000 -0.0000 1.0000 0 -0.0000 0.0000 1.0000
>>A*A^-1 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 =
-1.8049 0.2927 2.6341
>>Xb=inv(A)*B Xb =
-1.8049 0.2927 2.6341
>>C=[4 2 6;-2 8 10;6 2 3] C =
4 2 6 -2 8 10 6 2 3
>>D=[8 4 0] D =
8 4 0>>Xc=D/C Xc =
-1.8049 0.2927 2.634113.
>>A=[3 6 8; 3 5 6] A =
3 6 8 3 5 6
>>B=[2 4 3; 6 3 4] B =
Bautista, Keziah Lynn S. Laboratory Exercise No. 1Familiarization with Matlab Environment, November 9, 2013Built-in Functions, Matrices and Plotting
17
2 4 3 6 3 4
>>C=A.*B C =
6 24 24 18 15 24
>>D=A./B D =
1.5000 1.5000 2.6667 0.5000 1.6667 1.5000
>>E=B.^B E =
Columns 1 through 2
4 256 46656 27
Column 3
27 256
>>F=A*B Inner matrix dimensions must agree.>>x=[1:8] x =
Columns 1 through 5
1 2 3 4 5
Columns 6 through 8
6 7 8>>y=x.^2 + 5*x y =
Columns 1 through 5
6 14 24 36 50
Columns 6 through 8
66 84 104>>x=[1:2:15] x =
Columns 1 through 5
1 3 5 7 9
Columns 6 through 8
Bautista, Keziah Lynn S. Laboratory Exercise No. 1Familiarization with Matlab Environment, November 9, 2013Built-in Functions, Matrices and Plotting
18
11 13 15>>y=(x.^3 + 5*x)./(4*x.^2 – 10) 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
3.1416>>y=cos(x) y =
Columns 1 through 3
1.0000 0.8660 0.5000
Columns 4 through 6
0.0000 -0.5000 -0.8660
Column 7
-1.000014.
Function Description Examplemean(A) It returns the mean values of
the elements along different dimensions of an array.
A = [1 2 3; 3 3 6; 4 6 8; 4 7 7];
mean(A)
Bautista, Keziah Lynn S. Laboratory Exercise No. 1Familiarization with Matlab Environment, November 9, 2013Built-in Functions, Matrices and Plotting
19
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 along different dimensions of an array.
Return the maximum of a 2-by-3 matrix from each column:X = [2 8 4; 7 3 9];max(X,[],1)ans =
7 8 9Return the maximum from each row:max(X,[],2)ans =
8 9Compare each element of X to a scalar:max(X,5)ans =
5 8 57 5 9
(d,n)=max(A)min(A) It returns the smallest elements
along different dimensions of an array.
Return the minimum of a 2-by-3 matrix from each column:X = [2 8 4; 7 3 9];min(X,[],1)ans =
2 3 4Return the minimum from each
Bautista, Keziah Lynn S. Laboratory Exercise No. 1Familiarization with Matlab Environment, November 9, 2013Built-in Functions, Matrices and Plotting
20
row:min(X,[],2)ans =
2 3Compare each element of X to a scalar:min(X,5)ans =
2 5 4 5 3 5
(d,n)=min(A)sum(A) It returns the sum of the
elements of A along the first array dimension whose size does not equal 1
Create a 3-by-3 matrix.A = [1 3 2; 4 2 5; 6 1 4]A =
1 3 2 4 2 5 6 1 4Compute the sum of the elements in each row.S = sum(A,2)S =
6 11 11
sort(A) It sorts the elements along different dimensions of an array, and arranges those elements in ascending order.
Sort horizontal vector A:A = [78 23 10 100 45 5 6];
sort(A)ans = 5 6 10 23 45 78 100
median(A) It returns the median value of A. 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 2Find the median value of each column.M = median(A)M =1.5000 2.5000 2.0000
Bautista, Keziah Lynn S. Laboratory Exercise No. 1Familiarization with Matlab Environment, November 9, 2013Built-in Functions, Matrices and Plotting
21
For each column, the median value is the mean of the middle two numbers in sorted order.
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.
For matrix XX = 1 5 9 7 15 22s = std(X,0,1) s = 4.2426 7.0711 9.1924s = std(X,0,2)s = 4.000 7.5056
det(A) It returns the determinant of the square matrix X.
The statement A = [1 2 3; 4 5 6;
7 8 9]
Produces
A =
1 2 3
4 5 6
7 8 9
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 The
statement A = [1 2 3; 4 5 6; 7 8
9]produces
A =
1 2 3
Bautista, Keziah Lynn S. Laboratory Exercise No. 1Familiarization with Matlab Environment, November 9, 2013Built-in Functions, Matrices and Plotting
22
4 5 6
7 8 9
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) 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.
The dot product of two vectors is calculated as shown:a = [1 2 3]; b = [4 5 6];c = dot(a,b)c = 32
cross(a,b) It returns the cross product of the vectors A and B. That is, C = A x B. A and B must be 3-element vectors. If A and B are multidimensional arrays, cross returns the cross product of A and B along the first dimension of length 3.
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 -3d = dot(a,b)d = 32
inv(A) It returns the inverse of the square matrix X. A warning message is printed if X is badly scaled or nearly singular.
Here is an example demonstrating the difference between solving a linear system 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
Bautista, Keziah Lynn S. Laboratory Exercise No. 1Familiarization with Matlab Environment, November 9, 2013Built-in Functions, Matrices and Plotting
23
the statementsn = 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; tocerr = norm(y-x)res = norm(A*y-b)produceelapsed_time = 1.4320 err = 7.3260e-006 res = 4.7511e-007while the statementstic, z = A\b, tocerr = norm(z-x)res = norm(A*z-b)produceelapsed_time = 0.6410err = 7.1209e-006res = 4.4509e-015It 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
Bautista, Keziah Lynn S. Laboratory Exercise No. 1Familiarization with Matlab Environment, November 9, 2013Built-in Functions, Matrices and Plotting
24
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.
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 ________
Bautista, Keziah Lynn S. Laboratory Exercise No. 1Familiarization with Matlab Environment, November 9, 2013Built-in Functions, Matrices and Plotting
25
Performance Indicators
Unsatisfactory1
Developing2
Satisfactory3
Very Satisfactory4
Score
1. Apply appropriate techniques, skills, and modern tools to perform a discipline-specific engineering task.
Fails to identify any modern techniques to perform discipline-specific engineering task.
Identifies modern techniques but fails to apply these in performing discipline-specific engineering task.
Identifies modern techniques and is able to apply these in performing discipline-specific engineering task.
Recognizes the benefits and constraints of modern engineering tools and shows intention to apply them for engineering practice.
2. Demonstrate skills in applying different techniques and modern tools to solve engineering problems.
Fails to apply any modern tools to solve engineering problems.
Attempts to apply modern tools but has difficulties to solve engineering problems.
Shows ability to apply fundamental procedures in using modern tools when solving engineering problems.
Shows ability to apply the most appropriate and effective modern tools to solve engineering problems.
3. Recognize the benefits and constraints of modern engineering tools.
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 ScoreMean Score = (Total Score / 3)
Percentage Rating = (Total Score / 12) x 100%Evaluated by: ______________________________________ _______________ Printed Name and Signature of Faculty Member Date
Bautista, Keziah Lynn S. Laboratory Exercise No. 1Familiarization with Matlab Environment, November 9, 2013Built-in Functions, Matrices and Plotting
26