Exemplo n.º 1
0
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
Exemplo n.º 2
0
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
Exemplo n.º 3
0
  def __call__(self, r, z=1e-10):
    """
    Returns the intensity distribution near the focal spot.
    """
    u = self.normalized_distance(z)
    v = self.normalized_radius(r)

    α = self.alpha()
    β = self.beta(u, v)

    I = 2 * α**2 * mp.exp(-α) / (mp.cosh(α) - 1) / (u**2 + 4 * α**2)

    if mp.sqrt(u**2 + 4 * α**2) < v:
      U1 = lommelU(u, v, 1)
      U2 = lommelU(u, v, 2)

      U1s = mp.re(U1)
      U1c = mp.im(U1)
      U2s = mp.re(U2)
      U2c = mp.im(U2)

      return I * ((U1c + U2s)**2 + (U1s - U2c)**2)

    if mp.sqrt(u**2 + 4 * α**2) > v:
      V0 = lommelV(u, v, 0)
      V1 = lommelV(u, v, 1)

      V0s = mp.re(V0)
      V0c = mp.im(V0)
      V1s = mp.re(V1)
      V1c = mp.im(V1)

      exp = mp.exp(α * (1 - β))
      cos = mp.cos(u * (1 + β) / 2)
      sin = mp.sin(u * (1 + β) / 2)

      return I * ((V0c - V1s - exp * cos)**2 + (V0s + V1c + exp * sin)**2)

    raise ValueError('invalid coordinates')
# 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))
        
        u1 = u1 + (k*(k-a))/(2*eta1)
        u2 = u2 + (k*(k-a))/(2*eta2)
Exemplo n.º 5
0
def f103(x):
    # lncosh
    return mpmath.log(mpmath.cosh(x))
Exemplo n.º 6
0
def fi(x):
    r = -(10 / 3) * (mpmath.log(mpmath.cosh(x) / 2))
    return r
Exemplo n.º 7
0
 def interfunc(x):
     return scipy.constants.pi/2*dor**5 * x**4 / (mp.sinh(x*dor))**3 * mp.cosh(x*dor) \
     * mp.j0(x)
Exemplo n.º 8
0
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))))
Exemplo n.º 9
0
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))
Exemplo n.º 10
0
 def Is(self, x):
     return math.log(mpmath.cosh(x))
Exemplo n.º 11
0
    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])]])
Exemplo n.º 12
0
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))))
Exemplo n.º 13
0
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))
Exemplo n.º 14
0
 def eval(self, z):
     return mpmath.cosh(z)
Exemplo n.º 15
0
 def eval(self, z):
     return mpmath.cosh(z)
Exemplo n.º 16
0
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