mdbtxt1
mdbtxt2
Proceed to Safety

Solving a System of 2 Equations in 2 Unknowns    

Robert P. Munafo, 2023 Feb 19



This is a basic algebra technique generally taught in secondary school as part of the algebra curriculum. It is a specific case of a general method for solving any system of linear equations.

Given a set of two equations in two unknowns:

ax + by = c          (1)
dx + ey = f          (2)

One may first express x in terms of y by rearranging one of the equations, e.g. the first:

x = (c - by)/a          (3)

then substitute the right side of (3) for x in the equation (2):

d(c-by)/a + ey = f          (4)

rearanging and solving for y:

ey - dby/a = f-dc/a          (5)
y = (f-dc/a)/(e-db/a)          (6)

then finally substitute the right side of (5) for y in equation (3) to get the answer for x.

Program

The following program sets up an example and prints the calculations as it goes; you can use the example values to verify that your implementation is working.

   // Solve a system of two equations in two unknowns // a x + b y = c // d x + e y = f // Given the values of (a, b, c, d, e, f) determine the values of x and y    // Example values for the equations: -3x+2y=33 ; x+y=34 a = -3 b = 2 c = 33 d = 1 e = 1 f = 34    // Solve for y t1 = f-d*c/a print t1 // should print 45 t2 = e-d*b/a print t2 // should print 5/3 or approx. 1.666667 y = t1/t2 print y // should print 2 // Solve for x x = (c - b*y)/a print x // should print 7   




From the Mandelbrot Set Glossary and Encyclopedia, by Robert Munafo, (c) 1987-2024.

Mu-ency main pageindexrecent changesDEMZ


Robert Munafo's home pages on AWS    © 1996-2024 Robert P. Munafo.    about    contact
This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License. Details here.

This page was written in the "embarrassingly readable" markup language RHTF, and was last updated on 2023 Feb 19. s.27