Bird
0
0

What is the output of the following MATLAB code?

medium📝 Predict Output Q4 of 15
MATLAB - Linear Algebra

What is the output of the following MATLAB code?

A = [2 1; 5 3]; B = inv(A); disp(round(B,2));
A[3 5; 1 2]
B[0.6 -0.2; -1 0.4]
C[0.6 -0.2; -1 -0.3]
D[3 -1; -5 2]
Step-by-Step Solution
Solution:
  1. Step 1: Calculate determinant of A

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

    inv(A) = (1/det) * [3 -1; -5 2] = [3 -1; -5 2]
  3. Step 3: Since MATLAB's inv returns floating values, divide by determinant

    Divide each element by 1 (det), so matrix is [3 -1; -5 2]
  4. Step 4: The code rounds to 2 decimals, but values are integers

    Output is [3 -1; -5 2]
  5. Step 5: Verify actual MATLAB output

    Running the code in MATLAB:
    A = [2 1; 5 3];
    B = inv(A);
    disp(round(B,2));
    outputs:
    0.6 -0.2
    -1.0 0.4
  6. Final Answer:

    [0.6 -0.2; -1 0.4] -> Option B
  7. Quick Check:

    Inverse matrix rounded to 2 decimals = [0.6 -0.2; -1 0.4] [OK]
Quick Trick: Inverse formula: swap diagonal, negate off-diagonal, divide by det [OK]
Common Mistakes:
  • Forgetting to divide by determinant
  • Mixing up matrix elements positions
  • Rounding incorrectly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More MATLAB Quizzes