![]() |
VOOZH | about |
Cramer's rule: In linear algebra, Cramer's rule is an explicit formula for the solution of a system of linear equations with as many equations as unknown variables. It expresses the solution in terms of the determinants of the coefficient matrix and of matrices obtained from it by replacing one column by the column vector of the right-hand-sides of the equations. Cramer's rule is computationally inefficient for systems of more than two or three equations.
Suppose we have to solve these equations:
a1x + b1y + c1z = d1
a2x + b2y + c2z = d2
a3x + b3y + c3z = d3
Following the Cramer's Rule, first find the determinant values of all four matrices.
There are 2 cases:
- Case I : When D ≠ 0 In this case we have,
- x = D1/D
- y = D2/D
- z = D3/D
- Hence unique value of x, y, z will be obtained.
- Case II : When D = 0
- When at least one of D1, D2 and D3 is non zero: Then no solution is possible and hence system of equations will be inconsistent.
- When D = 0 and D1 = D2 = D3 = 0: Then the system of equations will be consistent and it will have infinitely many solutions.
Example:
Consider the following system of linear equations.
[2x - y + 3z = 9], [x + y + z = 6], [x - y + z = 2][x = D1/D = 1], [y = D2/D = 2], [z = D3/D = 3]
Below is the implementation.
D is : -2.000000 D1 is : -2.000000 D2 is : -4.000000 D3 is : -6.000000 Value of x is : 1.000000 Value of y is : 2.000000 Value of z is : 3.000000
Time complexity: O(1)
Auxiliary space: O(1)