matrix.cramers_rule_2x2

Functions

cramers_rule_2x2(→ tuple[float, float])

Solves the system of linear equation in 2 variables.

Module Contents

matrix.cramers_rule_2x2.cramers_rule_2x2(equation1: list[int], equation2: list[int]) tuple[float, float]

Solves the system of linear equation in 2 variables. :param: equation1: list of 3 numbers :param: equation2: list of 3 numbers :return: String of result input format : [a1, b1, d1], [a2, b2, d2] determinant = [[a1, b1], [a2, b2]] determinant_x = [[d1, b1], [d2, b2]] determinant_y = [[a1, d1], [a2, d2]]

>>> cramers_rule_2x2([2, 3, 0], [5, 1, 0])
(0.0, 0.0)
>>> cramers_rule_2x2([0, 4, 50], [2, 0, 26])
(13.0, 12.5)
>>> cramers_rule_2x2([11, 2, 30], [1, 0, 4])
(4.0, -7.0)
>>> cramers_rule_2x2([4, 7, 1], [1, 2, 0])
(2.0, -1.0)
>>> cramers_rule_2x2([1, 2, 3], [2, 4, 6])
Traceback (most recent call last):
    ...
ValueError: Infinite solutions. (Consistent system)
>>> cramers_rule_2x2([1, 2, 3], [2, 4, 7])
Traceback (most recent call last):
    ...
ValueError: No solution. (Inconsistent system)
>>> cramers_rule_2x2([1, 2, 3], [11, 22])
Traceback (most recent call last):
    ...
ValueError: Please enter a valid equation.
>>> cramers_rule_2x2([0, 1, 6], [0, 0, 3])
Traceback (most recent call last):
    ...
ValueError: No solution. (Inconsistent system)
>>> cramers_rule_2x2([0, 0, 6], [0, 0, 3])
Traceback (most recent call last):
    ...
ValueError: Both a & b of two equations can't be zero.
>>> cramers_rule_2x2([1, 2, 3], [1, 2, 3])
Traceback (most recent call last):
    ...
ValueError: Infinite solutions. (Consistent system)
>>> cramers_rule_2x2([0, 4, 50], [0, 3, 99])
Traceback (most recent call last):
    ...
ValueError: No solution. (Inconsistent system)