Lets say you have three equations with 3 unknowns:
- x + y + z = -5
- x -4y + z = 35
- x – 3y + 4z = -18
Using Cramer’s rule we can solve each unknown, x, y, z without having to solve each equation. We first have to deduce the coefficient matrix determinate. We can find the by looking at the number in front of the x, y, and z value. The first equation is the first column in the matrix. Eg. x + y + z is 1 1 1.
This is the coefficient matrix determinate.
Important to now. If the determinate of D = 0, then Cramer’s Rule can not be used.
The answer column is simple the value on the right of each linear equation.
We need to find the coefficient determinates Dx, Dy, and Dz. They are simply the coefficient matrix determinate with the answer column replacing values in the x, y or z depending on the determinate. E.g Dx has it’s x column replaced with the answer column.
How to find the determinate of a matrix:
Using the + – + rule for the expansion of a matrix you can solve for the determinate of a valid matrix. What i mean by the rule for expansion is that the first number will have a + the second a – and the third a +. Lets say we want to solve the coefficient matrix determinate giving above. We first look at the x column. Ie. 1, 1, 1 we give each of these numbers a sign based on the expansion rule +-+. So 1, 1, 1 is now +1, -1, +1. The three, 2×2 matrices seen below are deduced by looking at 2 rows and 2 columns. What rows and columns depend on the component. So for the x component. We look at the y & z columns and y & z rows. That gives us -4 1 over -3 1.
When multiply out the matrices it is important to keep note of the signs. As guided in the solution below.
The answer is then simply giving by multiplying out.
To solve for each component x, y & z. It is giving by:
The Data:
“If you don’t understand the data, you don’t understand the problem” – Mike Acton.
I written down the representation of the data in my programming notebook. Each number is stored in a array of 12 elements. It is important to remember when calculating Dx for example you access the correct elements for the calculations.
int matrix_Dx[9]{ matrix[3], matrix[1] , matrix[2], matrix[7] , matrix[5] , matrix[6] , matrix[11] , matrix[9] , matrix[10] }; int deter_Dx = determinateOfMatrix(matrix_Dx);
C++ source code for using Cramer’s Rule is available on my GitHub. Here is a link to the repository: Cramers-Rule
I’m enjoying these posts a lot, keep up the work and someone is bound to notice 🙂
Thank you Dan, i really hope so.
Hello, can you give 4×4 cramers rule source code? I badly neeed it. thank you 🙂