Why This Matters
One equation with one unknown gives you a single answer. But many real problems have multiple unknowns. If you buy apples and oranges and know the total cost and the total number of items, you need two equations to figure out how many of each you bought. A system of equations is a set of equations that must all be true at the same time, and solving the system means finding values that satisfy every equation simultaneously.
There are two main strategies. The substitution method solves one equation for one variable, then plugs that expression into the other equation. The elimination method adds or subtracts the equations to cancel out one variable entirely. Both approaches reduce a two- variable problem to a single-variable problem you already know how to solve.
Systems of equations are the mathematical backbone of everything from physics simulations to economics models to machine learning. Any time you have multiple constraints and multiple unknowns, you are solving a system. In code, this translates to matrix operations, optimization routines, and constraint solvers that power modern applications.
Define Terms
Visual Model
The full process at a glance. Click Start tour to walk through each step.
Elimination cancels one variable by combining equations; substitution replaces one variable with an expression.
Code Example
// Solve 2x2 system using elimination
// a1*x + b1*y = c1
// a2*x + b2*y = c2
function solveSystem(a1, b1, c1, a2, b2, c2) {
const det = a1 * b2 - a2 * b1;
if (det === 0) {
return "no unique solution (parallel or same line)";
}
const x = (c1 * b2 - c2 * b1) / det;
const y = (a1 * c2 - a2 * c1) / det;
return { x, y };
}
// 2x + y = 10, x - y = 2
const sol1 = solveSystem(2, 1, 10, 1, -1, 2);
console.log("System 1:", sol1); // { x: 4, y: 2 }
// 3x + 2y = 12, x - y = 1
const sol2 = solveSystem(3, 2, 12, 1, -1, 1);
console.log("System 2:", sol2); // { x: 2.8, y: 1.8 }
// Parallel lines: x + y = 1, x + y = 3
const sol3 = solveSystem(1, 1, 1, 1, 1, 3);
console.log("Parallel:", sol3); // no unique solution
// Step-by-step elimination
function eliminationSteps(a1, b1, c1, a2, b2, c2) {
console.log(`Eq1: ${a1}x + ${b1}y = ${c1}`);
console.log(`Eq2: ${a2}x + ${b2}y = ${c2}`);
// Multiply eq1 by b2, eq2 by b1 to match y coefficients
const m1 = b2, m2 = b1;
console.log(`Multiply Eq1 by ${m1}: ${a1*m1}x + ${b1*m1}y = ${c1*m1}`);
console.log(`Multiply Eq2 by ${m2}: ${a2*m2}x + ${b2*m2}y = ${c2*m2}`);
const newA = a1 * m1 - a2 * m2;
const newC = c1 * m1 - c2 * m2;
console.log(`Subtract: ${newA}x = ${newC}`);
console.log(`x = ${newC / newA}`);
}
eliminationSteps(2, 1, 10, 1, -1, 2);Interactive Experiment
Try these exercises:
- Solve the system x + y = 5 and x - y = 1 by hand using elimination. Verify with the code.
- Try substitution on the same system: solve the first equation for y, plug into the second.
- Create a system with no solution (parallel lines). What does the determinant equal?
- Create a system where both equations describe the same line. How many solutions exist?
- Solve 3x + 4y = 25 and 2x - y = 1. Which method feels easier for this one?
Quick Quiz
Coding Challenge
Write a function called `solveSystem` that takes six numbers: a1, b1, c1, a2, b2, c2 representing the system a1*x + b1*y = c1 and a2*x + b2*y = c2. Return an array [x, y] with the solution. Use the elimination method: compute the determinant (a1*b2 - a2*b1), then x = (c1*b2 - c2*b1) / det and y = (a1*c2 - a2*c1) / det. You may assume the determinant is never 0.
Real-World Usage
Systems of equations power multi-variable problem solving:
- Economics: Supply and demand curves intersect at equilibrium price and quantity -- a two-equation, two-unknown system.
- Computer graphics: Ray-plane intersection requires solving a system to find where a ray hits a surface.
- Circuit analysis: Kirchhoff laws produce systems of equations for current and voltage in each branch.
- Machine learning: Linear regression with multiple features solves a system (often via matrices) to find the best-fit weights.
- Navigation: GPS triangulation solves a system of distance equations to pinpoint a location from satellite signals.