Add a PyMOL builder to SCons and generalize PYMOL_PATH setup.
[thesis.git] / src / cantilever-calib / test / locate_roots.py
1 import matplotlib
2 matplotlib.use('Agg') # select backend that doesn't require X Windows
3 from pylab import *
4 from numpy import *
5
6 N=100
7 root_height = 1
8 i = complex(0,1)
9
10 def zr(a,b,p,q) : # p, q \in {-1,1}
11     return p*i*b/2.0 * (1 + q*sqrt(complex(1,0) - (2*a/b)**2))
12 def zrc(c,b,p,q) : # p, q \in {-1,1}
13     return p*i*b/2.0 * (1 + q*sqrt(complex(1,0) - (2*c)**2))
14 def loc_roots(c,b) :
15     figure()
16     subplot(311)
17     hold(True)
18     dpp = zrc(c,b,+1,+1)
19     dmp = zrc(c,b,-1,+1)
20     dpm = zrc(c,b,+1,-1)
21     dmm = zrc(c,b,-1,-1)
22     plot(dpp.real,dpp.imag,'ro', label="++")
23     plot(dmp.real,dmp.imag,'b+', label="-+")
24     plot(dpm.real,dpm.imag,'gx', label="+-")
25     plot(dmm.real,dmm.imag,'k.', label="--")
26     title('plane')
27     legend(loc='upper right')
28     subplot(312)
29     plot(c, dpp.real,'ro',
30          c, dmp.real,'b+',
31          c, dpm.real,'gx',
32          c, dmm.real,'k.')
33     title('real')
34     subplot(313)
35     plot(c, dpp.imag,'ro',
36          c, dmp.imag,'b+',
37          c, dpm.imag,'gx',
38          c, dmm.imag,'k.')
39     title('imag')
40
41 ioff()
42
43 # critically damped for b^2 = 4a^2
44 # so for c = a/b = 0.5
45 #for b in [0.1, 1, 2, 4, 6] :
46 #    testroots(a,b,x)
47 c = linspace(0,4,N-1)
48 loc_roots(c,1)
49
50         FIGURE.savefig("figure.png")
51 show()