def compound_interest_fnc_mpmath_with_hyperbolic(initial_investment, percent1, percent2, percent3, percent4, percent5, compounding_frequency): #converting the float values to numbers that have 100 decimal places initial_investment = mpmath.mpmathify(initial_investment) percent1 = mpmath.mpmathify(percent1) percent2 = mpmath.mpmathify(percent2) percent3 = mpmath.mpmathify(percent3) percent4 = mpmath.mpmathify(percent4) percent5 = mpmath.mpmathify(percent5) # limit definition: e^x = lim n->infinity (1+x/n)^n principal = initial_investment x = percent1 * compounding_frequency principal = principal * (mpmath.cosh(x) + mpmath.sinh(x)) x = percent2 * compounding_frequency principal = principal * (mpmath.cosh(x) + mpmath.sinh(x)) x = percent3 * compounding_frequency principal = principal * (mpmath.cosh(x) + mpmath.sinh(x)) x = percent4 * compounding_frequency principal = principal * (mpmath.cosh(x) + mpmath.sinh(x)) x = percent5 * compounding_frequency principal = principal * (mpmath.cosh(x) + mpmath.sinh(x)) return principal
def FDoubleDisc(x1,x2,t,s,b): """ inside of log() for disconnected HEE. We take single interval subsystem A=[x1,x2]. This has very complicated minimizasion because the configuration of boundary surface Q varys by Hawking-Page transition. """ v1 = v(x1,t,s,b) v2 = v(x2,t,s,b) vb1 = vb(x1,t,s,b) vb2 = vb(x2,t,s,b) h1 = v1-vb1 hp1 = h1+j*s/2 hm1 = h1-j*s/2 h2 = v2-vb2 hp2 = h2+j*s/2 hm2 = h2-j*s/2 F = (pi**(-4))*Dw(v1,s,b)*(-Dw(-vb1,s,b))*Dw(v2,s,b)*(-Dw(-vb2,s,b)) if s<1: g1 = min([re(sinh(pi*hp1/s)**2),re(sinh(pi*hm1/s)**2)]) g2 = min([re(sinh(pi*hp2/s)**2),re(sinh(pi*hm2/s)**2)]) return F * (s**4)*g1*g2 else: m1 = (sin(pi*hp1)*sin(pi*hp2))**2 m2 = ((sin(pi*hp1)*sin(pi*hm2))**2)*exp(2*pi*s) m3 = ((sin(pi*hm1)*sin(pi*hp2))**2)*exp(2*pi*s) m4 = (sin(pi*hm1)*sin(pi*hm2))**2 return F * min([re(m1),re(m2),re(m3),re(m4)])
def fl(x): p1 = a * mpmath.cosh(a * x) p2 = b * mpmath.cosh(b * x) p3 = mpmath.sinh(a * x) p4 = mpmath.sinh(b * x) r = ((p2 - p1) / x) - ((p4 - p3) / (x**2)) return r
def test_bounds_for_Q1(): """ These bounds are from: Jiangping Wang and Dapeng Wu, "Tight bounds for the first order Marcum Q-function" Wireless Communications and Mobile Computing, Volume 12, Issue 4, March 2012, Pages 293-301. """ with mpmath.workdps(50): sqrt2 = mpmath.sqrt(2) sqrthalfpi = mpmath.sqrt(mpmath.pi / 2) for b in [mpmath.mp.mpf(1), mpmath.mp.mpf(10)]: for a in [b / 16, 0.5 * b, 0.875 * b, b]: q1 = marcumq(1, a, b) sinhab = mpmath.sinh(a * b) i0ab = mpmath.besseli(0, a * b) # lower bound when 0 <= a <= b lb = (mpmath.sqrt(mpmath.pi / 8) * b * i0ab / sinhab * (mpmath.erfc((b - a) / sqrt2) - mpmath.erfc( (b + a) / sqrt2))) assert lb < q1 # upper bound when 0 <= a <= b ub = ((i0ab + 3) / (mpmath.exp(a * b) + 3) * ( mpmath.exp(-(b - a)**2 / 2) + a * sqrthalfpi * mpmath.erfc( (b - a) / sqrt2) + 3 * mpmath.exp(-(a**2 + b**2) / 2))) assert q1 < ub, ("marcumq(1, a, b) < ub for a = %s, b = %s" % (a, b)) for a in [mpmath.mp.mpf(1), mpmath.mp.mpf(10)]: for b in [b / 16, 0.5 * b, 0.875 * b, b]: q1 = marcumq(1, a, b) sinhab = mpmath.sinh(a * b) i0ab = mpmath.besseli(0, a * b) # lower bound when 0 <= b <= a lb = (1 - sqrthalfpi * b * i0ab / sinhab * (mpmath.erf(a / sqrt2) - mpmath.erf( (a - b) / sqrt2) / 2 - mpmath.erf( (a + b) / sqrt2) / 2)) assert lb < q1 # upper bound when 0 <= b <= a ub = ( 1 - i0ab / (mpmath.exp(a * b) + 3) * (4 * mpmath.exp(-a**2 / 2) - mpmath.exp(-(b - a)**2 / 2) - 3 * mpmath.exp(-(a**2 + b**2) / 2) + a * sqrthalfpi * (mpmath.erfc(-a / sqrt2) - mpmath.erfc((b - a) / sqrt2)))) assert q1 < ub, ("marcumq(1, a, b) < ub for a = %s, b = %s" % (a, b))
def S_double_hol_conn(x1, x2, t, s, b): v1, v2, vb1, vb2 = v(x1, t, s, b), v(x2, t, s, b), vb(x1, t, s, b), vb(x2, t, s, b) deriv = (pi**(-4)) * Dw(v1, s, b) * (-Dw(-vb1, s, b)) * Dw( v2, s, b) * (-Dw(-vb2, s, b)) if s < 1: conn = (s**2) * sinh(pi * (v1 - v2) / s) * sinh(pi * (vb1 - vb2) / s) else: conn = sin(pi * (v1 - v2)) * sin(pi * (vb1 - vb2)) return re(log(deriv * conn**2)) / 12 - log((x2 - x1)**2) / 6
def FDoubleConn(x1,x2,t,s,b): """ inside of log() for connected HEE. We take single interval subsystem A=[x1,x2]. """ v1 = v(x1,t,s,b) v2 = v(x2,t,s,b) vb1 = vb(x1,t,s,b) vb2 = vb(x2,t,s,b) F = (pi**(-4))*Dw(v1,s,b)*(-Dw(-vb1,s,b))*Dw(v2,s,b)*(-Dw(-vb2,s,b)) if s<1: return F * (s**4)*((sinh(pi*(v1-v2)/s)*sinh(pi*(vb1-vb2)/s))**2) else: return F * (sin(pi*(v1-v2))*sin(pi*(vb1-vb2)))**2
def S_double_hol_disconn(x1, x2, t, s, b): v1, v2, vb1, vb2 = v(x1, t, s, b), v(x2, t, s, b), vb(x1, t, s, b), vb(x2, t, s, b) #difference from mirror twist op p1, n1, p2, n2 = v1 - vb1 + j * s / 2, v1 - vb1 - j * s / 2, v2 - vb2 + j * s / 2, v2 - vb2 - j * s / 2 deriv = (pi**(-4)) * Dw(v1, s, b) * (-Dw(-vb1, s, b)) * Dw( v2, s, b) * (-Dw(-vb2, s, b)) if s < 1: g1 = min([re(sinh(pi * p1 / s)**2), re(sinh(pi * n1 / s)**2)]) g2 = min([re(sinh(pi * p2 / s)**2), re(sinh(pi * n2 / s)**2)]) disconnSquare = (s**4) * g1 * g2 else: m1 = sin(pi * p1) * sin(pi * p2) m2 = sin(pi * p1) * sin(pi * n2) * exp(pi * s) m3 = sin(pi * n1) * sin(pi * p2) * exp(pi * s) m4 = sin(pi * n1) * sin(pi * n2) disconnSquare = min([re(m1**2), re(m2**2), re(m3**2), re(m4**2)]) return re(log(deriv * disconnSquare)) / 12 - log((x2 - x1)**2) / 6
def S_double_hol(x1, x2, t, s, b): v1, v2, vb1, vb2 = v(x1, t, s, b), v(x2, t, s, b), vb(x1, t, s, b), vb(x2, t, s, b) p1, n1, p2, n2 = v1 - vb1 + j * s / 2, v1 - vb1 - j * s / 2, v2 - vb2 + j * s / 2, v2 - vb2 - j * s / 2 deriv = (pi**(-4)) * Dw(v1, s, b) * (-Dw(-vb1, s, b)) * Dw( v2, s, b) * (-Dw(-vb2, s, b)) if s < 1: conn = (s**2) * sinh(pi * (v1 - v2) / s) * sinh(pi * (vb1 - vb2) / s) g1 = min([re(sinh(pi * p1 / s)**2), re(sinh(pi * n1 / s)**2)]) g2 = min([re(sinh(pi * p2 / s)**2), re(sinh(pi * n2 / s)**2)]) disconnSquare = (s**4) * g1 * g2 else: conn = sin(pi * (v1 - v2)) * sin(pi * (vb1 - vb2)) m1 = sin(pi * p1) * sin(pi * p2) m2 = sin(pi * p1) * sin(pi * n2) * exp(pi * s) m3 = sin(pi * n1) * sin(pi * p2) * exp(pi * s) m4 = sin(pi * n1) * sin(pi * n2) disconnSquare = min([re(m1**2), re(m2**2), re(m3**2), re(m4**2)]) return min([re(log(deriv * re(conn)**2)), re(log(deriv * disconnSquare))]) / 12 - log((x2 - x1)**2) / 6
def yk(h, k): return float(1 / (mpmath.exp(mpmath.pi / 2 * mpmath.sinh(k * h)) * mpmath.cosh(mpmath.pi / 2 * mpmath.sinh(k * h))))
def wk(h, k): return float(0.5 * mpmath.pi * h * mpmath.cosh(k * h) / (mpmath.cosh(0.5 * mpmath.pi * mpmath.sinh(k * h))**2))
def eval(self, z): return mpmath.sinh(z)
def f102(x): # lnsinh return mpmath.log(mpmath.sinh(x))
def f(x): r = (-(1 / x) * (mpmath.sinh(a * x) - mpmath.sinh(b * x))) - L return r
def interfunc(x): return scipy.constants.pi/2*dor**4 * x**3 / mp.sinh(x*dor)**2 * mp.j0(x)
def interfunc(x): return scipy.constants.pi/2*dor**5 * x**4 / (mp.sinh(x*dor))**3 * mp.cosh(x*dor) \ * mp.j0(x)
def wk(h, k): return float(0.5*mpmath.pi*h*mpmath.cosh(k*h)/(mpmath.cosh(0.5*mpmath.pi*mpmath.sinh(k*h))**2))
######################################### # The velocity profile is to be calculated as a Fourier series # Define the m-th element, then sum up to M # Define the Fourier part of the term first: in Giovanni's notation, v/G. # G is to be calculated later u = np.zeros((nPointsZ, nPointsY)) for j in y: for k in z: u1 = 0 u2 = 0 for m in [x+1 for x in range(M)]: Km = 2*a**2*(1-(-1)**m)/(m**3*np.pi**3) Cm = S*mp.sinh(b*m*np.pi/a) + D*mp.sinh((b-2*Y)*m*np.pi/a) A1m = Km/eta1 B1m = (Km/(eta1*Cm)) * (2*eta1 - S*mp.cosh(b*m*np.pi/a) + D*(mp.cosh((b-2*Y)*m*np.pi/a) - 2*mp.cosh((b-Y)*m*np.pi/a)) ) A2m = (Km/(eta2*Cm)) * (2*(eta2 + D*mp.cosh(Y*m*np.pi/a))*mp.sinh(b*m*np.pi/a) - D*mp.sinh(2*Y*m*np.pi/a) ) B2m = (Km/(eta2*Cm)) * (S - 2*mp.cosh(b*m*np.pi/a)*(eta2 + D*mp.cosh(Y*m*np.pi/a)) + D*mp.cosh(2*Y*m*np.pi/a) ) u1 = u1 + np.sin(m*np.pi*k/a)* (A1m*mp.cosh(m*np.pi*j/a) + B1m*mp.sinh(m*np.pi*j/a)) u2 = u2 + np.sin(m*np.pi*k/a)* (A2m*mp.cosh(m*np.pi*j/a) + B2m*mp.sinh(m*np.pi*j/a))
def get_BC_Matrix(self): """ Function that creates the BC Matrix using mpmath and the previous calculated variables. The resulting Matrix is stored as self.BCM. """ self.BCM = mp.matrix([[1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, self.taus[0], 0, self.taus[1], 0, 0, 0, 0, 0, 0, 0, 0], [mp.cos(self.parameters['L1'] * self.taus[0]), mp.sin(self.parameters['L1'] * self.taus[0]), mp.cosh(self.parameters['L1'] * self.taus[1]), mp.sinh(self.parameters['L1'] * self.taus[1]), -mp.cos(self.parameters['L1'] * self.taus[2]), -mp.sin(self.parameters['L1'] * self.taus[2]), -mp.cosh(self.parameters['L1'] * self.taus[3]), -mp.sinh(self.parameters['L1'] * self.taus[3]), 0, 0, 0, 0], [-self.taus[0] * mp.sin(self.parameters['L1'] * self.taus[0]), self.taus[0] * mp.cos(self.parameters['L1'] * self.taus[0]), self.taus[1] * mp.sinh(self.parameters['L1'] * self.taus[1]), self.taus[1] * mp.cosh(self.parameters['L1'] * self.taus[1]), self.taus[2] * mp.sin(self.parameters['L1'] * self.taus[2]), -self.taus[2] * mp.cos(self.parameters['L1'] * self.taus[2]), -self.taus[3] * mp.sinh(self.parameters['L1'] * self.taus[3]), -self.taus[3] * mp.cosh(self.parameters['L1'] * self.taus[3]), 0, 0, 0, 0], [self.E_1 * self.I_1 * self.taus[0] ** 2 * mp.cos(self.parameters['L1'] * self.taus[0]), self.E_1 * self.I_1 * self.taus[0] ** 2 * mp.sin(self.parameters['L1'] * self.taus[0]), -self.E_1 * self.I_1 * self.taus[1] ** 2 * mp.cosh(self.parameters['L1'] * self.taus[1]), -self.E_1 * self.I_1 * self.taus[1] ** 2 * mp.sinh(self.parameters['L1'] * self.taus[1]), -self.E_2 * self.I_2 * self.taus[2] ** 2 * mp.cos(self.parameters['L1'] * self.taus[2]), -self.E_2 * self.I_2 * self.taus[2] ** 2 * mp.sin(self.parameters['L1'] * self.taus[2]), self.E_2 * self.I_2 * self.taus[3] ** 2 * mp.cosh(self.parameters['L1'] * self.taus[3]) , self.E_2 * self.I_2 * self.taus[3] ** 2 * mp.sinh(self.parameters['L1'] * self.taus[3]), 0, 0, 0, 0], [self.E_1 * self.I_1 * self.taus[0] ** 3 * mp.sin(self.parameters['L1'] * self.taus[0]), -self.E_1 * self.I_1 * self.taus[0] ** 3 * mp.cos(self.parameters['L1'] * self.taus[0]), self.E_1 * self.I_1 * self.taus[1] ** 3 * mp.sinh(self.parameters['L1'] * self.taus[1]), self.E_1 * self.I_1 * self.taus[1] ** 3 * mp.cosh(self.parameters['L1'] * self.taus[1]), -self.E_2 * self.I_2 * self.taus[2] ** 3 * mp.sin(self.parameters['L1'] * self.taus[2]), self.E_2 * self.I_2 * self.taus[2] ** 3 * mp.cos(self.parameters['L1'] * self.taus[2]), -self.E_2 * self.I_2 * self.taus[3] ** 3 * mp.sinh(self.parameters['L1'] * self.taus[3]), -self.E_2 * self.I_2 * self.taus[3] ** 3 * mp.cosh(self.parameters['L1'] * self.taus[3]), 0, 0, 0, 0], [0, 0, 0, 0, mp.cos(self.parameters['L2'] * self.taus[2]), mp.sin(self.parameters['L2'] * self.taus[2]), mp.cosh(self.parameters['L2'] * self.taus[3]), mp.sinh(self.parameters['L2'] * self.taus[3]), -mp.cos(self.parameters['L2'] * self.taus[4]), -mp.sin(self.parameters['L2'] * self.taus[4]), -mp.cosh(self.parameters['L2'] * self.taus[5]), -mp.sinh(self.parameters['L2'] * self.taus[5])], [0, 0, 0, 0, -self.taus[2] * mp.sin(self.parameters['L2'] * self.taus[2]), self.taus[2] * mp.cos(self.parameters['L2'] * self.taus[2]), self.taus[3] * mp.sinh(self.parameters['L2'] * self.taus[3]), self.taus[3] * mp.cosh(self.parameters['L2'] * self.taus[3]), self.taus[4] * mp.sin(self.parameters['L2'] * self.taus[4]), -self.taus[4] * mp.cos(self.parameters['L2'] * self.taus[4]), -self.taus[5] * mp.sinh(self.parameters['L2'] * self.taus[5]), -self.taus[5] * mp.cosh(self.parameters['L2'] * self.taus[5])], [0, 0, 0, 0, self.E_2 * self.I_2 * self.taus[2] ** 2 * mp.cos(self.parameters['L2'] * self.taus[2]), self.E_2 * self.I_2 * self.taus[2] ** 2 * mp.sin(self.parameters['L2'] * self.taus[2]), -self.E_2 * self.I_2 * self.taus[3] ** 2 * mp.cosh(self.parameters['L2'] * self.taus[3]), -self.E_2 * self.I_2 * self.taus[3] ** 2 * mp.sinh(self.parameters['L2'] * self.taus[3]), -self.E_3 * self.I_3 * self.taus[4] ** 2 * mp.cos(self.parameters['L2'] * self.taus[4]), -self.E_3 * self.I_3 * self.taus[4] ** 2 * mp.sin(self.parameters['L2'] * self.taus[4]), self.E_3 * self.I_3 * self.taus[5] ** 2 * mp.cosh(self.parameters['L2'] * self.taus[5]), self.E_3 * self.I_3 * self.taus[5] ** 2 * mp.sinh(self.parameters['L2'] * self.taus[5])], [0, 0, 0, 0, self.E_2 * self.I_2 * self.taus[2] ** 3 * mp.sin(self.parameters['L2'] * self.taus[2]), -self.E_2 * self.I_2 * self.taus[2] ** 3 * mp.cos(self.parameters['L2'] * self.taus[2]), self.E_2 * self.I_2 * self.taus[3] ** 3 * mp.sinh(self.parameters['L2'] * self.taus[3]), self.E_2 * self.I_2 * self.taus[3] ** 3 * mp.cosh(self.parameters['L2'] * self.taus[3]), -self.E_3 * self.I_3 * self.taus[4] ** 3 * mp.sin(self.parameters['L2'] * self.taus[4]), self.E_3 * self.I_3 * self.taus[4] ** 3 * mp.cos(self.parameters['L2'] * self.taus[4]), -self.E_3 * self.I_3 * self.taus[5] ** 3 * mp.sinh(self.parameters['L2'] * self.taus[5]), -self.E_3 * self.I_3 * self.taus[5] ** 3 * mp.cosh( self.parameters['L2'] * self.taus[5])], [0, 0, 0, 0, 0, 0, 0, 0, mp.cos(self.parameters['L3'] * self.taus[4]), mp.sin(self.parameters['L3'] * self.taus[4]), mp.cosh(self.parameters['L3'] * self.taus[5]), mp.sinh(self.parameters['L3'] * self.taus[5])], [0, 0, 0, 0, 0, 0, 0, 0, -self.taus[4] * mp.sin(self.parameters['L3'] * self.taus[4]), self.taus[4] * mp.cos(self.parameters['L3'] * self.taus[4]), self.taus[5] * mp.sinh(self.parameters['L3'] * self.taus[5]), self.taus[5] * mp.cosh(self.parameters['L3'] * self.taus[5])]])
import numpy as np import decimal as dec import math from sys import maxsize import mpmath as mp import matplotlib.pyplot as plt f1 = lambda x: mp.cos(x) * mp.cosh(x) - 1 f2 = lambda x: 1 / x - mp.tan(x) if x != 0 else maxsize f3 = lambda x: 2**(-x) + mp.exp(x) + 2 * mp.cos(x) - 6 f1d = lambda x: mp.cos(x) * mp.sinh(x) - mp.sin(x) * mp.cosh(x) f2d = lambda x: -1 / (x**2) - 1 / (mp.cos(x)**2) f3d = lambda x: mp.exp(x) - (2**(-x) * mp.log(2) - 2 * mp.sin(x)) funcs = [f1, f2, f3] funcsD = [f1d, f2d, f3d] intervals = [(3 / 2 * math.pi, 2 * math.pi), (0, math.pi / 2), (1, 3)] precisions = [math.pow(10, -7), math.pow(10, -15), math.pow(10, -33)] DEC = mp.mpf def bisection(f, a, b, precision, E): mp.mp.dps = precision if mp.sign(f(a)) == mp.sign(f(b)): print("no root") return (maxsize, maxsize) middle = DEC(a) + (DEC(b) - DEC(a)) / 2 numOfSteps = 0 while abs(DEC(a) - DEC(b)) > E: middle = DEC(a) + (DEC(b) - DEC(a)) / 2