# -*- coding: iso-8859-1 -*- # mk, 26.8.08 from math import sqrt def quadglei(a,b,c): """ Rückgabe: [Anzahl der Lösungen, Lösungen], [3]=unendl. >>> quadglei(0,0,0) [3] >>> quadglei(0,0,1) [0] >>> quadglei(0,1,2) [1, -2.0] >>> quadglei(7,7,-84) [2, -4.0, 3.0] >>> quadglei(1,2,-3) [2, -3.0, 1.0] >>> quadglei(10,1,0.025) [1, -0.050000000000000003] >>> (abs(quadglei(10,1,0.025)[1]--0.05)<1e-10) True >>> quadglei(10,1,1) [0] """ if a==0: if b==0: if c==0: return [3] else: return [0] else: x = float(-c)/b return [1,x] else: d = b*b-4*a*c if d>0: wd = sqrt(d) x1 = (-b-wd)/float(2*a) x2 = (-b+wd)/float(2*a) return [2,x1,x2] else: if d==0: x = -b/float(2*a) return [1,x] else: return [0] if __name__ == "__main__": import doctest doctest.testmod(verbose=True)