Skip to content
QuantReadySign In
#452easyMatrix Operations

Solve 2x2 Linear System

Problem

Given a 2×22 \times 2 matrix AA and a vector bb, solve the linear system Ax=bAx = b using Cramer's rule (or direct matrix inversion).

(a11a12a21a22)(x1x2)=(b1b2)\begin{pmatrix} a_{11} & a_{12} \\ a_{21} & a_{22} \end{pmatrix} \begin{pmatrix} x_1 \\ x_2 \end{pmatrix} = \begin{pmatrix} b_1 \\ b_2 \end{pmatrix}

The determinant det(A)=a11a22a12a21\det(A) = a_{11} a_{22} - a_{12} a_{21} is guaranteed to be nonzero.

Input Format

Six space-separated values: a11 a12 a21 a22 b1 b2

Output Format

Two space-separated values: x1 x2, each to 4 decimal places.

Examples

Example 1
Input(Six space-separated values: a11 a12 a21 a22 b1 b2)
2 1 1 3 5 7
Output
1.6000 1.8000

2x+y=5, x+3y=7. det=5, x1=(15-7)/5=1.6, x2=(14-5)/5=1.8.

Example 2
Input(Six space-separated values: a11 a12 a21 a22 b1 b2)
1 0 0 1 3 4
Output
3.0000 4.0000

Identity matrix: x1=3, x2=4.

Constraints

  • Determinant of A is nonzero (system has unique solution)
  • -1000 ≤ matrix entries ≤ 1000
  • Output to 4 decimal places

Execution limits: 2s · 256MB

Loading interactive editor…