MATLAB Matrix and Vector Operations 3 — Questions and Answers
Question 1: What does `norm(v, Inf)` compute for a vector v in MATLAB?
- The Euclidean (L2) norm
- The sum of absolute values
- The maximum absolute value of any element (Correct answer)
- Infinity
Correct answer: The maximum absolute value of any element
The infinity norm of a vector is the maximum of the absolute values of its elements.
Question 2: Given A is a 3x4 matrix, what is the size of `A' * A`?
- 3x3
- 4x4 (Correct answer)
- 3x4
- 4x3
Correct answer: 4x4
A' is 4x3, so A'*A is (4x3)*(3x4) = 4x4.
Question 3: Which MATLAB function performs LU decomposition of matrix A?
- lu(A) (Correct answer)
- lufactor(A)
- decomp(A, 'lu')
- factorize(A)
Correct answer: lu(A)
lu(A) returns lower and upper triangular factors L and U such that A = L*U (with optional permutation).
Question 4: What does `cross([1 0 0], [0 1 0])` return in MATLAB?
- [0 0 0]
- [1 1 0]
- [0 0 1] (Correct answer)
- [1 0 1]
Correct answer: [0 0 1]
The cross product of unit vectors i and j equals unit vector k, which is [0 0 1].
Question 5: How do you compute the cumulative sum of a vector v in MATLAB?
- sum(v)
- cumsum(v) (Correct answer)
- running_sum(v)
- accumarray(v)
Correct answer: cumsum(v)
cumsum returns a vector where each element is the sum of all previous elements including itself.
Question 6: What is `det` of the matrix [2 0; 0 3]`?
- 5
- 6 (Correct answer)
- 1
- -6
Correct answer: 6
For a diagonal 2x2 matrix, the determinant is the product of the diagonal elements: 2*3 = 6.
Question 7: In MATLAB, what does `reshape(1:12, 3, 4)` produce?
- A 4x3 matrix filled row-by-row
- A 3x4 matrix filled column-by-column (Correct answer)
- A 12x1 vector
- An error because 1:12 is a row vector
Correct answer: A 3x4 matrix filled column-by-column
reshape fills the output matrix column-by-column from the input data, producing a 3x4 matrix.
What does `norm(v, Inf)` compute for a vector v in MATLAB?