2 matplotlib.use('Agg') # select backend that doesn't require X Windows
10 def d(a,b,x) : # know denominator
11 return (x, ((a**2 - x**2)**2 + (b*x)**2))
12 def rm(r, height) : # root marker
13 return ([r, r], float(height) * array([0.0001,1]))
14 def zr(a,b,p,q) : # p, q \in {-1,1}
15 return p*i*b/2.0 * (1 + q*sqrt(complex(1,0) - (2*a/b)**2))
16 def rp(a,b,p,q,h) : # plot root
17 (x,d) = rm(zr(a,b,p,q), h)
18 if x[0].imag == 0 and x[0] > 0 : plot(x,d,'-x')
19 print "Root at ", x[0]
20 def dr(a,b,x) : # attempt at factoring
21 return (x, (x-zr(a,b,+1,+1)) \
25 def testroots(a,b,x) :
30 print "For a = %g, b = %g" % (a, b)
31 rp(a,b,+1,+1, root_height)
32 rp(a,b,-1,+1, root_height*2)
33 rp(a,b,+1,-1, root_height*3)
34 rp(a,b,-1,-1, root_height*4)
35 title("For a = %g, b = %g" % (a, b))
43 title("For a = %g, b = %g" % (a, b))
49 # critically damped for b^2 = 4a^2
50 #for b in [0.1, 1, 2, 4, 6] :
53 x = linspace(0,4*a,N-1)
54 for b in linspace(a/10, 4*a, 5) :
57 x = linspace(0,4*a,N-1)
58 for b in linspace(a/10, 4*a, 5) :
61 x = linspace(0,4*a,N-1)
62 for b in linspace(a/10, 4*a, 5) :