Solve two linear equations for the general case.

Given:

Equation 1: ax + by = c
Equation 2: dx + ey = f

Solve Equation 2 for y

dx + ey = f
ey = f-dx
y = (f-dx)/e

Replace the y in Equation 1 with (f-dx)/e then solve for x

ax + by = c
ax + b(f-dx)/e = c 
ax + (b/e)(f-dx) = c
ax + bf/e -bdx/e = c
ax - bdx/e = c - bf/e
ax - (bd/e)x = c - bf/e
(a-bd/e)x = c - bf/e
(ae/e - bd/e)x = (ce/e - bf/e)
((ae-bd)/e)x = (ce-bf)/e
(ae-bd)x = (ce-bf)
x = (ce-bf)/(ae-bd)



Solve Equation 2 for x

dx + ey = f
dx = f - ey
x = (f-ey)/d

Replace the x in equation 1 with (f-ey)/d then solve for y

ax + by = c
a(f-ey)/d + by = c
(a/d)(f-ey) + by = c
af/d - aey/d + by = c
by - aey/d + af/d = c
by - aey/d = c - af/d
(b-ae/d)y = c - af/d
(bd/d - ae/d)y = (cd/d - af/d)
((bd-ae)/d)y = (cd-af)/d
(bd-ae)y = (cd-af)
y = (cd-af)/(bd-ae)

Therefore the general case solution for two linear equations is:

x = (ce-bf)/(ae-bd)
y = (cd-af)/(bd-ae)