18.3: Using Cramer’s rule to solve Ax=b
- Page ID
- 67884
Let \(Ax=b\) be a system of \(n\) linear equations in \(n\) variables such that \(|A| \neq 0\). The system has a unique solution given by:
\[x_1 = \frac{|A_1|}{|A|}, x_2 = \frac{|A_2|}{|A|}, \ldots, x_n = \frac{|A_n|}{|A|} \nonumber \]
where \(A_i\) is the matrix obtained by replacing column \(i\) of \(A\) with \(b\). The following function generates \(A_i\) by replacing the \(i\)th column of \(A\) with \(b\):
Create a new function called cramersRule
, which takes \(A\) and \(b\) and returns \(x\) using the Cramer’s rule.
Note: Use numpy
and NOT mydet
to find the required determinants. mydet
is too slow.
Test your cramersRule
function on the following system of linear equations:
\[ x_1 + 2x_2 = 3 \nonumber \]
\[3x_1 + x_2 = -1 \nonumber \]
Verify the above answer by using the np.linalg.solve
function:
Test your cramersRule
function on the following system of linear equations and verify the answer by using the np.linalg.solve
function:
\[ x_1 + 2x_2 +x_3 = 9 \nonumber \]
\[ x_1 + 3x_2 - x_3 = 4 \nonumber \]
\[ x_1 + 4x_2 - x_3 = 7 \nonumber \]
Cramer’s rule is a \(O(n!)\) algorithm and the Gauss-Jordan (or Gaussian) elimination is \(O(n^3)\). What advantages does Cramer’s rule have over elimination?