Skip to content

Instantly share code, notes, and snippets.

@felclef
Created Oct 4, 2011
Embed
What would you like to do?
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