PIXELBANKv8.3.0
Menu

Solve Linear System

Problem Statement

Solve a system of linear equations Ax = b.

Background

A linear system Ax = b can be solved using:

  • np.linalg.solve(A, b) - direct solution
  • np.linalg.inv(A) @ b - via inverse (less efficient)

Example: 2x + y = 5, x + 3y = 7 Matrix form: [[2,1],[1,3]] @ [x,y] = [5,7]

Your Task

Write a function solve_system(A, b) that solves the linear system.

Output Format

Return a dictionary with:

  • "solution": Solution vector x (rounded to 2 decimals, as list)
  • "verification": A @ x (should equal b, rounded to 2 decimals, as list)
  • "is_correct": True if A @ x ≈ b

Example:

Input:
A = [[2, 1], [1, 3]], b = [5, 7]
Output:
{'solution': [1.6, 1.8], 'verification': [5.0, 7.0], 'is_correct': True}
Reasoning:

2(1.6) + 1(1.8) = 5, 1(1.6) + 3(1.8) = 7

Constraints:

  • A is square and invertible
  • Round to 2 decimal places
Editor

Test Results

0/0
Run code to see test results.