2次方程式の解

2019/01/15

def quadratic_equation(a,b,c):
    d = b*b-4*a*c
    if d < 0:
        return []
    if d == 0:
        x = -b/(2.0*a)
        return [x]
    else:
        x0 = (-b+d**0.5)/(2.0*a)
        x1 = (-b-d**0.5)/(2.0*a)
    return [x0,x1]

if __name__ == '__main__':
    print(quadratic_equation(2,3,-5))


二次方程式の解の公式
http://www.geisya.or.jp/~mwm48961/kou3/quad_eq2.htm