Professional Documents
Culture Documents
Introduction:
The purpose of this exercise is to introduce MATLAB to students, its basic commands and functions.
MATLAB originally stood for Matrix Laboratory. Today it is regarded as high-performance language for
technical computing. This software incorporates many features that are used for many complex
mathematical computations, simulations and modeling.
-1
-9
1. Define the following matrices in MATLAB. Note that the variable names are case sensitive.
Q1.1. Write the commands that you issued to define the matrices above.
B=[4 1 0;1 3 2;0 2 5]
B=
4
1
0
1
3
2
0
2
5
C=[0,2,-8;-2,0,6;8,-6,0]
C=
0
2 -8
-2
0
6
8 -6
0
d=[2;1;4]
d=
2
1
4
e=[9 0 5]
e=
9
0
5
F=[3,2;4,1]
F=
3
2
4
1
G=[0,-2;4,5]
G=
0 -2
4
5
H=[3 0 2;4 0 1]
H=
3
4
0
0
2
1
Q1.2 Place a semi colon after defining one of the matrices above. What happens?
>>
>>
>>
>>
>>
>>
>>
>>
B = [4 1 0; 1 3 2; 0 2 5;];
C = [0 2 -8; -2 0 6; 8 -6 0];
d = [2;1;4];
e = [9 0 5];
F = [3 2; 4 1;];
G = [0 -2; 4 5;];
H = [3 0 2 ; 4 0 1];
J = [6 1 -5; 5 -2 13];
If one line of code places a semi colon after defining any of the matrices above, the output
is produced but is not shown in the Command Window. One can confirm that the code has
been produced by simply checking the value of the assigned variable in the Workspace
Window.
Q1.3 Which of the matrices defined above is/are row matrice/s? Column matrice/s? Square
matrice/s?
The only row matrix listed above is the matrix e. And the only column matrix listed above is the
matrix d. And the square matrices are matrix B,C,F, and G.
Row matrice/s
e
Column matrice/s
d
Square matrice/s
B
C
F
G
Q2.1 Using the matrices defined in part 1, perform the indicated operation. Record the output.
a.
AB , B
ans =
-5
9 11
27 24
9
-36 -5 10
ans =
-3 19
-5 24
-35 14
b.
H +J , H J
ans =
9
1 -3
9 -2 14
ans =
-3
-1
-1
7
2 -12
3
2
8
c.
C .A , A ./C
ans =
0
-10
-72
6
0
0
-8
-6
0
ans =
-Inf 1.5000 -0.1250
-2.5000
Inf -0.1667
-1.1250
0
Inf
d.
d +e ,d + e , d + e
d+e
Error using +
Matrix dimensions must agree.
d+e',d'+e
ans =
11
1
9
ans =
11
e.
d , e
ans =
3
ans =
1
f.
g.
inv(C), inv(G)
Warning: Matrix is singular to working precision.
ans =
Inf Inf Inf
Inf Inf Inf
Inf Inf Inf
ans =
0.6250
-0.5000
h.
0.2500
0
BC , B .C
ans =
-2
8 -26
10 -10 10
36 -30 12
ans =
0
2
-2
0
0 -12
i.
0
12
0
HJ , H .J
H*J
Error using *
Inner matrix dimensions must agree.
H.*J
ans =
18
20
j.
0 -10
0 13
C2, C . 2
ans =
-68 48 12
48 -40 16
12 16 -100
ans =
0
4
64
4
0
36
64
36
0
Q2.2 Which operations above are invalid (i.e. those that returned error messages)? Explain why
each errors are returned?
Invalid commands
d +e
det (d )
HJ
Explanation
It is impossible to add/subtract unequal
dimensions. Both matrix d and e needs
to have same dimensions (e.g. 2x2 +
2x2)
In solving/finding for the determinant of
a matrix, the matrix itself has to be a
square, dimensionally.
In multiplying matrices, both matrices
must have similar inner matrix
dimension. (e.g. 3x2 * 2x4, since they
both have 2 as their inner dimension,
they can be multiplied)
x+ jyr < .
1.
z1 z2
9.
abs(z1*z2),angle(z
1*z2)
2.
3. z1*z2
4.
5.
ans =
6.
7.
-14.0000i
8.
10.
11.
12.
13.
23.0000
ans =
26.9258
14.
15.
16.
17.
ans =
-0.5468
18.
Answer: 23-j14 or
26.9258<0.548
19.
20.
( 3 z 1z 2)
21.
22.
(3*z1-z2)^2
23.
24.
ans =
25.
26.
-9.6000e+01 +
2.8000e+02i
27.
28.
abs((3*z1z2)^2),angle((3*z1-z2)^2)
29.
30.
ans =
31.
32.
296
33.
34.
ans =
35.
36.
1.9011
37.
Answer: -96+j280 or
296<1.9011
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
-0.6435
Answer: 0.16-j0.12
or
63.
64.
65.
0.2<-0.6435
25 z 2
z1
66.
67.
(25*z2)/z1
68.
69.
ans =
70.
71.
-7.0000 -26.0000i
72.
73.
abs(((25*z2)/z1)),angle(((
25*z2)/z1))
74.
75.
ans =
76.
77.
26.9258
78.
79.
ans =
80.
81.
-1.8338
82.
Answer: -7-j26 or
83.
26.9258 <1.8338
84.
85.
1
z1
1/z1
ans =
0.1600 - 0.1200i
abs(1/z1),angle(1/z1)
ans =
0.2000
ans =
86.
(z 31 )( z 1 )3
87.
88.
real(z1^3),(real(z1))^3
89.
90.
ans =
91.
92.
-44
93.
94.
ans =
95.
96.
64
97.
98.
abs(real(z1^3)),angle(rea
l(z1^3))
99.
100.
ans =
101.
102.
44
113.
64
103.
114.
104.
115.
105.
ans =
116.
ans =
106.
117.
107.
3.1416
118.
0
108.
119.
109.
abs(((real(z1))^3)),angle(
120.
Answer: -44+j0 and
((real(z1))^3))
64+j0
110.
121.
or 44<3.1416 and
111.
ans =
64<0
112.
122.
123.
124.
125.
Q3.2 Find values in the rectangular form
126.
cos( 1+ j)
1.
2.
3. ans =
4.
5.
0.8337 - 0.9889i
6. Answer: 0.8337j0.9889
7.
8.
sin j
9.
10.
sin(j*pi)
11.
12.
ans =
13.
14.
0.0000
+11.5487i
15.
Answer: 0+j11.5487
16.
17.
1
cos ( j)
2
18.
cos(pi/2-pi*i)
19.
20.
ans =
21.
22.
0.0000
+11.5487i
23.
Answer: 0+j11.5487
24.
cosh (3 j 6)
25.
26.
cosh(-3-6i)
27.
28.
ans =
29.
30.
9.6667 - 2.7991i
31.
Answer: 9.6667-
j2.7991
32.
33.
34.
35.
sinh( 4+ j5)
36.
37.
sinh(4+5j)
38.
39.
ans =
40.
41.
7.7411 -26.1865i
42.
43.
Answer: 7.7411-
j26.1865
44.
45.
46.
47.
48.
49.
50.
84.
b. plot(x,y,'--')
the line became a dashed line.
85.
c. plot(x,y,'-o')
the line remains a solid line but with circles.
86.
d. plot(x,y,'-.xg')
the line was assigned as green with dashed
lines and plus
87.
symbol.
88.
89.
Q4.5 Using the plot function, obtain the graph of the functions
y=x 210
and
below.
90.
91.
y=x 210 .
94.
95.
3
Figure 4.5.2. A graph of the function y=x 2 .