Final 2.34 PDF
Final 2.34 PDF
Final 2.34 PDF
Name: Date:
Section: Rating:
Exercises #02
Matrix Operation, Complex Numbers and 2-D Plotting
2 3 1
5 7 1
9 0 2
A =
1
-2 3 1
5 7 -1
-9 0 2
1. Define the following matrices in MATLAB. Note that the variable names are case sensitive.
4 1 0 0 2 - 8 2
e 9 0 5
B 1 3 2 C 2 0 6 d 1
0 2 5 8 6 0 4
3 2 0 2 3 0 2 6 1 5
F G H J
4 1 4 5 4 0 1 5 2 13
Q1.1. Write the commands that you issued to define the matrices above.
Q1.2 Place a semi colon after defining one of the matrices above. What happens?
Q1.3 Which of the matrices defined above is/are row matrice/s? Column matrice/s? Square
matrice/s?
2
Part 2 – Matrix operation
The following are MATLAB symbols for matrix operation
Operator Function
Element-by-element addition and subtraction, respectively. Matrices to be
+ or -
added or subtracted should be of the same dimension
Matrix multiplication and division, respectively. Matrices to be multiplied or
* or / divided should be conformable. If one of the operands is a scalar, the
operation becomes scalar.
^ Matrix exponentiation. One of the operands must be scalar
Element-by-element multiplication, division and exponentiation, respectively.
.* or ./ or .^ Matrices to be operated on an element-by-element basis should be of the
same dimension.
size(A) Determines the dimensions of matrix A.
A’ Determines the transpose of matrix A.
inv(A) Determines the inverse of matrix A. The matrix should be non-singular.
det(A) Evaluate the determinant of matrix A.
Q2.1 Using the matrices defined in part 1, perform the indicated operation. Record the output.
a. A*B, B*A b. H + J, H - J
3
g. inv(C), inv(G) h. B*C, B.*C
Q2.2 Which operations above are invalid (i.e. those that returned error messages)? Explain why
each errors are returned?
>> M = 3 + 4i
4
The table below summarizes other functions of MATLAB and their syntax
Operation Function
sin(M),
Obtains the value of sine, cosine and tangent of M. M is assumed to be in radians.
cos(M),
M can be a complex number.
tan(M)
Q3.1 Let z1 4 j3 and z 2 2 j5 . Find each of the following in the form x jy and r .
1. z1z 2 2. 3z1 z 2 2
1 25z 2
3. 4.
z1 z1
5
2
3. cos 1 j 4. cosh 3 j6
5. sinh4 j5
>> x = [-10:10]
6
Using the plot function, a line graph can be generated. Typing the line below in MATLAB’s workspace
>> plot(x,y)
30
20
10
-10
-20
-30
-40
-10 -5 0 5 10
Q4.3 What features are added to the plot when the following commands are issued?
a. grid on
c. xlabel(‘x’)
d. ylabel(‘y’)
e. title(‘Line’)
f. clf
Q4.4 What happens when you change the plot command to the following?
a. plot(x,y,’r’)
b. plot(x,y,’--')
7
c. plot(x,y,’—o’)
d. plot(x,y,’-.xg’)
Q4.4 Using the plot function, obtain the graph of the functions y x 2 10 and y x 3 2 . Plot
the curves on the space provided below.
parabola
10
-2
-4
-6
-8
-10
-10 -8 -6 -4 -2 0 2 4 6 8 10
cubic function
10
-2
-4
-6
-8
-10
-10 -8 -6 -4 -2 0 2 4 6 8 10
8
9
Laboratory Report
Signals, Spectra and Signal Processing (ECE 401)
Name: Date:
Section: Rating:
Exercises #02
Matrix Operation, Complex Numbers and 2-D Plotting
DATA
3 2 0 2 3 0 2 6 1 5
F G H J
4 1 4 5 4 0 1 5 2 13
Q1.1. Write the commands that you issued to define the matrices above.
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]
Q1.2 Place a semi colon after defining one of the matrices above. What happens?
It doesn't display results and goes directly to a new line.
10
Q1.3 Which of the matrices defined above is/are row matrice/s? Column matrice/s? Square
matrice/s?
Row Matrices:
e
Column Matrices:
d
Square Matrices:
B,C F G H J
11
i. H*J, H.*J j. C^2, C.^2
H*J= C^2= C.^2=
Error using * -68 48 12 0 4 64
Incorrect dimensions for matrix multiplication. Check 48 -40 16 4 0 36
that the number of columns in the first matrix matches 12 16 -100 64 36 0
the number of rows in the second matrix. To perform
elementwise multiplication, use '.*'.
H.*J= 18 0 -10
20 0 13
Q2.2 Which operations above are invalid (i.e. those that returned error messages)? Explain why
each errors are returned?
det(d): Error using det. Matrix must be square. in using det function, the matrix must be a square matrix.
H*J: Error using * Incorrect dimensions for matrix multiplication. Check that the number of columns in the first matrix matches
the number of rows in the second matrix. To perform elementwise multiplication, use '.*'.
The number of columns in the first matrix must match the number of columns of the other matrix.
The * symbol is defined as matrix multiplication when used on two matrices while .* symbol is used
to specify element-wise multiplication.
Q3.1 Let z1 4 j3 and z 2 2 j5 . Find each of the following in the form x jy and r .
x = z1*z2 y= ((3*z1)-z2)^2
1. z1z 2 x = 23.0000 -14.0000i 2. 3z1 z 2 2 y = -96 + 280i
abs(x), angle(x) abs(y), angle(y)
ans = 26.9258 ans = 296
ans = -0.5468 ans = 1.9011
26.9258∠ -0.5468 296∠ 1.9011
12
5. Re z13 and Re z1 3
>> real (z1^3)
ans = -44
>> (real(z1))^3
ans = 64
2
3. cos 1 j 4. cosh 3 j6
>> cosh(-3-6i)
>> cos((1/2*pi)-(i*pi))
ans =
ans =
9.6667 - 2.7991i
7.098e-16 + 11.549i
5. sinh4 j5
>> sinh(4+5i)
ans =
7.7411 - 26.187i
13
Q4.2 Define y in terms of x.
>> plot(x,y)
Q4.3 What features are added to the plot when the following commands are issued?
g. grid on
Enables grid view in the graph.
j. ylabel(‘y’)
Inserts a label name for Y - axis.
k. title(‘Line’)
Inserts the title name of the graph.
l. clf
Q4.4 What happens when you change the plot command to the following?
e. plot(x,y,’r’)
14
h. plot(x,y,’-.xg’)
Q4.4 Using the plot function, obtain the graph of the functions y x 2 10 and y x 3 2 . Plot
the curves on the space provided below.
Conclusion:
(Student Name 2): This laboratory experiment is important to students who are taking the subject
because it recalls the basic elements of the matlab software.
MATLAB has many commands that you can apply like Microsoft Excel but more applicable to
(Student Name 3): Engineers and Scientist. Because of Matrices and 2D Graphs in MATLAB has many useful
features that only Engineers can appy.
(Student Name 4): In this experiment it refresh my knowledge about MATLAB and the
different types of plot that MATLAB has. And also computing complex
numbers using matlab.
15