In [2]:
from math import *
In [39]:
def layerExpansionRatio(n,totalOverFirst):
    maxIters = 200
    tol = 1e-8
 
    if (abs(n-totalOverFirst) < tol):
         return 1.0
 
    # // Calculate the bounds of the solution
 
    if (totalOverFirst < n):
         minR = 0.0
         maxR = pow(totalOverFirst/n, 1/(n-1))
    else:
         minR = pow(totalOverFirst/n, 1/(n-1))
         maxR = totalOverFirst/(n - 1);
 
    # // Starting guess
    r = 0.5*(minR + maxR);
 
    for i in range(maxIters):
        prevr = r;
 
        fx = pow(r, n) - totalOverFirst*r - (1 - totalOverFirst);
        dfx = n*pow(r, n - 1) - totalOverFirst;
        r -= fx/dfx;

        print 'Iter=',i,' r=',r
        if (abs(r - prevr) < tol):
             break
    return r
In [48]:
nLayers = 16
desiredExpansionRatio = 1.3
firstLayerThickness = 0.003
totalThickness = firstLayerThickness*((1.-pow(desiredExpansionRatio,nLayers))/(1.-desiredExpansionRatio)-1.)
print 'totalThickness', totalThickness
finalLayerThickness = firstLayerThickness * pow(desiredExpansionRatio,nLayers -1 )

print layerExpansionRatio(nLayers,totalOverFirst=totalThickness/firstLayerThickness)
totalThickness 0.652416609183
Iter= 0  r= 7.26475634566
Iter= 1  r= 6.81070907407
Iter= 2  r= 6.38503975696
Iter= 3  r= 5.98597477221
Iter= 4  r= 5.61185134908
Iter= 5  r= 5.2611106401
Iter= 6  r= 4.93229122591
Iter= 7  r= 4.62402302628
Iter= 8  r= 4.33502159194
Iter= 9  r= 4.06408275407
Iter= 10  r= 3.81007761001
Iter= 11  r= 3.57194782704
Iter= 12  r= 3.34870125055
Iter= 13  r= 3.13940781266
Iter= 14  r= 2.94319575786
Iter= 15  r= 2.75924824865
Iter= 16  r= 2.58680052001
Iter= 17  r= 2.42513799285
Iter= 18  r= 2.27359630126
Iter= 19  r= 2.13156540152
Iter= 20  r= 1.99850257441
Iter= 21  r= 1.87396470467
Iter= 22  r= 1.75768132611
Iter= 23  r= 1.64970973591
Iter= 24  r= 1.55074028734
Iter= 25  r= 1.46262385274
Iter= 26  r= 1.38905017869
Iter= 27  r= 1.33568101213
Iter= 28  r= 1.30739430053
Iter= 29  r= 1.29995911775
Iter= 30  r= 1.29950094128
Iter= 31  r= 1.29949928276
Iter= 32  r= 1.29949928274
1.29949928274