MATLAB Matrix and Vector Operations 4 — Questions and Answers
Question 1: What does `pinv(A)` compute when A is not square?
- The regular inverse of A
- The Moore-Penrose pseudoinverse of A (Correct answer)
- The partial inverse of A
- An error
Correct answer: The Moore-Penrose pseudoinverse of A
pinv computes the Moore-Penrose pseudoinverse, which provides a least-squares solution for non-square or singular matrices.
Question 2: Which MATLAB command creates a 5x5 matrix of uniformly distributed random numbers?
- random(5,5)
- rand(5) (Correct answer)
- uniform(5,5)
- randi(5)
Correct answer: rand(5)
rand(5) generates a 5x5 matrix with values uniformly distributed between 0 and 1.
Question 3: What is the MATLAB syntax to flip a matrix A left-to-right?
- flip(A)
- fliplr(A) (Correct answer)
- rot90(A)
- flipud(A)
Correct answer: fliplr(A)
fliplr reverses the order of columns, effectively reflecting the matrix horizontally.
Question 4: How do you compute the condition number of matrix A in MATLAB?
- condnum(A)
- cond(A) (Correct answer)
- condition(A)
- kappa(A)
Correct answer: cond(A)
cond(A) returns the 2-norm condition number, which indicates sensitivity of the solution to perturbations.
Question 5: What does `kron(A, B)` compute in MATLAB?
- The element-wise product of A and B
- The Kronecker tensor product of A and B (Correct answer)
- The concatenation of A and B
- The Kronecker delta of A and B
Correct answer: The Kronecker tensor product of A and B
kron computes the Kronecker tensor product, replacing each element of A with that scalar times B.
Question 6: What is the output of `sum(eye(4))` in MATLAB?
- 4
- [1 1 1 1] (Correct answer)
- 16
- [4 0 0 0]
Correct answer: [1 1 1 1]
sum operates column-wise by default; each column of eye(4) has exactly one 1, so the result is [1 1 1 1].
Question 7: Which MATLAB function computes the singular value decomposition of a matrix A?
- [U, S, V] = svd(A) (Correct answer)
- [U, S, V] = singular(A)
- [U, S, V] = decomp(A)
- svdecomp(A)
Correct answer: [U, S, V] = svd(A)
svd(A) returns unitary matrices U and V and a diagonal matrix S of singular values such that A = U*S*V'.
What does `pinv(A)` compute when A is not square?