1. A sparse identity matrix is generated by the ______ command.
a) sparseid
b) isparse
c) speye
d) idensparse
Explanation: The correct command to generate a sparse identity matrix is the speye command. The issparse command checks whether an input matrix is a sparse matrix. Hence speye is correct.
2. What is the command used to generate a sparse normally generated matrix?
a) sparserndn
b) sprandom
c) sprandn
d) no such command
Explanation: The sprandn command uses the same random number generator as that of the randn command. The rest of the commands don’t exist.
3. What is the output of the following code?
A=[1 2 0 3; 2 8 4 1; sin(Inf) 2 3 4];
P=sparse(A); nnz(P)
a) 11
b) 10
c) Error while declaring A
d) Error while making sparse matrix
Explanation: The number of non-zero numbers in the A vector is 11. Sin(Inf) Is treated as NaN and holding a non-zero value since the range of sine is [-1,1]. There won’t be any error while declaring A or making the sparse matrix.
4. The non-zero elements in a sparse matrix are shown by the ______ command.
a) nzeros
b) nonzeros
c) notzeros
d) nozero
Explanation: The non-zeros command is used to get the non-zero elements present in the sparse matrix. The rest of the options are not defined in MATLAB.
5. What is the output of the following code?
A=[0 Inf/Inf 0 0; 2 9 7 0; sin(Inf) 8 0 0];
P=sparse(A);q=nmz(p); L=full(P);
a) l = a
b) lmemory > amemory
c) lmemory < amemory
d) lmemory != amemory
Explanation: The full command converts a sparse matrix into it’s original matrix. The space taken up by both the matrices in the memory are same. Hence, only l=a is correct.
6. The size of the sparse matrix will be ___ the original matrix.
a) equal
b) greater than
c) less than
d) not equal to
Explanation: The sparse matrix stores the non-zero elements in the sparse matrix. The space taken up by the sparse matrix being very less than the original, the size of both the matrix will be same. Hence, only option equal is correct.
7. The maximum space allocated for sparse matrices is given by the ____ command.
a) maxsparse
b) sparsemax
c) nzmax
d) no such command
Explanation: The nzmax is the command to find the maximum space allocated for sparse matrices. The maximum space is proportional to the number of non-zero elements in the original matrix.
8. The output of the following command is
a=[1 2 3;4 0 0;3 0 9]; spy(A)
a) a graph of sparsity
b) a pattern of sparsity
c) syntactical error
d) logical error
Explanation: The spy command generates the sparsity pattern of the sparse matrix which might be generated from the given matrix. The output will generate a pattern in a window which shows the position of non-zero elements occupying space.
9. The output of the following code is:
a=[pi/2 pi 3*pi]; spy[a]
a) Suppressed output
b) A pattern of sparsity
c) Syntactical error
d) Symbolic error
Explanation: The input to the spy command has to be within parentheses. Due to this, there will be a syntactical error in the above command.
10. The spy command takes in multiple matrices.
a) True
b) False
Explanation: The spy command does not take in multiple inputs. It will show the sparsity pattern of only input vector.