Laboratory Activity 1 - Introduction To MATLAB (Part1)
Laboratory Activity 1 - Introduction To MATLAB (Part1)
Name: Date:
Section: Rating:
Exercises #01
Introduction to MATLAB (Part 1)
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.
− 2 3 1
5 7 − 1
− 9 0 2
A =
-2 3 1
5 7 -1
-9 0 2
1
1. Define the following matrices in MATLAB. Note that the variable names are case sensitive.
4 1 0 0 2 - 8 2
B = 1 3 2 C = − 2 0 6 d = 1 e = [9 0 5]
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
i. H*J, H.*J j. C^2, C.^2
Q2.2 Which operations above are invalid (i.e. those that returned error messages)? Explain why
each errors are returned?
>> M = 3 + 4i
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)
4
exp(M) Computes the value of e M . M can be a complex number.
log(M) Computes the logarithm of complex number M to the base e.
sinh(M),
cosh(M), Computes the hyperbolic sine, cosine and tangent of a complex number M.
tanh(M)
real(M),
Determines the real and imaginary parts of complex number M, respectively.
imag(M)
abs(M), Determines the magnitude and angle in radians of complex number M,
angle(M) respectively.
pi The value of constant π = 3.14159 ...
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 25 z 2
3. 4.
z1 z1
5
(2
3. cos 1 π − jπ ) 4. cosh(− 3 − j6)
5. sinh(4 + j5 )
>> x = [-10:10]
Using the plot function, a line graph can be generated. Typing the line below in MATLAB’s workspace
>> plot(x,y)
6
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,’--')
c. plot(x,y,’—o’)
d. plot(x,y,’-.xg’)
7
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