TensorTonic
Problems
Matrix Inverse
Linear Algebra
Medium

Compute the inverse of a square matrix with Gauss-Jordan elimination. The inverse A−1A^{-1}A−1 satisfies:

AA−1=A−1A=IAA^{-1}=A^{-1}A=IAA−1=A−1A=I

Form the augmented matrix [A∣I][A\mid I][A∣I]. For each column, choose the remaining row with the largest absolute pivot, swap it into place, scale the pivot row to make the pivot one, and eliminate that column from every other row. Return None if no nonzero pivot exists. Do not use NumPy linear-algebra solver or inverse functions. Return the right half as a floating-point NumPy array.

Loading visualization...

Examples

Input: A = [[1, 2], [3, 4]]

Output: [[-2, 1], [1.5, -0.5]]

Explanation: Multiplying A by this matrix gives the 2 by 2 identity matrix.

Input: A = [[2.0]]

Output: [[0.5]]

Hint 1

Build the augmented matrix with np.concatenate((matrix, np.eye(n)), axis=1).

Hint 2

Find each pivot row with column + np.argmax(np.abs(augmented[column:, column])).

Hint 3

Eliminate all non-pivot rows using their current value in the pivot column.

Requirements

  • Perform Gauss-Jordan elimination with partial pivoting
  • Normalize each pivot row and eliminate its column from all other rows
  • Return None for a singular matrix
  • Do not use np.linalg.inv, np.linalg.solve, or np.linalg.pinv

Constraints

  • A is a nonempty square numeric matrix
  • Treat a pivot with absolute value below 1e-12 as zero
  • Use NumPy only
Try Similar Problems
Calculate Eigenvalues of a MatrixMediumLinear Regression Closed FormMediumMatrix TransposeEasyPCA Projection onto Principal ComponentsHardMatrix TraceEasyImplement Sinusoidal Positional EncodingMediumCompute Pearson Correlation MatrixMediumParallel and Recurrent Linear AttentionMediumHessian Tensor of a Vector-Valued FunctionMediumPCA from ScratchMediumConvexity Certificate via the HessianMediumLow-Rank ApproximationMedium

Accepts: array

You must run your code first.
Matrix Inverse

Matrix Inverse

Linear Algebra
Medium

Compute the inverse of a square matrix with Gauss-Jordan elimination. The inverse A−1A^{-1}A−1 satisfies:

AA−1=A−1A=IAA^{-1}=A^{-1}A=IAA−1=A−1A=I

Form the augmented matrix [A∣I][A\mid I][A∣I]. For each column, choose the remaining row with the largest absolute pivot, swap it into place, scale the pivot row to make the pivot one, and eliminate that column from every other row. Return None if no nonzero pivot exists. Do not use NumPy linear-algebra solver or inverse functions. Return the right half as a floating-point NumPy array.

Loading visualization...

Examples

Input: A = [[1, 2], [3, 4]]

Output: [[-2, 1], [1.5, -0.5]]

Explanation: Multiplying A by this matrix gives the 2 by 2 identity matrix.

Input: A = [[2.0]]

Output: [[0.5]]

Hint 1

Build the augmented matrix with np.concatenate((matrix, np.eye(n)), axis=1).

Hint 2

Find each pivot row with column + np.argmax(np.abs(augmented[column:, column])).

Hint 3

Eliminate all non-pivot rows using their current value in the pivot column.

Requirements

  • Perform Gauss-Jordan elimination with partial pivoting
  • Normalize each pivot row and eliminate its column from all other rows
  • Return None for a singular matrix
  • Do not use np.linalg.inv, np.linalg.solve, or np.linalg.pinv

Constraints

  • A is a nonempty square numeric matrix
  • Treat a pivot with absolute value below 1e-12 as zero
  • Use NumPy only
Try Similar Problems
Calculate Eigenvalues of a MatrixMediumLinear Regression Closed FormMediumMatrix TransposeEasyPCA Projection onto Principal ComponentsHardMatrix TraceEasyImplement Sinusoidal Positional EncodingMediumCompute Pearson Correlation MatrixMediumParallel and Recurrent Linear AttentionMediumHessian Tensor of a Vector-Valued FunctionMediumPCA from ScratchMediumConvexity Certificate via the HessianMediumLow-Rank ApproximationMedium

Accepts: array

You must run your code first.
Problems
Loading...
1 / 1