Sparse Matrices

MATLAB

This set of MATLAB Multiple Choice Questions & Answers focuses on “Sparse Matrices”.

1. What is the output of the following code?

A=[0 0 0; 0 9 0; 1 2 3]; nnz[A]

a) 4
b) 5
c) 3
d) Error

2. What is the output of the following code?

A=[1 2 3; 32 23 26; 0 0 0]; spones(A)

a) Returns a sparse matrix with the non-zeros replaced by normally distributed random numbers
b) Returns a sparse matrix with the zeros replaced by ones
c) Returns a sparse matrix with the non-zeros replaced by fractions
d) Returns a sparse matrix with the non-zeros replaced by random numbers

3. The space located for the matrix generated from the spones command is _______
a) Same as a sparse matrix
b) Same as the original matrix
c) Same as an identity matrix
d) Double that of the sparse matrix

4. What is the output of the following code?

A=[1 2 3; 4 5 6; 7 8 9];if( nzmax(A)==nzmax(spones(A) ) disp(‘Yeah !’)

a) No output
b) Error
c) Yeah !
d) Output suppressed

5. What is the output of the following code?

nnz(spconvert([1 2 3; 4 5 6; 7 8 9])

a) 3
b) 2
c) 1
d) 6

6. What is the output of the following code?

nzmax(spconvert([1 2 3; 4 5 6; 7 8 9])

a) 2
b) 3
c) 1
d) Error

7. A memory for sparse matrix is dedicated by the ______ command.
a) spalloc
b) sparsealloc
c) allocspar
d) no such command

8. What is the output of the following command?

spalloc(2,3, 7)

a) A 2*3 sparse matrix
b) Memory is allocated for a 2*3 sparse matrix
c) A 3*2 sparse matrix
d) Error

9. The default number of non-zero elements which can be put into the memory allocated by the spalloc command is > 1.
a) True
b) False

10. The pattern generated by the spy command is a measure of the number of zeros in the input matrix.
a) True
b) False

11. What is the attribute of sparse matrices?
a) sparse
b) double
c) vector
d) no attribute

12. What is the output of the following code?

sparse[m n]

a) A m*n all zero sparse matrix
b) A m*n sparse matrix
c) Error due to syntax
d) Error in the input

13. The nature of complex input taken by the sparse() command is ______________
a) Only Imaginary part
b) Only positive imaginary part
c) Only negative real part
d) All of the mentioned

14. Which of the following can be the space taken up by a sparse matrix?
a) .25 megabytes
b) 600 megabytes
c) .5 GB
d) 450 megabytes

15. To check whether the input matrix is sparse or not, we use the ________ command.
a) issparse
b) besparse
c) ifsparse
d) sparse

16. A sparse identity matrix is generated by the ______ command.
a) sparseid
b) isparse
c) speye
d) idensparse

17. What is the command used to generate a sparse normally generated matrix?
a) sparserndn
b) sprandom
c) sprandn
d) no such command

18. 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

19. The non-zero elements in a sparse matrix are shown by the ______ command.
a) nzeros
b) nonzeros
c) notzeros
d) nozero

20. 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

21. The size of the sparse matrix will be ___ the original matrix.
a) equal
b) greater than
c) less than
d) not equal to

22. The maximum space allocated for sparse matrices is given by the ____ command.
a) maxsparse
b) sparsemax
c) nzmax
d) no such command

23. 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

24. 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

25. The spy command takes in multiple matrices.
a) True
b) False

Leave a Reply

Your email address will not be published. Required fields are marked *