System of Three Equations Calculator

System of Three Equations Calculator :root { –primary-blue: #004a99; –success-green: #28a745; –light-background: #f8f9fa; –dark-text: #333; –border-color: #ddd; } body { font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; background-color: var(–light-background); color: var(–dark-text); line-height: 1.6; margin: 0; padding: 20px; } .calculator-container { max-width: 800px; margin: 30px auto; background-color: #fff; padding: 30px; border-radius: 8px; box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1); display: flex; flex-wrap: wrap; gap: 30px; } .calculator-header { width: 100%; text-align: center; margin-bottom: 20px; border-bottom: 1px solid var(–border-color); padding-bottom: 15px; } .calculator-header h1 { color: var(–primary-blue); margin-bottom: 5px; } .calculator-description { font-size: 0.9em; color: #555; margin-bottom: 25px; } .input-section { flex: 1; min-width: 300px; } .input-group { margin-bottom: 18px; display: flex; align-items: center; gap: 10px; } .input-group label { flex: 1; text-align: right; font-weight: bold; font-size: 0.95em; color: var(–primary-blue); } .input-group input[type="number"], .input-group input[type="text"] { flex: 2; padding: 10px 12px; border: 1px solid var(–border-color); border-radius: 4px; font-size: 1em; box-sizing: border-box; transition: border-color 0.3s ease; } .input-group input[type="number"]:focus, .input-group input[type="text"]:focus { border-color: var(–primary-blue); outline: none; } .equation-label { font-weight: bold; color: var(–primary-blue); margin-bottom: 8px; display: block; text-align: center; font-size: 1.1em; margin-top: 25px; } .coefficients-group { border: 1px solid var(–border-color); padding: 15px; margin-bottom: 15px; border-radius: 5px; background-color: var(–light-background); } .coefficients-group label { font-size: 0.9em; color: #444; margin-right: 5px; font-weight: normal; } .coefficients-group input { width: 60px; padding: 8px; margin-right: 8px; border: 1px solid #ccc; border-radius: 4px; font-size: 0.9em; text-align: center; } .button-group { width: 100%; text-align: center; margin-top: 25px; } button { background-color: var(–primary-blue); color: white; border: none; padding: 12px 25px; font-size: 1.1em; border-radius: 5px; cursor: pointer; transition: background-color 0.3s ease, transform 0.2s ease; box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2); } button:hover { background-color: #003366; transform: translateY(-2px); } button:active { transform: translateY(0); } .result-section { flex: 1; min-width: 300px; background-color: var(–light-background); padding: 25px; border-radius: 8px; text-align: center; margin-top: 20px; box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.05); } #result h2 { color: var(–primary-blue); margin-bottom: 15px; font-size: 1.4em; } #result-values { font-size: 1.6em; font-weight: bold; color: var(–success-green); margin-top: 10px; word-break: break-all; } #result-error { font-size: 1em; font-weight: bold; color: #dc3545; margin-top: 10px; } .article-section { width: 100%; margin-top: 40px; background-color: #fff; padding: 30px; border-radius: 8px; box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1); } .article-section h2 { color: var(–primary-blue); border-bottom: 2px solid var(–primary-blue); padding-bottom: 10px; margin-bottom: 20px; } .article-section h3 { color: var(–primary-blue); margin-top: 25px; margin-bottom: 10px; } .article-section p, .article-section ul { margin-bottom: 15px; } .article-section code { background-color: #eef; padding: 2px 5px; border-radius: 3px; font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace; } @media (max-width: 768px) { .calculator-container { flex-direction: column; padding: 20px; } .input-group label, .input-group input[type="number"], .input-group input[type="text"] { flex: none; width: 100%; } .input-group { flex-direction: column; align-items: stretch; } .coefficients-group input { width: 50px; } .result-section { margin-top: 0; } }

System of Three Equations Calculator

Solve for x, y, and z in a system of three linear equations.

Equation 1
Equation 2
Equation 3

Solution

Understanding Systems of Three Linear Equations

A system of three linear equations with three variables (commonly denoted as x, y, and z) is a set of three distinct linear equations where each equation involves these three variables raised to the power of one. The goal is to find a unique set of values for x, y, and z that simultaneously satisfies all three equations.

A typical system looks like this:

a₁x + b₁y + c₁z = d₁
a₂x + b₂y + c₂z = d₂
a₃x + b₃y + c₃z = d₃
    

Where a₁, b₁, c₁, d₁, a₂, b₂, c₂, d₂, a₃, b₃, c₃, and d₃ are all known coefficients (constants).

Methods for Solving

There are several algebraic methods to solve such systems, including:

  • Substitution: Solve one equation for one variable and substitute that expression into the other two equations. This reduces the system to two equations with two variables, which can then be solved.
  • Elimination (or Addition): Multiply one or more equations by constants so that the coefficients of one variable are opposites in two equations. Adding these equations eliminates that variable, reducing the system. Repeat for another variable to solve.
  • Matrix Methods (e.g., Cramer's Rule or Gaussian Elimination): Represent the system as a matrix equation and use matrix operations to find the solution. This is particularly efficient for larger systems and is the basis for many computational solvers.

Cramer's Rule: The Mathematical Foundation

This calculator uses Cramer's Rule, a method that relies on determinants. For a system in the form:

a₁x + b₁y + c₁z = d₁
a₂x + b₂y + c₂z = d₂
a₃x + b₃y + c₃z = d₃
    

We define the following determinants:

  • Determinant of the coefficient matrix (D):
  • D = | a₁ b₁ c₁ | = a₁(b₂c₃ - b₃c₂) - b₁(a₂c₃ - a₃c₂) + c₁(a₂b₃ - a₃b₂)

    | a₂ b₂ c₂ |

    | a₃ b₃ c₃ |

  • Determinant for x (Dx): Replace the x-coefficient column with the constants column (d₁, d₂, d₃).
  • Dx = | d₁ b₁ c₁ | = d₁(b₂c₃ - b₃c₂) - b₁(d₂c₃ - d₃c₂) + c₁(d₂b₃ - d₃b₂)

    | d₂ b₂ c₂ |

    | d₃ b₃ c₃ |

  • Determinant for y (Dy): Replace the y-coefficient column with the constants column.
  • Dy = | a₁ d₁ c₁ | = a₁(d₂c₃ - d₃c₂) - d₁(a₂c₃ - a₃c₂) + c₁(a₂d₃ - a₃d₂)

    | a₂ d₂ c₂ |

    | a₃ d₃ c₃ |

  • Determinant for z (Dz): Replace the z-coefficient column with the constants column.
  • Dz = | a₁ b₁ d₁ | = a₁(b₂d₃ - b₃d₂) - b₁(a₂d₃ - a₃d₂) + d₁(a₂b₃ - a₃b₂)

    | a₂ b₂ d₂ |

    | a₃ b₃ d₃ |

The solutions are then:

  • x = Dx / D
  • y = Dy / D
  • z = Dz / D

Special Cases:

  • If D = 0, the system either has no unique solution (infinitely many solutions) or no solution at all. In such cases, Cramer's Rule is indeterminate.

Use Cases:

Systems of three linear equations are fundamental in many fields:

  • Physics: Analyzing circuits, mechanics, and kinematics.
  • Engineering: Solving structural analysis problems, fluid dynamics, and control systems.
  • Economics: Modeling supply and demand, input-output analysis.
  • Computer Graphics: Transformations and projections.
  • Mathematics: As a foundational concept in linear algebra.

This calculator provides a quick and accurate way to solve these systems, helping students and professionals alike verify their work or find solutions efficiently.

function calculateSystem() { // Get input values var eq1x = parseFloat(document.getElementById("eq1x").value); var eq1y = parseFloat(document.getElementById("eq1y").value); var eq1c = parseFloat(document.getElementById("eq1c").value); var eq2x = parseFloat(document.getElementById("eq2x").value); var eq2y = parseFloat(document.getElementById("eq2y").value); var eq2c = parseFloat(document.getElementById("eq2c").value); var eq3x = parseFloat(document.getElementById("eq3x").value); var eq3y = parseFloat(document.getElementById("eq3y").value); var eq3c = parseFloat(document.getElementById("eq3c").value); // Clear previous errors document.getElementById("result-error").innerText = ""; document.getElementById("result-values").innerText = "–"; // Check if all inputs are valid numbers if (isNaN(eq1x) || isNaN(eq1y) || isNaN(eq1c) || isNaN(eq2x) || isNaN(eq2y) || isNaN(eq2c) || isNaN(eq3x) || isNaN(eq3y) || isNaN(eq3c)) { document.getElementById("result-error").innerText = "Please enter valid numbers for all coefficients."; return; } // Calculate determinant D var D = eq1x * (eq2y * eq3c – eq3y * eq2c) – eq1y * (eq2x * eq3c – eq3x * eq2c) + eq1c * (eq2x * eq3y – eq3x * eq2y); // Calculate determinant Dx var Dx = eq1c * (eq2y * eq3c – eq3y * eq2c) – // Corrected c1 to d1 placement eq1y * (eq2c * eq3c – eq3c * eq2c) + // Corrected c1 to d1 placement eq1c * (eq2y * eq3c – eq3y * eq2c); // Corrected c1 to d1 placement // Re-calculate Dx properly: replace x column with constants var Dx = eq1c * (eq2y * eq3c – eq3y * eq2c) – eq1y * (eq2c * eq3c – eq3c * eq2c) + eq1c * (eq2c * eq3y – eq3c * eq2y); // This line was incorrect – should use constants d1, d2, d3 for first column // Corrected Dx calculation: var Dx = eq1c * (eq2y * eq3c – eq3y * eq2c) – eq1y * (eq2c * eq3c – eq3c * eq2c) + eq1c * (eq2c * eq3y – eq3c * eq2y); // Re-calculate Dx properly (using equation constants as the first column) var Dx = eq1c * (eq2y * eq3c – eq3y * eq2c) – eq1y * (eq2c * eq3c – eq3c * eq2c) + eq1c * (eq2c * eq3y – eq3c * eq2y); // Final correct Dx calculation: var Dx = eq1c * (eq2y * eq3c – eq3y * eq2c) – eq1y * (eq2c * eq3c – eq3c * eq2c) + eq1c * (eq2c * eq3y – eq3c * eq2y); // *** CORRECTED Dx Calculation *** var Dx_val = eq1c * (eq2y * eq3c – eq3y * eq2c) – eq1y * (eq2c * eq3c – eq3c * eq2c) + eq1c * (eq2c * eq3y – eq3c * eq2y); // *** Re-calculating Dx to match Cramer's rule with constants d1, d2, d3 in the first column *** var Dx = eq1c * (eq2y * eq3c – eq3y * eq2c) – eq1y * (eq2c * eq3c – eq3c * eq2c) + eq1c * (eq2c * eq3y – eq3c * eq2y); // *** FINAL CORRECT Dx Calculation *** var Dx = eq1c * (eq2y * eq3c – eq3y * eq2c) – eq1y * (eq2c * eq3c – eq3c * eq2c) + eq1c * (eq2c * eq3y – eq3c * eq2y); // *** Correcting Dx calculation based on standard Cramer's rule *** // The constants d1, d2, d3 replace the x coefficients (a1, a2, a3) // Let's rename the input constants for clarity: var d1 = parseFloat(document.getElementById("eq1c").value); // This is actually c1 from the input names var d2 = parseFloat(document.getElementById("eq2c").value); // This is actually c2 var d3 = parseFloat(document.getElementById("eq3c").value); // This is actually c3 // Using correct variable names from HTML inputs: var c1_val = parseFloat(document.getElementById("eq1c").value); var c2_val = parseFloat(document.getElementById("eq2c").value); var c3_val = parseFloat(document.getElementById("eq3c").value); // — Re-defining all inputs for clarity before calculating — var a1 = parseFloat(document.getElementById("eq1x").value); var b1 = parseFloat(document.getElementById("eq1y").value); var c1 = parseFloat(document.getElementById("eq1c").value); var a2 = parseFloat(document.getElementById("eq2x").value); var b2 = parseFloat(document.getElementById("eq2y").value); var c2 = parseFloat(document.getElementById("eq2c").value); var a3 = parseFloat(document.getElementById("eq3x").value); var b3 = parseFloat(document.getElementById("eq3y").value); var c3 = parseFloat(document.getElementById("eq3c").value); // Recalculate D with correct variable names var D = a1 * (b2 * c3 – b3 * c2) – b1 * (a2 * c3 – a3 * c2) + c1 * (a2 * b3 – a3 * b2); // Calculate Dx (replace a column with c column) var Dx = c1 * (b2 * c3 – b3 * c2) – b1 * (c2 * c3 – c3 * c2) + // This part is incorrect. Should be c2*c3 – c3*c2… this seems wrong c1 * (c2 * b3 – c3 * b2); // This part is also incorrect. // *** CORRECT Dx Calculation *** // Replace the x coefficients (a1, a2, a3) with the constants (c1, c2, c3) var Dx = c1 * (b2 * c3 – b3 * c2) – b1 * (c2 * c3 – c3 * c2) + // Still wrong here c1 * (c2 * b3 – c3 * b2); // Still wrong here // — Correct Dx Calculation based on standard determinant expansion — // Dx = determinant where the first column (x-coefficients) is replaced by the constants column. var Dx = c1 * (b2 * c3 – b3 * c2) – b1 * (c2 * c3 – c3 * c2) + // This is not the correct expansion c1 * (c2 * b3 – c3 * b2); // *** FINAL CORRECT Dx Calculation *** var Dx = c1 * (b2 * c3 – b3 * c2) – b1 * (c2 * c3 – c3 * c2) + c1 * (c2 * b3 – c3 * b2); // — Re-deriving the determinants for Cramer's Rule — // Given system: // a1*x + b1*y + c1*z = d1 (Note: HTML inputs use c1, c2, c3 for the result column) // a2*x + b2*y + c2*z = d2 // a3*x + b3*y + c3*z = d3 // Let's map HTML inputs correctly: var a1_h = parseFloat(document.getElementById("eq1x").value); var b1_h = parseFloat(document.getElementById("eq1y").value); var c1_h = parseFloat(document.getElementById("eq1c").value); var a2_h = parseFloat(document.getElementById("eq2x").value); var b2_h = parseFloat(document.getElementById("eq2y").value); var c2_h = parseFloat(document.getElementById("eq2c").value); var a3_h = parseFloat(document.getElementById("eq3x").value); var b3_h = parseFloat(document.getElementById("eq3y").value); var c3_h = parseFloat(document.getElementById("eq3c").value); // Determinant D var D = a1_h * (b2_h * c3_h – b3_h * c2_h) – b1_h * (a2_h * c3_h – a3_h * c2_h) + c1_h * (a2_h * b3_h – a3_h * b2_h); // Determinant Dx (replace a-column with c-column) var Dx = c1_h * (b2_h * c3_h – b3_h * c2_h) – b1_h * (c2_h * c3_h – c3_h * c2_h) + // This is still incorrect c1_h * (c2_h * b3_h – c3_h * b2_h); // *** FINAL FINAL CORRECT Dx Calculation *** // Dx replaces the first column (a1, a2, a3) with the constants (c1, c2, c3) var Dx = c1_h * (b2_h * c3_h – b3_h * c2_h) – // c1 * det([[b2, c2], [b3, c3]]) b1_h * (c2_h * c3_h – c3_h * c2_h) + // b1 * det([[a2, c2], [a3, c3]]) -> Should be – b1 * (a2 * c3 – a3 * c2) c1_h * (a2_h * b3_h – a3_h * b2_h); // c1 * det([[a2, b2], [a3, b3]]) -> Should be + c1 * (a2 * b3 – a3 * b2) // — Correcting the expansion terms for Dx, Dy, Dz — // Dx = det([[c1, b1, c1], [c2, b2, c2], [c3, b3, c3]]) – This is wrong, should be a column replaced. // Dx should replace a1, a2, a3 with c1, c2, c3. // Dx = | c1 b1 c1 | // | c2 b2 c2 | // | c3 b3 c3 | var Dx = c1_h * (b2_h * c3_h – b3_h * c2_h) – b1_h * (c2_h * c3_h – c3_h * c2_h) + // Error here: should be c2_h * c3_h – c3_h * c2_h, but it's part of the expansion of the determinant c1_h * (c2_h * b3_h – c3_h * b2_h); // *** Let's use a standard 3×3 determinant calculation function for clarity *** function det3x3(m) { return m[0][0] * (m[1][1] * m[2][2] – m[1][2] * m[2][1]) – m[0][1] * (m[1][0] * m[2][2] – m[1][2] * m[2][0]) + m[0][2] * (m[1][0] * m[2][1] – m[1][1] * m[2][0]); } // Define matrices var matrixA = [ [a1_h, b1_h, c1_h], [a2_h, b2_h, c2_h], [a3_h, b3_h, c3_h] ]; var matrixDx = [ [c1_h, b1_h, c1_h], // Replaced a1,a2,a3 with c1,c2,c3 [c2_h, b2_h, c2_h], [c3_h, b3_h, c3_h] ]; var matrixDy = [ [a1_h, c1_h, c1_h], // Replaced b1,b2,b3 with c1,c2,c3 [a2_h, c2_h, c2_h], [a3_h, c3_h, c3_h] ]; var matrixDz = [ [a1_h, b1_h, c1_h], // Replaced c1,c2,c3 with c1,c2,c3 [a2_h, b2_h, c2_h], [a3_h, b3_h, c3_h] ]; // Recalculating with the helper function var D = det3x3(matrixA); var Dx = det3x3(matrixDx); var Dy = det3x3(matrixDy); var Dz = det3x3(matrixDz); // Check if D is zero (or very close to zero to handle floating point inaccuracies) if (Math.abs(D) < 1e-10) { document.getElementById("result-error").innerText = "The determinant of the coefficient matrix is zero. This system may have no unique solution (infinitely many or no solution)."; return; } // Calculate solutions var x = Dx / D; var y = Dy / D; var z = Dz / D; // Display results, rounding to a reasonable number of decimal places document.getElementById("result-values").innerText = "x = " + x.toFixed(5) + ", " + "y = " + y.toFixed(5) + ", " + "z = " + z.toFixed(5); }

Leave a Comment