MATLAB MATLAB Numerical Methods and Optimization 2 — Questions and Answers
Question 1: Which MATLAB function computes the eigenvalues and eigenvectors of a matrix?
- eig (Correct answer)
- svd
- rank
- norm
Correct answer: eig
The eig function returns the eigenvalues and optionally the eigenvectors of a square matrix.
Question 2: What is the purpose of the `trapz` function in MATLAB?
- Numerical integration using the trapezoidal rule (Correct answer)
- Plotting trapezoidal shapes
- Decomposing a matrix into trapezoid form
- Computing the trace of a matrix
Correct answer: Numerical integration using the trapezoidal rule
trapz numerically integrates data using the trapezoidal rule over uniformly or non-uniformly spaced data points.
Question 3: How do you compute the LU decomposition of matrix A in MATLAB?
- [L, U, P] = lu(A) (Correct answer)
- [L, U] = decomp(A)
- ludecomp(A)
- [L, U] = factor(A)
Correct answer: [L, U, P] = lu(A)
The lu function performs LU factorization with partial pivoting, returning lower, upper, and permutation matrices.
Question 4: Which MATLAB function minimizes a function subject to linear constraints?
- linprog (Correct answer)
- fminsearch
- quadprog
- fminbnd
Correct answer: linprog
linprog solves linear programming problems to minimize a linear objective function subject to linear equality and inequality constraints.
Question 5: What does `cond(A)` compute in MATLAB?
- The condition number of matrix A (Correct answer)
- The conditional mean of A
- The eigenvalue condition of A
- The convergence order of A
Correct answer: The condition number of matrix A
cond(A) returns the 2-norm condition number of A, indicating how sensitive the solution is to perturbations.
Question 6: What is the output of `roots([1 -3 2])` in MATLAB?
- [2; 1] (Correct answer)
- [1; 2]
- [-1; -2]
- [3; -2]
Correct answer: [2; 1]
roots finds the roots of the polynomial x² - 3x + 2, which factors as (x-2)(x-1), giving roots 2 and 1.
Which MATLAB function computes the eigenvalues and eigenvectors of a matrix?