Assignment 1 Lab
Assignment 1 Lab
EMI-Lab
By: -
Hussain Ali (FA20-EEE-008)
Abdul Hanan (FA20-EEE-016)
Ali Ahmed Tariq (FA20-EEE-028)
Q1. Identify if the following variable is a scalar, a row vector, a column vector,
or a matrix and write your findings in the blank space provided in front of each
part.
a. var = [1 2 3 4 5]: - Row vector.
b. var = [100]: - Scalar.
c. var = [10:10:50]: - Row vector.
d. var = [10:15]: - Row vector.
e. var = [5: -1:1]: - Row vector.
f. var = [1;2;3]: - Column vector.
g. var = [0 -1; 2 4]: - Matrix.
h. var = [1 2 3 4 5]’: - Column vector.
Q2. Create a 3 × 2 matrix containing arbitrary data. Explore using the following
MATLAB functions. (Where N = 3 and M = 2 for this example).
a. zeros (N, M): -
Ans = 0 0
0 0
0 0
c. eye(N): -
Ans = 1 0 0
0 1 0
0 0 1
e. Find a way to use the square matrix eye (2) as part of your 3 × 2 matrix. Verify
the sizes of your arrays using size () and length () functions.
var = [1 2; eye (2)]
var = 1 2
1 0
0 1
Ones (): -
It is used to make matrix of ones.
eye (): -
It is used to make diagonal matrix.
rand (): -
It is used to make matrix of random number.
size (): -
It is used to get the size of matrix.
length (): -
It is used to get longest dimension of matrix (row or column).
Q3. Use the functions size () and length () to compute the size of the arrays
given by array1 = -1: 0.10.1:1 and array2 = 10: 2: 28. Consider general array
constructor patter, i.e., array = start: step: stop. Answer in the space provided
after evaluate ng each expression in MATLAB.
a. How many elements are in each array? array1: - 12_&_array2: - 10.
b. Can you add these arrays? Give reason. No, because dimensions are not same.
c. Now concatenate ones such that the number of columns in array1 are
increased by 2, (i.e., says array3 = [ ones (1,2), array2]. Can you add array1 and
array3? Give reason to your answer. Yes, because now both have same number of
dimensions.
e. Multiply array1 and the transpose of array2 (i.e., array 1 * array2’) as in part
d. Explain your findings? No, because dimension problem exists here.
f. Repeat the same with the expression given by array2’ * array1. What re the
dimensions of your output now? No, because dimension problem exists here.
Q4: -
a. Following the same procedure, compute the values of the following function
with input given along. (Write the first five values of the outputs in table
below).
b. Use the following functions write down the results in the following table.
MATLAB Domain Range (first five values)
Function
round () 2: 2: 14 2 4 6 8 10
ceil () {0, 𝜋⁄10, 2π} 0 32 7
floor () {0, 𝜋⁄10, 2π} 0 0 6
c. What does each function do to the input?
round (): -
It is used to round off decimal number to any nearest integer.
ceil (): -
It is also used to round off number but towards larger integer.
floor (): -
As its name indicate it round off number towards smaller integer.
Q5. Let’s visualize(plot) a sinusoid represented by the following expression,
Q2. Evaluate the following expressions in MATLAB and give the length of time,
‘t’ and output, ‘x’ vectors. Plot the signals as well. (t=start value: 0.05: end value;).
Q3. What is the purpose of the following built-in MATLAB functions and
special variables; give concise answers include format of the functions and an
example as well. (Use MathWorks website or MATLAB help): -
1. abs (): -
It is used to give absolute value of any complex number (say X).
Format: - abs (X)
Example: -
2. real (): -
It is used to give the complex part of complex number.
Format: - real ()
Example: -
3. conj (): -
It is used to give the complex number as output.
Format: - conj(X)
Example: -
4. diag(): -
It is used to make the diagonal matrix.
Format: - diag (X, Y)
Example: -
5. size (): -
It is used to get the size of matrix (means order of matrix).
Format: -size(X)
Example: -
6. inv (): -
It is used to give inverse of specified matrix(X).
Format: -inv(X)
Example: -
7. max (): -
It is used to get maximum number of matrix(X).
Format: - max ()
Example: -
8. atan(): -
It is used to give inverse of number.
Format: - atan(X)
Example: -
9. sound (): -
It is used to make signal in audible form (signal having time t).
Format: - sound (X, t)
Example: -
11.audioread(): -
It is used to read any audio file.
Format: - audioread (filename).
12.audiowrite (): -
It is used to write a matrix of audio data.
Format: -audiowrite(filename)
13.NaN: -
It is used to return the scalar representation of ‘not a number’.
Format: - NaN (X)
14. Inf/inf: -
It is used to represent infinity.
Format: - inf (m, n)
Example: -
15. mod (): -
It is used to give mode of number(n).
Format: - mode(n)
Example: -
16.ceil (): -
It gives closet integer number from number(n).
Format: - ceil(n)
Example: -
Where did you use the element-by-element multiplication? Why was it necessary?
Yes, we use element-by-element multiplication, without this error will occur. This is because of
incorrect dimensions in both matrixes.