Bird
Raised Fist0
MATLABdata~20 mins

Matrix inverse (inv) in MATLAB - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Matrix Inverse Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
2:00remaining
Output of matrix inverse multiplication
What is the output of this MATLAB code snippet?
MATLAB
A = [2 1; 5 3];
B = inv(A) * A;
A[1 0; 0 1]
B[0 1; 1 0]
C[2 1; 5 3]
DError: Matrix is singular
Attempts:
2 left
💡 Hint
Multiplying a matrix by its inverse results in the identity matrix.
❓ Predict Output
intermediate
2:00remaining
Result of inverse on singular matrix
What happens when you run this MATLAB code?
MATLAB
A = [1 2; 2 4];
B = inv(A);
A[1 2; 2 4]
BError: Matrix is singular to working precision.
C[0.5 -0.25; -0.25 0.125]
DError: Matrix must be square.
Attempts:
2 left
💡 Hint
Check if the matrix has linearly dependent rows.
🔧 Debug
advanced
2:00remaining
Identify the error in matrix inverse calculation
What error does this MATLAB code produce?
MATLAB
A = [1 2 3; 4 5 6];
B = inv(A);
AError: Matrix must be square.
B[0.5 -0.5 0; -0.5 0.5 0]
C[1 0 0; 0 1 0; 0 0 1]
DError: Matrix is singular.
Attempts:
2 left
💡 Hint
Check the shape of the matrix before inversion.
❓ Predict Output
advanced
2:00remaining
Inverse of a diagonal matrix
What is the output of this MATLAB code?
MATLAB
D = diag([4 5 6]);
E = inv(D);
AError: Matrix is singular.
B[4 5 6; 0 0 0; 0 0 0]
C[1 0 0; 0 1 0; 0 0 1]
D[0.25 0 0; 0 0.2 0; 0 0 0.1667]
Attempts:
2 left
💡 Hint
The inverse of a diagonal matrix is a diagonal matrix with reciprocal elements.
🧠 Conceptual
expert
2:00remaining
Properties of matrix inverse and multiplication
Given a nonsingular matrix A, which statement is TRUE?
Ainv(A + B) = inv(A) + inv(B)
Binv(A * B) = inv(A) * inv(B)
Cinv(A * B) = inv(B) * inv(A)
Dinv(A) * A = zeros(size(A))
Attempts:
2 left
💡 Hint
Recall the order of multiplication when inverting a product.

Practice

(1/5)
1.

What does the MATLAB function inv(A) do when A is a square matrix?

easy
A. Calculates the eigenvalues of matrix A
B. Calculates the transpose of matrix A
C. Calculates the inverse of matrix A
D. Calculates the determinant of matrix A

Solution

  1. Step 1: Understand the function purpose

    The function inv in MATLAB is designed to compute the inverse of a square matrix.
  2. Step 2: Recall matrix inverse definition

    The inverse of a matrix A is a matrix B such that A * B = I, where I is the identity matrix.
  3. Final Answer:

    Calculates the inverse of matrix A -> Option C
  4. Quick Check:

    inv(A) = inverse of A [OK]
Hint: inv() finds matrix inverse, not transpose or determinant [OK]
Common Mistakes:
  • Confusing inverse with transpose
  • Thinking inv() calculates determinant
  • Assuming inv() returns eigenvalues
2.

Which of the following is the correct syntax to compute the inverse of a matrix A in MATLAB?

easy
A. A\inv
B. inverse(A)
C. A.inv()
D. inv(A)

Solution

  1. Step 1: Recall MATLAB function for inverse

    MATLAB uses the function inv() to compute the inverse of a matrix.
  2. Step 2: Check syntax correctness

    The correct syntax is inv(A). Other options are not valid MATLAB syntax for matrix inverse.
  3. Final Answer:

    inv(A) -> Option D
  4. Quick Check:

    Use inv(A) to invert matrix A [OK]
Hint: Use inv(A) function, not inverse() or dot notation [OK]
Common Mistakes:
  • Using inverse(A) instead of inv(A)
  • Trying object-oriented syntax like A.inv()
  • Confusing backslash operator with inv()
3.

What is the output of the following MATLAB code?

A = [1 2; 3 4]; B = inv(A); disp(round(B,2));
medium
A. [[-2.00 1.00]; [1.50 -0.50]]
B. [[4.00 -2.00]; [-3.00 1.00]]
C. [[1.00 3.00]; [2.00 4.00]]
D. Error: Matrix is singular

Solution

  1. Step 1: Calculate determinant of A

    det(A) = (1*4) - (2*3) = 4 - 6 = -2 (non-zero, so inverse exists)
  2. Step 2: Compute inverse of A

    Inverse formula for 2x2 matrix: (1/det) * [d -b; -c a] = (1/-2) * [4 -2; -3 1] = [[-2 1]; [1.5 -0.5]]
  3. Final Answer:

    [[-2.00 1.00]; [1.50 -0.50]] -> Option A
  4. Quick Check:

    inv(A) = [[-2 1]; [1.5 -0.5]] [OK]
Hint: Use formula for 2x2 inverse: swap diagonal, negate off-diagonal [OK]
Common Mistakes:
  • Mixing up signs in inverse formula
  • Calculating determinant incorrectly
  • Confusing inverse with transpose
4.

Consider this MATLAB code snippet:

A = [1 2; 2 4]; B = inv(A); disp(B);

What is the problem with this code?

medium
A. Matrix A is not square
B. Matrix A is singular and cannot be inverted
C. Syntax error in inv function usage
D. Matrix A is not numeric

Solution

  1. Step 1: Check matrix shape

    Matrix A is 2x2, so it is square, no problem here.
  2. Step 2: Check if matrix is invertible

    Calculate determinant: det(A) = (1*4) - (2*2) = 4 - 4 = 0, so A is singular and cannot be inverted.
  3. Final Answer:

    Matrix A is singular and cannot be inverted -> Option B
  4. Quick Check:

    det(A) = 0 means no inverse [OK]
Hint: Check determinant; zero means no inverse [OK]
Common Mistakes:
  • Assuming all square matrices are invertible
  • Ignoring determinant calculation
  • Thinking syntax error causes failure
5.

You have a system of linear equations represented by A * x = b, where A is a 3x3 matrix and b is a vector. Which MATLAB command is the best practice to find x?

hard
A. x = A \ b;
B. x = inv(A) * b;
C. x = A / b;
D. x = b * inv(A);

Solution

  1. Step 1: Understand solving linear systems in MATLAB

    Using inv(A)*b works but is inefficient and less accurate.
  2. Step 2: Use MATLAB backslash operator

    The recommended way is x = A \ b; which solves the system efficiently without explicitly computing inverse.
  3. Final Answer:

    x = A \ b; -> Option A
  4. Quick Check:

    Use backslash \ for solving Ax=b, not inv(A) [OK]
Hint: Use backslash \ operator to solve linear systems [OK]
Common Mistakes:
  • Using inv(A)*b which is slower and less stable
  • Using division operators incorrectly
  • Multiplying b by inv(A) instead of inv(A)*b
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard