dzs commited on
Commit
b2fee3f
·
1 Parent(s): dfad619

changed cython root finder to brent q, but changed from tan to cos and sin

Browse files
Files changed (1) hide show
  1. transportEqs.py +21 -12
transportEqs.py CHANGED
@@ -20,24 +20,33 @@ def SolubilityLimited(beta, tau, nmax=100):
20
  # finite bath model functions
21
  from fast_bisect import cbisect
22
 
 
 
23
  def PlaneSheetFiniteBathMassC(tau, alpha, nterms):
24
- Minfty = 1. / (1. + 1. / (alpha))
25
 
26
- qn = zeros((nterms))
 
 
 
27
  for j in range(nterms):
28
- solved = False
29
- eps = 1e-8
30
- f = lambda x: tan(x) + alpha * x
31
- myargs = {'alpha': alpha}
32
- rts = cbisect(a=pi / 2. + j * pi + eps, b=pi * (1. + j) - eps, args=myargs)
33
- # print(rts)
34
- solved = True
35
- qn[j] = rts
36
 
37
  result = 1.
 
38
  for j in range(nterms):
39
- result = result - (2. * alpha * (1. + alpha)) * exp(-tau * qn[j] ** 2.) / (
40
- 1. + alpha + alpha ** 2. * qn[j] ** 2.)
 
 
 
 
41
  result = Minfty * result
42
 
43
  return result
 
20
  # finite bath model functions
21
  from fast_bisect import cbisect
22
 
23
+ from scipy.optimize import brentq
24
+
25
  def PlaneSheetFiniteBathMassC(tau, alpha, nterms):
 
26
 
27
+ Minfty = 1. / (1. + 1. / alpha)
28
+
29
+ qn = zeros(nterms)
30
+
31
  for j in range(nterms):
32
+
33
+ a = pi / 2. + j * pi
34
+ b = pi * (1. + j)
35
+
36
+ def f(x):
37
+ return sin(x) + alpha * x * cos(x)
38
+
39
+ qn[j] = brentq(f, a, b)
40
 
41
  result = 1.
42
+
43
  for j in range(nterms):
44
+ result -= (
45
+ 2. * alpha * (1. + alpha)
46
+ * exp(-tau * qn[j]**2.)
47
+ / (1. + alpha + alpha**2. * qn[j]**2.)
48
+ )
49
+
50
  result = Minfty * result
51
 
52
  return result