Purpose: To use Cramer's Rule to solve a system of two equations and two unknowns. This program does not, however, introduce any new programming commands.
Because Cramer's Rule only uses formulas for the determinants of a 2 X 2 matrices, no new programming commands will be needed here. Of course, just as when the problem is being worked on paper, the system must first be tested to see if it has one solution.
When does a system have no solutions? When does a system have infinitely many solutions?
Consider the system Ax+By = C and Dx+Ey = F. The first step is to prompt the user for A, B, C, D, E, and F. Make sure the equations are in standard form. To see if there is zero or multiple solutions, test to see if the determinant of the following matrix equals zero. Use an "If" statement. Does AE-BD = 0? Print an output message to the user if it does. Store the value of AE-BD because we will need it later, I chose to store it as M.
|
|
|
|
Otherwise, solve the system using Cramer's Rule.
Determine expressions for the determinants of the following 2 X 2 matrices.
C |
|
|
|
|
|
|
|
Use those to evaluate the solution (x,y).
x=(determinant 1)/M
y=(determinant 2)/M
Output the solution to the user.
For code, click here.