Cuesta - Activity 1
Short Description
MATLAB and LabVIEW Laboratory Activity...
Description
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, onedimensional 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). 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: CHE 508 Group No.: Group Members: Cuesta, Alwyn Wren C.
Laboratory Exercise No.: 1 Section: CH51FC1 Date Performed: June 14, 2017 Date Submitted: June 14, 2017 Instructor: Engr. Crispulo Maranan
6. Data and Results: 1. Window
Purpose
1.Command Window
The window where you type the commands to run a function, or to set a variable equal to some value
2.Figure Window
The window where the graph generated by the command input appears
3.Editor Window
The window where you can write a program or script called a m-file that can be used later
4.Help Window
The window where you can search for guides and instructions about different processes and commands
5.Launch Pad Window
To access all MATLAB services and toolboxes
6.Command History
To display all commands issued in MATLAB since the last session
7.Workspace Window
To view variable definitions and variable memory allocations
8.Current Directory
It provides quick access to all files available such as the M-files created
2. Symbol
Purpose
>>
To designate the start of a command
;
To separate columns and suppresses display
%
To designate a line as a comment and it will not affect the program
clc
To clear your workspace and command window
3. Mathematical Expression
Result
>> 8 + 5/9
ans = 8.5556
>> (8 + 5)/9
ans = 1.4444
>> 8^5/9
ans = 3.6409e+03
>>29^1/5 + 35^0.7
ans = 17.8461
4. Built-in Function
Result
>>sqrt(144)
ans =
12 >>exp(7)
ans = 1.0966e+03
>>abs(-99)
ans = 99
>>log(100000)
ans = 11.5129
>>log10(100000)
ans = 5
>>factorial(10)
ans = 3628800
>>sin(pi/4)
ans = 0.7071
>>round(19/6)
ans = 3
>>rem(16,5)
ans = 1
>>sign(-19)
ans = -1
5. >>x= 10
x = 10
>>x=4*x -15
x = 25
>>a = 10
a = 10
>>B= 9
B =
9 C =
>>C= (a –B) +50 – a/B *16
33.2222 a =
>>a=10,B=9; C= (a –B) +50 – a/B *16
10 C = 33.2222 x =
>>x = 0.99;
0.9900 E =
>>E = sin(x)^3 + cos(x)^4
0.6750 6. >>yr = [ 2001 2002 2003 2004 2005]
yr = 2001
>>yr = [ 256; 299; 350; 402; 503]
2002
2003
5
9
2004
2005
yr = 256 299 350 402 503
>>y = [1:2:15]
y = 1
>>y = [1.5:0.1;2.0]
3
7
11
13
15
y = 2
>>y=[-5:15]
y = Columns 1 through 12 -5
-4
-3
-2
-1
0
1
2
3
4
5
6
Columns 13 through 21 7 8
9
10
11
12
13
14
15 >>b = [21:-3:6]
y = 21
>>a = linspace(0,8,6)
18
15
6
3.2000
4.8000
y = 16
>>c=linspace(49.5,0.5)
9
y = 0 1.6000 6.4000 8.000
>>b=linspace(30,10,11)
12
30 28 26 14 12 10
24
22
20
18
c = Columns 1 through 7 49.5000 48.0152 46.5303
49.0051 47.5202
48.5101 47.0253
Columns 8 through 14 46.0354 44.5505 43.0657
45.5404 44.0556
45.0455 43.5606
Columns 15 through 21 42.5707 41.0859 39.6010
42.0758 40.5909
41.5808 40.0960
Columns 22 through 28 39.1061 37.6212
38.6111 37.1263
38.1162 36.6313
36.1364
Columns 29 through 35 35.6414 34.1566 32.6717
35.1465 33.6616
34.6515 33.1667
Columns 36 through 42 32.1768 30.6919 29.2071
31.6818 30.1970
31.1869 29.7020
Columns 43 through 49 28.7121 27.2273 25.7424
28.2172 26.7323
27.7222 26.2374
Columns 50 through 56 25.2475 23.7626 22.2778
24.7525 23.2677
24.2576 22.7727
Columns 57 through 63 21.7828 20.2980 18.8131
21.2879 19.8030
20.7929 19.3081
Columns 64 through 70 18.3182 16.8333 15.3485
17.8232 16.3384
17.3283 15.8434
Columns 71 through 77 14.8535 13.3687 11.8838
14.3586 12.8737
13.8636 12.3788
Columns 78 through 84 11.3889 9.9040 8.4192
10.8939 9.4091
10.3990 8.9141
Columns 85 through 91 7.9242 6.4394 4.9545
7.4293 5.9444
6.9343 5.4495
Columns 92 through 98 4.4596 2.9747 1.4899
3.9646 2.4798
3.4697 1.9848
Columns 99 through 100 0.9949
0.5000
7. >>a = [2 35 6;5 67 88;22 56 89]
>>b = [23 56 78 73 68 35 98 54 32 15
a = 2
35
6
5
67
88
22
56
89
23
56
78
b = 73
68
99 34 23 12 2]
>>cd = 9 ;e 6;h=8;
35
98
54
32
15
99
34
23
12
2
Ram =
>>Ram=[e, cd*h,cos(pi/3);h^2,sqrt(h*h/cd),15] 6.0000 64.0000 >>Z= [1:2:11;0.0:5:25;linspace(10,60,6)]
>>zr=zeros(4,6)
>>on=ones(3,4)
>>we=eye(5)
>>aa=[4 8 9]
72.0000
0.5000
2.6667
15.0000
Z =
1
3
5
7
9
11
0
5
10
15
20
25
10
20
30
40
50
60
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
1
1
1
1
1
1
1
1
1
1
1
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
zr =
on =
we =
bb =
>>bb= aa’ 4 8 9 >>B=[3 6 7 8; 8 7 6 4;2 7 9 3]
C =
>>C=B’
>>D=[ 3 5 6 8 23 67]
8
2
6
7
7
7
6
9
8
4
3
69
6
8
E = 6
>>E=D(3) >>D(2)=69
3
D = 3
>>D(2) + D(5)
ans = 92
>>D(3)^3 + D(4)^4
ans = 4312
>>M=[3 11 6 5;4 7 10 2;13 9 0 8]
>>M(2,3)=18
>>M(3,2)-M(3,1)
M = 3
11
6
5
4
7
10
2
13
9
0
8
3
11
6
5
4
7
18
2
13
9
0
8
M =
ans = -4
23
67
8. >> v=[23 56 34 45 67 54 23 12 21] >>w=v(2:6) >>Q=[1 3 4 5 6 8 ;4 6 7 8 2 1;1 1 4 6 8 9;
w = 56
34
45
67
54
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
4
6
7
8
2
1
4
6
7
8
2
1
1
1
4
6
8
9
23
56
7
8
34
2
3
4
5
6
7
8
1
4
6
Q =
23 56 7 8 34 2; 21 45 67 83 2 3]
>>R=Q(:,3)
R = 4 7 4 7 67
>>S=Q(2,:)
>>T=Q(2:4,:)
>>U=Q(1:3,2:4)
>>V=4:3:34
S =
T =
U =
V =
4 28
25 >>A=[10:-1:4;ones(1,7);2:2:14;zeros(1,7)]
>>B=A([1,3],[1,3,5:7])
7 10 31 34
13
16
19
A = 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
10
8
6
5
4
2
6
10
12
14
B =
9. Function length(A)
Description Number of columns of matrix A
Example A = 1
-2
4
-5
2
0
1
0
3
>> length(A) ans = 3 size(A)
Dimensions of matrix A
A = 1
-2
4
-5
2
0
1
0
3
>> size(A) ans = 3 reshape(A,m,n)
Change the rows of matrix A by m A =
3
22
and columns of matrix A by n
1
2
3
4
5
6
>> reshape(A,3,2) ans =
diag(v)
Create a matrix with the elements of v = v on the main diagonal
1
5
4
3
2
6
23
56
34
>> diag(v) ans =
Diag(A)
Create a matrix with the elements of A= A on the main diagonal
23
0
0
0
56
0
0
0
34
23
56
34
>> diag(A) ans = 23
0
0
0
56
0
0
0
34
where: A is a matrix and v is a vector 10. >> b = ‘Matlab Programming’
b = Matlab Programming
>>c= ‘ My name is Richard Schooling’
c =
My name is Richard Schooling ans =
>>c(5)
a ans =
>>c(12:18)
Richard >>Info=char(‘Student Schooling’,’Grade:’,’A+’)
Name:’,’Richard
Info = Student
Name:
Richard Schooling Grade: A+ 11. >>VecA=[ 8 6 7];VecB=[2 3 6]; >>VecC= VecA + VecB >>A=[3 -5 7;7 8 3];B=[2 4 5; 1 2 2];
VecC = 10
9
13
C = 1
-9
2
6
6
1
5
-1
12
8
10
5
>>B=[3 4 ; 3 2 ; 7 8];
43
46
>>C=A*B
76
84
90
96
31
34
43
46
76
84
>>C= A - B
>>D= A + B
>>A=[2 3 4; 5 4 7; 3 6 9; 5 3 1];
>>D=A*B
D =
C =
D =
>>F=[6 7; 4 3]; G=[1 2; 4 5];
>>AV=[ 2 5 7];BV=[3;4;1];
>>A=[2 6 7 9; 3 2 1 4; 4 6 3 1]; b=2;
>>D=5*A
>>A=[3 -2 5; 3 2 6;7 4 2];
34
34
47
16
23
14
13
44
43
ans = 33 ans = 6
15
21
8
20
28
2
5
7
4
12
14
18
6
4
2
8
8
12
6
2
4
12
14
18
6
4
2
8
8
12
6
2
10
30
35
45
15
10
5
20
20
30
15
5
ans =
>>b*A
>>A*b
31
I =
>>AV*BV >>BV*AV
96
H =
>>H=F*G
>>I=G*F
90
ans =
D =
B =
0.1408
-0.1690
0.1549
-0.2535
0.2042
0.0211
0.0141
0.1831
-0.0845
1.0000
0.0000
-0.0000
-0.0000
1.0000
-0.0000
-0.0000
0.0000
1.0000
1.0000
0.0000
-0.0000
-0.0000
1.0000
-0.0000
-0.0000
0.0000
1.0000
>>B=inv(A)
>>A*B
>>A*A^-1
ans =
ans =
12. >>A = [4 -2 6;2 8 2;6 10 3]; >>B= [8;4;0];
X = -1.8049 0.2927
>>X = A\B
2.6341 >>Xb=inv(A)*B
Xb = -1.8049 0.2927 2.6341
>>C=[4 2 6;-2 8 10;6 2 3]
>>D=[8 4 0]
>>Xc=D/C
C = 4
2
6
-2
8
10
6
2
3
8
4
0
D =
Xc =
-1.8049
0.2927
2.6341
13. >>A=[3 6 8; 3 5 6]
>>B=[2 4 3; 6 3 4]
>>C=A.*B
>>D=A./B
>>E=B.^B
>>F=A.*B
>>x=[1:8]
A = 3
6
8
3
5
6
2
4
3
6
3
4
6
24
24
18
15
24
B =
C =
D = 1.5000
1.5000
2.6667
0.5000
1.6667
1.5000
E = 4
256
27
46656
27
256
6
24
24
18
15
24
F =
x = 1
>>y=x.^2 + 5*x
4
5
6
7
8
14
24
36
50
66
84
104
3
5
7
9
11
13
15
x = 1
>>y=(x.^3 + 5*x)./(4*x.^2 – 10)
3
y = 6
>>x=[1:2:15]
2
y =
Columns 1 through 7 -1.0000 2.0323 3.3964
1.6154 2.4650
1.6667 2.9241
Column 8 3.8764 x =
>>x=[0:pi/6:pi]
0 2.0944
0.5236 1.0472 2.6180 3.1416
1.5708
y =
>>y=cos(x)
1.0000 0.8660 0.5000 0.0000 -0.5000 -0.8660 -1.0000 14. Function mean(A)
Description
Example
Returns the mean of the element A A = along the first array dimension whose size does not equal 1
3
6
8
3
5
6
>> mean(A) ans = 3.00 C=max(A)
Returns the largest element of A
5.50
7.00
A = 3
6
8
3
5
6
>> C=max(A) C =
(d,n)=max(A)
Sets the number
maximum
3
6
8
3
6
8
definable A =
3
5
6
>> (d,n)=max(A) ans =
min(A)
Returns the smallest element of A
3
6
8
3
5
6
3
6
8
3
5
6
3
5
6
3
6
8
3
5
6
A =
>> min(A) ans =
(d,n)=min(A)
Sets the minimum definable number
A =
>> (d,n)=min(A) ans =
sum(A)
Returns the sum of the elements of A = A along the first array dimension whose size does not qual 1
3
6
8
3
5
6
3
6
8
3
5
6
6
11
14
3
6
8
>> sum(A) ans =
sort(A)
Sorts the elements ascending order
of A in A =
3
5
6
3
5
6
3
6
8
3
6
8
3
5
6
>> sort(A) ans =
median(A)
Returns the median value of A
A =
>> median(A) ans = 3.0000 7.0000 std(A)
Returns the standard deviation of A = the elements of A along the first array dimension whose size does not equal 1
5.5000
3
6
8
3
5
6
>> std(A) ans = 0
0.7071
1.4142 det(A)
To get the determinant of matrix A
A = 1
-2
4
-5
2
0
1
0
3
>> det(A) ans = -32 dot(a,b)
Returns the scalar dot product of a a = and b
2
35
6
5
67
88
22
56
89
1
-2
4
-5
2
0
1
0
3
>> b b =
>> dot(a,b) ans =
cross(a,b)
-1
64
291
2
35
6
5
67
88
22
56
89
1
-2
4
-5
2
0
1
0
3
Returns the cross product of a and a = b
>> b b =
>> cross(a,b) ans =
inv(A)
115
-112
264
20
-112
338
-15
204
-352
Computes the inverse of square A = matrix A
1
-2
4
-5
2
0
1
0
3
>> inv(A) ans = -0.1875 0.2500
-0.1875
-0.4688 0.6250
0.0313
0.0625 0.2500
0.0625
7. Conclusion: I therefore conclude that MATLAB is a very powerful and versatile software/tool. After getting acquainted and familiarized by following the procedures and doing the experiment, I found out that it can solve almost every matrices and vectors of any operations. Back then, my only known way of solving the matrices from the courses such as Linear Algebra and Advanced Mathematics manually, now I could solve it lightning speed by simply typing the equation on the command window. You just have to learn the basic commands and the fundamentals of MATLAB and it will greatly boost your arsenal of tools as a chemical engineering student. 8. Assessment (Rubric for Laboratory Performance):
View more...
Comments