Skip to content

Instantly share code, notes, and snippets.

@JuliusNM
Last active October 12, 2016 20:44
Show Gist options
  • Save JuliusNM/095ac9b9b23dd0a3f7ca66b14c6f43b7 to your computer and use it in GitHub Desktop.
Save JuliusNM/095ac9b9b23dd0a3f7ca66b14c6f43b7 to your computer and use it in GitHub Desktop.
Quadratic Equation Solver, Simultaneous Equation Solver, Meeting organizer
#Julius and Mercy Quadratic Equation Solver
#Implementation of the formula x= (-b+- (b**2-4ac)**2)/2a
def quad_values(a,b,c)
a = a.to_f
b = b.to_f
c = c.to_f
d = (b**2) - (4*a*c)
if d >= 0
d = Math.sqrt(d)
x1 = (-b + d)/(2*a)
x2 = (-b - d)/(2*a)
print(x1.to_s + ',' + x2.to_s)
else
print('the roots are not real numbers')
end
end
quad_values(2,3,1)
import numpy as np
def equation(eq,arr):
if eq == 2:
a,d = arr[0][0], arr[1][0]
b,e = arr[0][1], arr[1][1]
c,f = arr[0][2], arr[1][2]
J = np.array([[a,b],[d,e]])
b = np.array([c,f])
n = np.linalg.solve(J,b)
return n
elif eq == 1:
x = arr[0]
y = arr[1]
z = arr[2]
A = (z-(y))/x
return A
else:
print 'cant handle this'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment