def T(x,t,a):
    """
    conformal map for single splitting quench. a is qunech cutoff.
    """
    if x>0:
        return atan(-(x-t)/a)
    else:
        return -pi+atan(-(x-t)/a)
def TB(x,t,a):
    """
    complex conjugate of T
    """
    if x>0:
        return atan(-(x+t)/a)
    else:
        return -pi+atan(-(x+t)/a)
def forward(base, humerus, radius, angleL, angleR):
    E = two * radius * (base + humerus *
                        (mpmath.cos(angleR) - mpmath.cos(angleL)))
    F = two * humerus * radius * (mpmath.sin(angleR) - mpmath.sin(angleL))
    G = base * base + two * humerus * humerus + two * base * humerus * mpmath.cos(
        angleR) - two * humerus * humerus * mpmath.cos(angleR - angleL)

    if G - E != 0 and E * E + F * F - G * G > 0:  # avoid div by zero, sqrt of negative
        lumpXminus = (-F - mpmath.sqrt(E * E + F * F - G * G)) / (G - E)
        lumpYminus = (-F - mpmath.sqrt(E * E + F * F - G * G)) / (G - E)
        xMinus = base + humerus * mpmath.cos(angleR) + radius * mpmath.cos(
            two * mpmath.atan(lumpXminus))
        yMinus = humerus * mpmath.sin(angleR) + radius * mpmath.sin(
            two * mpmath.atan(lumpYminus))

        return [xMinus, yMinus]
Exemple #4
0
 def get_angle_alpha(self):
     if (mpmath.almosteq(self.getBelief(), 1, epsilon)):
         return mpmath.mpf("0")
     return mpmath.atan(
         (self.getUncertainty() * mpmath.sin(mpmath.pi / mpmath.mpf("3"))) /
         (self.getDisbelief() +
          self.getUncertainty() * mpmath.cos(math.pi / mpmath.mpf("3"))))
Exemple #5
0
 def get_angle_beta(self):
     if mpmath.almosteq(self.getDisbelief(), 1, epsilon):
         return mpmath.pi / 3
     return mpmath.atan(
         (self.getUncertainty() * mpmath.sin(mpmath.pi / mpmath.mpf("3"))) /
         (mpmath.mpf("1") - (self.getDisbelief() + self.getUncertainty() *
                             mpmath.cos(mpmath.pi / mpmath.mpf("3")))))
Exemple #6
0
def calculate_angles(Input_Cords):
    # Constants
    scalling_const = np.sqrt(.3)
    f = 195 * scalling_const
    t = 375 * scalling_const

    f = f * (10 ^ -3)
    t = t * (10 ^ -3)

    angle_list = []
    for coord in Input_Cords:
        X = (coord[0]) * (10 ^ -3)
        Y = (-coord[1]) * (10 ^ -3)
        H = np.sqrt(math.power(X, 2) + math.power(Y, 2))
        alpha = math.acos(
            (math.power(t, 2) - math.power(f, 2) - math.power(H, 2)) /
            (2 * f * H))
        beta = math.atan(Y / X)
        T_1 = alpha - beta + np.pi
        T_2 = math.acos(
            (math.power(H, 2) - math.power(f, 2) - math.power(t, 2)) /
            (2 * f * t)) + np.pi
        angles = [T_1, T_2]
        angle_list.append(angles)
    return angle_list
Exemple #7
0
def f(x, y, z):
    x = mp.mpmathify(x)
    y = mp.mpmathify(y)
    z = mp.mpmathify(z)

    R = radius(x, y, z)

    # solving 0 division problem here

    if x == 0 and z == 0 or y == 0:
        part1 = mp.mpmathify(0)
    else:
        part1 = mp.mpf('0.5') * y * (mp.power(z, 2) - mp.power(
            x, 2)) * mp.asinh(y / (mp.sqrt(mp.power(x, 2) + mp.power(z, 2))))

    if x == 0 and y == 0 or z == 0:
        part2 = 0
    else:
        part2 = mp.mpf('0.5') * z * (mp.power(y, 2) - mp.power(
            x, 2)) * mp.asinh(z / (mp.sqrt(mp.power(x, 2) + mp.power(y, 2))))

    if x == 0 or y == 0 or z == 0:
        part3 = 0
    else:
        part3 = x * y * z * mp.atan((y * z) / (x * R))

    # solving 0 division problem here

    part4 = mp.mpf('1 / 6') * R * (2 * mp.power(x, 2) - mp.power(y, 2) -
                                   mp.power(z, 2))

    return mp.mpmathify(part1 + part2 - part3 + part4)
Exemple #8
0
 def B_01(Non, Noff, alpha):
     Ntot = Non + Noff
     gam = (1 + 2 * Noff) * power(alpha, (0.5 + Ntot)) * gamma(0.5 + Ntot)
     delta = ((2 * power((1 + alpha), Ntot)) * gamma(1 + Ntot) *
              hyp2f1(0.5 + Noff, 1 + Ntot, 1.5 + Noff, (-1 / alpha)))
     c1_c2 = sqrt(pi) / (2 * atan(1 / sqrt(alpha)))
     return gam / (c1_c2 * delta)
Exemple #9
0
def psi_m_unstable(obukhov, z):
    # Lob   Obukhov Length / m
    # z     Height / m
    x = (1 - 16 * (z / obukhov))**(1 / 4)
    pmu = (2 * math.log((1 + x) / 2) + math.log(
        (1 + x**2) / 2) - 2 * mpmath.atan(x) + math.pi / 2)
    return pmu
Exemple #10
0
def mt_maju_rekursi(freq,res,thick):
    rhoa = np.zeros((len(freq)))
    phas = np.zeros((len(freq)))
    for i in range(len(freq)):
        c = mt_rekursi(res,thick,freq[i])
        rhoa[i] = 2.*np.pi*freq[i]*4.*np.pi*1e-7*np.abs(c**2)
        phas[i] = mpm.atan(c.real/-c.imag)
        
    return freq,rhoa,phas
Exemple #11
0
def QSatanElements(mat):
    if QSMODE == MODE_NORM:
        return np.arctan(mat)
    else:
        at = mpmath.matrix(mat.rows, mat.cols)
        for i in range(mat.rows):
            for j in range(mat.cols):
                at[i,j] = mpmath.atan(mat[i,j])
        return at
Exemple #12
0
def atan_elements(mat):
    if mode == mode_python:
        return np.arctan(mat)
    else:
        at = mpmath.matrix(mat.rows, mat.cols)
        for i in range(mat.rows):
            for j in range(mat.cols):
                at[i, j] = mpmath.atan(mat[i, j])
        return at
Exemple #13
0
def QSatanElements(mat):
    if QSMODE == MODE_NORM:
        return np.arctan(mat)
    else:
        at = mpmath.matrix(mat.rows, mat.cols)
        for i in range(mat.rows):
            for j in range(mat.cols):
                at[i, j] = mpmath.atan(mat[i, j])
        return at
    def equiv_tan(x, range1, range2, radians=None, degrees=None, accuracy=2):
        mpmath.mp.dps = accuracy + 1
        range1, range2 = TrigEquivAngle.deg_or_rad([range1, range2], degrees)
        firstTanAngle = mpmath.atan(x)

        angles = TrigEquivAngle.create_equiv_angle_list([firstTanAngle],
                                                        range1, range2,
                                                        mpmath.pi)
        return (TrigEquivAngle.clean_angles_rad_deg(angles, radians, degrees,
                                                    accuracy))
Exemple #15
0
def arctan_degrees(y, x):
    """ Arctangent of y/x in degrees."""
    if x == 0 and y != 0:
        return (math.copysign(1, y) * mpf(90)) % 360
    else:
        alpha = normalized_degrees_from_radians(atan(y / x))
        if x >= 0:
            return alpha
        else:
            return (alpha + mpf(180)) % 360
Exemple #16
0
def g(x, y, z):
    x = mp.mpmathify(x)
    y = mp.mpmathify(y)
    z = mp.mpmathify(z)

    R = radius(x, y, z)

    if x == 0 and y == 0:
        part1 = mp.mpf('0')
    else:
        part1 = x * y * z * mp.asinh(
            z / (mp.sqrt(mp.power(x, 2) + mp.power(y, 2))))

    if y == 0 and z == 0:
        part2 = mp.mpf('0')
    else:
        part2 = mp.mpf('1 / 6') * y * (3 * mp.power(z, 2) - mp.power(
            y, 2)) * mp.asinh(x / (mp.sqrt(mp.power(y, 2) + mp.power(z, 2))))

    if x == 0 and z == 0:
        part3 = 0
    else:
        part3 = mp.mpf('1 / 6') * x * (3 * mp.power(z, 2) - mp.power(
            x, 2)) * mp.asinh(y / (mp.sqrt(mp.power(x, 2) + mp.power(z, 2))))

    if y == 0:
        part4 = 0
    else:
        part4 = mp.mpf('0.5') * mp.power(y, 2) * z * mp.atan((x * z) / (y * R))

    if x == 0:
        part5 = 0
    else:
        part5 = mp.mpf('0.5') * mp.power(x, 2) * z * mp.atan((y * z) / (x * R))

    if z == 0:
        part6 = 0
    else:
        part6 = mp.mpf('1 / 6') * mp.power(z, 3) * mp.atan((x * y) / (z * R))

    part7 = mp.mpf('1 / 3') * x * y * R
    return mp.mpmathify(part1 + part2 + part3 - part4 - part5 - part6 - part7)
def calAngles(target, segments):
    x = target.x
    y = target.y
    z = target.z
    s1 = segments[0]
    s2 = segments[1]
    s3 = segments[2]
    theta0 = atan(y / x)
    theta1 = acos((s1**2 - z**2 + (s1 - z)**2)/(2*s1*sqrt(x**2 + y**2 + (s1 - z)**2))) \
            + acos((s2**2 - s3**2 + x**2 + y**2 + (s1 - z)**2)/(2*s2*sqrt(x**2 + y**2 + (s1 - z)**2)))
    theta2 = acos((s2**2 + s3**2 - x**2 - y**2 - (s1 - z)**2) / (2 * s2 * s3))
    return [theta0, theta1, theta2]
def get_angle(complex_number, deg=False):
    atan_angle = None

    if complex_number.real == 0:
        if complex_number.imag > 0:
            atan_angle = atan(mpf("inf"))
        else:
            atan_angle = atan(mpf("-inf"))

    else:
        atan_angle = atan(complex_number.imag / complex_number.real)

    if complex_number.real < 0:
        atan_angle += pi

    if deg:
        angle = degrees(atan_angle)

        return angle

    return atan_angle
Exemple #19
0
def calc(weight, bike, acc, vo2max, threshold, economy, position, crr, grade,
         wind, alt, temp):
    weight = float(weight)
    bike = float(bike)
    acc = float(acc)
    temp = float(temp)
    alt = float(alt)
    vo2max = float(vo2max)
    threshold = float(threshold)
    position = float(position)
    economy = float(economy)
    crr = float(crr)
    grade = float(grade)
    wind = float(wind)
    mass = (weight + bike + acc) / 2.2
    watts = round(
        (vo2max * (weight / 2.2)) * (threshold / 100) * (economy / 60), 2)
    rho = 1.2754 * (373 / ((temp - 32) * 5 / 9 + 273.15)) * np.exp(
        -1.2754 * 9.8070 * alt * .3048 / 100000)
    B = mpmath.atan(grade / 100)
    Crv = .1
    Crvn = Crv * (math.cos(B))
    Cm = .97
    Frg = 9.8072 * (mass) * ((crr * (math.cos(B))) + (math.sin(B)))
    cda = position
    W = wind * 1609.344 / 3600
    A1 = (W**3 + Crvn**3) / 27
    A2 = W * (5 * W * Crvn + (8 + Crvn**2) /
              (cda * rho) + 6 * Frg) / (9 * cda * rho)
    A3 = (2 * Frg * Crvn) / (3 * ((cda * rho)**2))
    A4 = watts / (Cm * cda * rho)
    A = A1 - A2 + A3 + A4
    X = (((2) / (9 * cda * rho)) *
         ((3 * Frg) - (4 * W * Crvn) - ((W**2) * cda * (rho / 2)) -
          ((2 * Crvn) / (cda * rho))))
    C = A**2 + X**3
    if C >= 0:
        V1 = (A + (A**2 + X**3)**(1 / 2))**(1 / 3)
        V2 = np.cbrt(A - (((A**2) + (X**3))**(1.0 / 2.0)))
        V3 = (2 / 3) * (W + ((Crvn) / (cda * rho)))
        V = V1 + V2 - V3
    else:
        V = (2 * (-X)**(1 / 2)) * math.cos((1 / 3) * math.acos(
            (A) / (((-X)**3)**1 / 2))) - (2 / 3) * ((W) + ((Crvn) /
                                                           (cda * rho)))
    speed = round(V * 3600 / 1609.344, 2)
    return speed, watts
Exemple #20
0
def AngoloDiRotazione(I):
    Iη = I[0]
    Iξ = I[1]
    Iηξ = I[2]
    if Iηξ == 0:
        return 0
    else:
        if Iη != Iξ:
            A = 2 * Iηξ / (Iξ - Iη)
            A = str(A)
            A = sym.sympify(A)
            A = sym.simplify(A)

            α = mpmath.atan(A) / 2
        else:
            α = pi / 4  # piu o meno??
        return α
Exemple #21
0
 def __compute_tau_xi(self):
     from mpmath import sqrt, asin, ellipf, mpc, atan
     if self.bound:
         # Gradshtein 3.131.3.
         u = self.__init_coordinates[0]**2 / 2
         c, b, a = self.__roots_xi
         gamma = asin(sqrt((u - c) / (b - c)))
         q = sqrt((b - c) / (a - c))
         # NOTE: here it's q**2 instead of q because of the difference in
         # convention between G and mpmath :(
         # NOTE: the external factor 1 / sqrt(8 * self.eps) comes from the fact
         # that G gives the formula for a polynomial normalised by its leading coefficient.
         retval = 1 / sqrt(8 * self.eps) * (2 / sqrt(a - c)) * ellipf(
             gamma, q**2)
     else:
         # Here we will need two cases: one for when the other two roots are real
         # but negative, one for when the other two roots are imaginary.
         if isinstance(self.__roots_xi[1], mpc):
             # G 3.138.7.
             m = self.__roots_xi[1].real
             n = abs(self.__roots_xi[1].imag)
             # Only real root is the first one.
             a = self.__roots_xi[0]
             u = self.__init_coordinates[0]**2 / 2
             p = sqrt((m - a)**2 + n**2)
             retval = 1 / sqrt(8 * self.eps) * (1 / sqrt(p)) * ellipf(
                 2 * atan(sqrt((u - a) / p)), (p + m - a) / (2 * p))
         else:
             # G 3.131.7.
             u = self.__init_coordinates[0]**2 / 2
             c, b, a = self.__roots_xi
             mu = asin(sqrt((u - a) / (u - b)))
             q = sqrt((b - c) / (a - c))
             retval = 1 / sqrt(8 * self.eps) * (2 / sqrt(a - c)) * ellipf(
                 mu, q**2)
     # Fix the sign according to the initial momentum.
     if self.__init_momenta[0] >= 0:
         return -abs(retval)
     else:
         return abs(retval)
Exemple #22
0
	def __compute_tau_xi(self):
		from mpmath import sqrt, asin, ellipf, mpc, atan
		if self.bound:
			# Gradshtein 3.131.3.
			u = self.__init_coordinates[0]**2 / 2
			c,b,a = self.__roots_xi
			gamma = asin(sqrt((u - c)/(b - c)))
			q = sqrt((b - c)/(a - c))
			# NOTE: here it's q**2 instead of q because of the difference in
			# convention between G and mpmath :(
			# NOTE: the external factor 1 / sqrt(8 * self.eps) comes from the fact
			# that G gives the formula for a polynomial normalised by its leading coefficient.
			retval = 1 / sqrt(8 * self.eps) * (2 / sqrt(a - c)) * ellipf(gamma,q**2)
		else:
			# Here we will need two cases: one for when the other two roots are real
			# but negative, one for when the other two roots are imaginary.
			if isinstance(self.__roots_xi[1],mpc):
				# G 3.138.7.
				m = self.__roots_xi[1].real
				n = abs(self.__roots_xi[1].imag)
				# Only real root is the first one.
				a = self.__roots_xi[0]
				u = self.__init_coordinates[0]**2 / 2
				p = sqrt((m - a)**2 + n**2)
				retval = 1 / sqrt(8 * self.eps) * (1 / sqrt(p)) * ellipf(2 * atan(sqrt((u - a) / p)),(p + m - a) / (2*p))
			else:
				# G 3.131.7.
				u = self.__init_coordinates[0]**2 / 2
				c,b,a = self.__roots_xi
				mu = asin(sqrt((u - a)/(u - b)))
				q = sqrt((b - c)/(a - c))
				retval = 1 / sqrt(8 * self.eps) * (2 / sqrt(a - c)) * ellipf(mu,q**2)
		# Fix the sign according to the initial momentum.
		if self.__init_momenta[0] >= 0:
			return -abs(retval)
		else:
			return abs(retval)
def atan(op):
    expr = mpmath.atan(op)
    return convertFromRadians(expr)
from copy import copy

def sqrt(x):
  if hasattr(x,'unit'):
    return math.sqrt(x.number) | x.unit**0.5 
  return math.sqrt(x)  

#trigonometric convenience functions which are "unit aware"
sin=lambda x: math.sin(1.*x)
cos=lambda x: math.cos(1.*x)
tan=lambda x: math.tan(1.*x)
cot=lambda x: math.cot(1.*x)

asin=lambda x: math.asin(x) | rad
acos=lambda x: math.acos(x) | rad
atan=lambda x: math.atan(x) | rad
atan2=lambda x,y: math.atan2(x,y) | rad

#~ cos=math.cos
#~ sin=math.sin
#~ tan=math.tan
#~ cosh=math.cosh
#~ sinh=math.sinh
#~ tanh=math.tanh
#~ acos=math.acos
#~ asin=math.asin
#~ atan=math.atan
acosh=math.acosh
asinh=math.asinh
atanh=math.atanh
#~ atan2=math.atan2
Exemple #25
0
    for angleR in anglesR:
        E = two * radius * (base + humerus *
                            (mpmath.cos(angleR) - mpmath.cos(angleL)))
        F = two * humerus * radius * (mpmath.sin(angleR) - mpmath.sin(angleL))
        G = base * base + two * humerus * humerus + two * base * humerus * mpmath.cos(
            angleR) - two * humerus * humerus * mpmath.cos(angleR - angleL)

        if G - E != 0 and E * E + F * F - G * G > 0:  # avoid div by zero, sqrt of negative

            lumpXplus = (-F + mpmath.sqrt(E * E + F * F - G * G)) / (G - E)
            lumpXminus = (-F - mpmath.sqrt(E * E + F * F - G * G)) / (G - E)
            lumpYplus = (-F + mpmath.sqrt(E * E + F * F - G * G)) / (G - E)
            lumpYminus = (-F - mpmath.sqrt(E * E + F * F - G * G)) / (G - E)

            xPlus = base + humerus * mpmath.cos(angleR) + radius * mpmath.cos(
                two * mpmath.atan(lumpXplus))
            xMinus = base + humerus * mpmath.cos(angleR) + radius * mpmath.cos(
                two * mpmath.atan(lumpXminus))

            yPlus = humerus * mpmath.sin(angleR) + radius * mpmath.sin(
                two * mpmath.atan(lumpYplus))
            yMinus = humerus * mpmath.sin(angleR) + radius * mpmath.sin(
                two * mpmath.atan(lumpYminus))

            ax.plot(xMinus, yMinus, 'o', color='blue')
            ax.plot(xMinus, yPlus, 'o', color='green')
            ax.plot(xPlus, yMinus, 'o', color='red')
            ax.plot(xPlus, yPlus, 'o', color='yellow')

ax.plot(baselineX, baselineY, color='black')
plt.show()
Exemple #26
0
def theta(x, t, a):
    if x > 0:
        return atan(-(x - t) / a)
    else:
        return -pi + atan(-(x - t) / a)
                        + " -1.08573620484781e-01   1.44764827303499e-01  "
                        + " -2.17147240951600e-01   4.34294481903245e-01  "
                        + " -8.37288532635468e-17"
                    ).split(" ")
                    if x != ""
                ]
            )
        )

        # generate the cordic luts
        import mpmath, operator

        mpmath.mp.prec = 100

        tangents = [mpmath.mpf(0.5) ** i for i in range(0, 61)]
        angles = [mpmath.atan(tan) for tan in tangents]
        circle_fracs = [angle / (mpmath.pi / 2) for angle in angles]

        # To speed up the cordic function, we can ignore fractions that are too
        # small
        circle_fracs = [cf for cf in circle_fracs if cf >= mpmath.mpf(0.5) ** (frac_bits + 2)]

        cordic_lut = [decimal.Decimal(str(c)) for c in circle_fracs]

        ps = [mpmath.cos(angle) for angle in angles]
        p = decimal.Decimal(str(reduce(operator.mul, ps)))
        cordic_p = decimal_to_fix_extrabits(p, internal_frac_bits)
        with args["lutfile"] as f:
            lutc = "#ifndef LUT_H\n"
            lutc += "#define LUT_H\n"
            lutc += "\n"
                          " -3.07931040695466e-02   3.32600850755936e-02  " +
                          " -3.62110089768021e-02   3.94927223523808e-02  " +
                          " -4.34283051806530e-02   4.82543694777421e-02  " +
                          " -5.42868520978555e-02   6.20420865245062e-02  " +
                          " -7.23824127625090e-02   8.68588960766508e-02  " +
                          " -1.08573620484781e-01   1.44764827303499e-01  " +
                          " -2.17147240951600e-01   4.34294481903245e-01  " +
                          " -8.37288532635468e-17").split(" ") if x != ''
            ]))

        # generate the cordic luts
        import mpmath, operator
        mpmath.mp.prec = 100

        tangents = [mpmath.mpf(0.5)**i for i in range(0, 61)]
        angles = [mpmath.atan(tan) for tan in tangents]
        circle_fracs = [angle / (mpmath.pi / 2) for angle in angles]

        # To speed up the cordic function, we can ignore fractions that are too
        # small
        circle_fracs = [
            cf for cf in circle_fracs if cf >= mpmath.mpf(0.5)**(frac_bits + 2)
        ]

        cordic_lut = [decimal.Decimal(str(c)) for c in circle_fracs]

        ps = [mpmath.cos(angle) for angle in angles]
        p = decimal.Decimal(str(reduce(operator.mul, ps)))
        cordic_p = decimal_to_fix_extrabits(p, internal_frac_bits)
        with args["lutfile"] as f:
            lutc = '#ifndef LUT_H\n'
Exemple #29
0
 'unitroots': ['primitive', [lambda x, y: Vector(mp.unitroots(x)),
                             None]],  #  
 'hypot': ['primitive', [lambda x, y: mp.hypot(x, y[0]),
                         None]],  # sqrt(x**2+y**2) 
 #
 'sin': ['primitive', [lambda x, y: mp.sin(x), None]],
 'cos': ['primitive', [lambda x, y: mp.cos(x), None]],
 'tan': ['primitive', [lambda x, y: mp.tan(x), None]],
 'sinpi': ['primitive', [lambda x, y: mp.sinpi(x), None]],  #sin(x * pi) 
 'cospi': ['primitive', [lambda x, y: mp.cospi(x), None]],
 'sec': ['primitive', [lambda x, y: mp.sec(x), None]],
 'csc': ['primitive', [lambda x, y: mp.csc(x), None]],
 'cot': ['primitive', [lambda x, y: mp.cot(x), None]],
 'asin': ['primitive', [lambda x, y: mp.asin(x), None]],
 'acos': ['primitive', [lambda x, y: mp.acos(x), None]],
 'atan': ['primitive', [lambda x, y: mp.atan(x), None]],
 'atan2': ['primitive', [lambda x, y: mp.atan2(y[0], x), None]],
 'asec': ['primitive', [lambda x, y: mp.asec(x), None]],
 'acsc': ['primitive', [lambda x, y: mp.acsc(x), None]],
 'acot': ['primitive', [lambda x, y: mp.acot(x), None]],
 'sinc': ['primitive', [lambda x, y: mp.sinc(x), None]],
 'sincpi': ['primitive', [lambda x, y: mp.sincpi(x), None]],
 'degrees': ['primitive', [lambda x, y: mp.degrees(x),
                           None]],  #radian - >degree 
 'radians': ['primitive', [lambda x, y: mp.radians(x),
                           None]],  #degree - >radian 
 #
 'exp': ['primitive', [lambda x, y: mp.exp(x), None]],
 'expj': ['primitive', [lambda x, y: mp.expj(x), None]],  #exp(x*i) 
 'expjpi': ['primitive', [lambda x, y: mp.expjpi(x), None]],  #exp(x*i*pi)
 'expm1': ['primitive', [lambda x, y: mp.expm1(x), None]],  #exp(x)-1
Exemple #30
0
    y = mp.sin(xx) / xx
    return y * 0.5 * mp.pi


FUNCS = [
    ('Exp', lambda x: mp.exp(x), lambda x: mp.exp(x), (0.0, 1.0)),
    ('Exp2', lambda x: 2.0**x, lambda x: 2.0**x, (0.0, 1.0)),
    ('Log', lambda x: mp.log(x + 1), lambda x: mp.log(x + 1) *
     (mp.log(2.0) - mp.log(x + 1)), (epsilon, 1.0 - epsilon)),
    ('Log2', lambda x: mp.log(x + 1, 2.0), lambda x: mp.log(x + 1, 2.0) *
     (1 - mp.log(x + 1, 2.0)), (epsilon, 1.0 - epsilon)),
    ('Rcp', lambda x: 1.0 / (x + 1), lambda x: 1.0 / (x + 1), (0.0, 1.0)),
    ('Sqrt', lambda x: mp.sqrt(x + 1), lambda x: mp.sqrt(x + 1), (0.0, 1.0)),
    ('RSqrt', lambda x: 1.0 / mp.sqrt(x + 1), lambda x: 1.0 / mp.sqrt(x + 1),
     (0.0, 1.0)),
    ('Atan', lambda x: mp.atan(x), lambda x: mp.atan(x), (0.0, 1.0)),
    ('Sin', sinSqr, sinSqr, (epsilon, 1.0)),
]


def generateCode():
    with open(f'fitted.txt', 'w', newline='\n') as file:
        file.write('\t// AUTO-GENERATED POLYNOMIAL APPROXIMATIONS\n')
        file.write('\n')
        file.write('\tpublic static class Util\n')
        file.write('\t{\n')

        for (name, func, weightFunc, domain) in FUNCS:
            print()
            print(f'{name}():')
            orderRange = range(3, 10) if name != 'Sin' else range(1, 5)
Exemple #31
0
 def eval(self, z):
     return mpmath.atan(z)
Exemple #32
0
def g(x):
    return mpmath.matrix([mpmath.atan(x[i]) for i in range(x.rows)])
Exemple #33
0
 def eval(self, z):
     return mpmath.atan(z)