Skip to content

Instantly share code, notes, and snippets.

@kharioki
Created October 13, 2016 08:37
Show Gist options
  • Save kharioki/81928ea3e6f0ea17ed5567ccceadb7ba to your computer and use it in GitHub Desktop.
Save kharioki/81928ea3e6f0ea17ed5567ccceadb7ba to your computer and use it in GitHub Desktop.
def simultaneous_eqn(eqns):
a = eqns[0]
b = eqns[1]
c = eqns[2]
x = float((-b - c) / a)
return x
def two_unknown(eqns):
x1 = eqns[0][0]
y1 = eqns[0][1]
c1 = eqns[0][2]
c1 = -c1
x2 = eqns[1][0]
y2 = eqns[1][1]
c2 = eqns[1][2]
c2 = -c2
det = (x1 * y2) - (x2 * y1)
det_x = (c1 * y2) - (c2 *y1)
det_y = (x1 * c2) - (x2 * c1)
x = float(det_x / det)
y = float(det_y / det)
return [x, y]
def system_of_eqns(unknown, eqns):
if unknown == 1:
print(simultaneous_eqn(eqns))
elif unknown == 2:
print(two_unknown(eqns))
unknown = 2
eqns = [[1, -3, 2], [2, 5, 4]]
print(system_of_eqns(unknown, eqns))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment