Skip to content

Instantly share code, notes, and snippets.

@felclef
Created October 4, 2011 19:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save felclef/1262465 to your computer and use it in GitHub Desktop.
Save felclef/1262465 to your computer and use it in GitHub Desktop.
Uma brincadeira com bhask-sei-lá-quem-indiano e as equações de 2o grau, pra explicar python prum amigo aí ;D
# a * x**2 + b * x + c = 0, a != 0
# (-b +- sqrt(d) ) / 2 * a
# d = b**2 - 4 * a * c
from math import sqrt
#print 3 ** 2
#print sqrt(9)
def get_d(a, b, c):
return ( b ** 2 ) - ( 4 * a * c )
def get_bsk(a, b, d):
return [ ( -b + sqrt(d) ) / ( 2 * a ), ( -b - sqrt(d) ) / ( 2 * a ) ]
def solve_eq(a, b, c):
d = get_d(a, b, c)
print "[x, x'] = ", get_bsk(a, b, d)
a = 1
b = -4
c = 3
solve_eq(a, b, c)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment