Пример #1
0
    def test_asinh(self):
        import math

        self.ftest(math.asinh(0), 0)
        self.ftest(math.asinh(1), 0.88137358701954305)
        self.ftest(math.asinh(-1), -0.88137358701954305)
        assert math.isinf(math.asinh(float("inf")))
Пример #2
0
 def testAsinh(self):
     self.assertRaises(TypeError, math.asinh)
     self.ftest('asinh(0)', math.asinh(0), 0)
     self.ftest('asinh(1)', math.asinh(1), 0.88137358701954305)
     self.ftest('asinh(-1)', math.asinh(-1), -0.88137358701954305)
     self.assertEqual(math.asinh(INF), INF)
     # self.assertEqual(math.asinh(NINF), NINF)
     self.assertTrue(math.isnan(math.asinh(NAN)))
Пример #3
0
def g(p):
  x, y, z = p[0], p[1], abs(p[2])
  return + x*y*z * asinh(z / (sqrt(x**2 + y**2) + eps))                         \
         + y / 6.0 * (3.0 * z**2 - y**2) * asinh(x / (sqrt(y**2 + z**2) + eps)) \
         + x / 6.0 * (3.0 * z**2 - x**2) * asinh(y / (sqrt(x**2 + z**2) + eps)) \
         - z**3 / 6.0 * atan(x*y / (z * sqrt(x**2 + y**2 + z**2) + eps))        \
         - z * y**2 / 2.0 * atan(x*z / (y * sqrt(x**2 + y**2 + z**2) + eps))    \
         - z * x**2 / 2.0 * atan(y*z / (x * sqrt(x**2 + y**2 + z**2) + eps))    \
         - x*y * sqrt(x**2 + y**2 + z**2) / 3.0
Пример #4
0
def tri_angle_side_angle(a1, s, a2):
  """if the sides go [s,X,Y] with angles a1, a2, on either side of s, this 
  function returns X,Y"""
  #find the remaining angle
  S = math.acos(math.sin(a1)*math.sin(a2)*math.cosh(s) - math.cos(a1)*math.cos(a2))
  #use the law of sines to get the other sides
  sin_ratio = math.sinh(s)/math.sin(S)
  X = math.asinh(sin_ratio*math.sin(a1))
  Y = math.asinh(sin_ratio*math.sin(a2))
  return X,Y
Пример #5
0
def coefRAsientoZapRectangularFlexible(l,b):
    '''
    coefRAsientoZapRectangularFlexible(l,b):
    Devuelve el coeficiente R de la expresión del asiento
    de una cimentación superficial flexible rectangular de
    acuerdo con el apartado 4.8.1 de la Guia de
    cimentaciones en obras de carretera, figura 4.10 de la página 113
    '''
    retv=b*math.asinh(l/float(b))+l*math.asinh(b/float(l))
    return(retv)
Пример #6
0
def acos(x):
    _acos_special = [
        [3*pi/4+infj, pi+infj, pi+infj, pi-infj, pi-infj, 3*pi/4-infj, nan+infj],
        [pi/2+infj, None, None, None, None, pi/2-infj, nan+nanj],
        [pi/2+infj, None, None, None, None, pi/2-infj, pi/2+nanj],
        [pi/2+infj, None, None, None, None, pi/2-infj, pi/2+nanj],
        [pi/2+infj, None, None, None, None, pi/2-infj, nan+nanj],
        [pi/4+infj, infj, infj, 0.0-infj, 0.0-infj, pi/4-infj, nan+infj],
        [nan+infj, nan+nanj, nan+nanj, nan+nanj, nan+nanj, nan-infj, nan+nanj]
    ]

    z = _make_complex(x)

    if not isfinite(z):
        return _acos_special[_special_type(z.real)][_special_type(z.imag)]

    if abs(z.real) > _LARGE_DOUBLE or abs(z.imag) > _LARGE_DOUBLE:
        if z.real < 0:
            imag = -math.copysign(math.log(math.hypot(z.real/2, z.imag/2)) +
                                  2 * _LOG_2, z.imag)
        else:
            imag = math.copysign(math.log(math.hypot(z.real/2, z.imag/2)) +
                                 2 * _LOG_2, -z.imag)
        return complex(math.atan2(abs(z.imag), z.real), imag)

    s1 = sqrt(complex(1.0 - z.real, -z.imag))
    s2 = sqrt(complex(1.0 + z.real, z.imag))
    return complex(2 * math.atan2(s1.real, s2.real),
                   math.asinh(s2.real*s1.imag - s2.imag*s1.real))
Пример #7
0
def asinh(x):
    _asinh_special = [
        [-inf-1j*pi/4, complex(-float("inf"), -0.0), complex(-float("inf"), -0.0),
            complex(-float("inf"), 0.0), complex(-float("inf"), 0.0), -inf+1j*pi/4, -inf+nanj],
        [-inf-1j*pi/2, None, None, None, None, -inf+1j*pi/2, nan+nanj],
        [-inf-1j*pi/2, None, None, None, None, -inf+1j*pi/2, nan+nanj],
        [inf-1j*pi/2, None, None, None, None, inf+1j*pi/2, nan+nanj],
        [inf-1j*pi/2, None, None, None, None, inf+1j*pi/2, nan+nanj],
        [inf-1j*pi/4, complex(float("inf"), -0.0), complex(float("inf"), -0.0),
            inf, inf, inf+1j*pi/4, inf+nanj],
        [inf+nanj, nan+nanj, complex(float("nan"), -0.0), nan, nan+nanj, inf+nanj, nan+nanj]
    ]

    z = _make_complex(x)

    if not isfinite(z):
        return _asinh_special[_special_type(z.real)][_special_type(z.imag)]

    if abs(z.real) > _LARGE_DOUBLE or abs(z.imag) > _LARGE_DOUBLE:
        if z.imag >= 0:
            real = math.copysign(math.log(math.hypot(z.imag/2, z.real/2)) +
                                 2 * _LOG_2, z.real)
        else:
            real = -math.copysign(math.log(math.hypot(z.imag/2, z.real/2)) +
                                  2 * _LOG_2, -z.real)
        return complex(real, math.atan2(z.imag, abs(z.real)))

    s1 = sqrt(complex(1+z.imag, -z.real))
    s2 = sqrt(complex(1-z.imag, z.real))
    return complex(math.asinh(s1.real*s2.imag-s2.real*s1.imag),
                   math.atan2(z.imag, s1.real*s2.real - s1.imag*s2.imag))
Пример #8
0
def acos(x):
    """
        Return the arc cosine of x.

        There are two branch cuts: One extends right from 1 along the real axis to ∞, continuous from below.
        The other extends left from -1 along the real axis to -∞, continuous from above.
    """

    ret = _SPECIAL_VALUE(x, _acos_special_values)
    if ret is not None:
        return ret

    if math.fabs(x.real) > _CM_LARGE_DOUBLE or math.fabs(x.imag) > _CM_LARGE_DOUBLE:

        # avoid unnecessary overflow for large arguments
        _real = math.atan2(math.fabs(x.imag), x.real)

        # split into cases to make sure that the branch cut has the
        # correct continuity on systems with unsigned zeros
        if x.real < 0:
            _imag = -math.copysign(math.log(math.hypot(x.real/2., x.imag/2.)) + _M_LN2*2., x.imag);
        else:
            _imag = math.copysign(math.log(math.hypot(x.real/2., x.imag/2.)) + _M_LN2*2., -x.imag);
    else:
        s1 = complex(float(1-x.real), -x.imag)
        s1 = sqrt(s1)
        s2 = complex(1.0+x.real, x.imag)
        s2 = sqrt(s2)
        _real = 2.0*math.atan2(s1.real, s2.real);
        _imag = math.asinh(s2.real*s1.imag - s2.imag*s1.real)

    return complex(_real,_imag)
Пример #9
0
 def zeta(self, snu, cnu, dnu, snv, cnv, dnv):
   '''
    Lee 54.17 but write
    atanh(snu * dnv) = asinh(snu * dnv / sqrt(cnu^2 + _mv * snu^2 * snv^2))
    atanh(_e * snu / dnv) =
            asinh(_e * snu / sqrt(_mu * cnu^2 + _mv * cnv^2))
   '''
   d1 = math.sqrt(cnu*cnu + self.mv * (snu*snv)**2.0)
   d2 = math.sqrt(self.mu * cnu*cnu + self.mv * cnv*cnv)
   t1 = snu * dnv
   if d1 != 0.0:
     t1 /= d1
   else: 
     t1 = self.overflow if snu >= 0.0 else -self.overflow
   
   t2 = self.e * snu
   if d2 != 0.0:
     t2 = math.sinh(self.e * math.asinh(t2 / d2))
   else:
     t2 = self.overflow if snu >= 0.0 else -self.overflow
   
   taup = t1 * math.hypot(1.0, t2) - t2 * math.hypot(1.0, t1);
   lam = 0.0
   if d1 != 0.0 and d2 != 0.0:
     lam = math.atan2(dnu*snv, cnu*cnv) - self.e * math.atan2(self.e*cnu*snv, dnu*cnv)
   return [taup, lam]
Пример #10
0
def deg2num(x, y, zoom):
    """Convert longitude, latitude to tile numbers."""
    xmerc = math.radians(x)
    ymerc = math.asinh(math.tan(math.radians(y)))
    xtile = int((1 + xmerc/math.pi) / 2 * 2**zoom)
    ytile = int((1 - ymerc/math.pi) / 2 * 2**zoom)
    return xtile, ytile
Пример #11
0
	def arclen_grad_x0y0ddd(x0, y0, d, dd, low, high):
		"""arclen_grad_x0y0ddd(x0, y0, d, dd, low, high) -> (alpha, beta, gamma)

		Where arc = Catenary.from_x0y0ddd(x0, y0, d, dd).arc_length(low, high),
			(D[arc, x0], D[arc, d], D[arc, dd])
		"""
		# gA = Sqrt[1 + d^2] / dd;
		# gxm = x0 - Sqrt[1 + d^2] ArcSinh[d]/dd;
		# gym = y0 - (1 + d^2)/dd;
		# arc = gA Sinh[(high - gxm)/gA] - gA Sinh[(low - gxm)/gA];

		f1 = lambda func, bound: func(dd * (bound - x0)/(1 + d**2)**0.5 + math.asinh(d))
		term = f1(math.sinh, high) - f1(math.sinh, low)
		term *= (1 + d**2)**0.5

		# D[arc, x0]
		alpha = f1(math.cosh, low) - f1(math.cosh, high)

		# D[arc, d]
		beta = (1 + d**2 + d * dd * (x0 - high)) * f1(math.cosh, high)
		beta -= (1 + d * (d - dd * low + dd * x0)) * f1(math.cosh, low)
		beta += d * term
		beta /= (1 + d**2.0) * dd

		# D[arc, dd]
		gamma = dd * (high - x0) * f1(math.cosh, high)
		gamma += dd * (x0 - low) * f1(math.cosh, low)
		gamma -= term
		gamma /= dd**2.0

		return alpha, beta, gamma
Пример #12
0
def pmuboost3d(jets, met, lep):
    mw = 80.385
    wwwtlv = ROOT.TLorentzVector(1e-9,1e-9,1e-9,1e-9)
    mettlv = ROOT.TLorentzVector(1e-9,1e-9,1e-9,1e-9)
    leptlv = ROOT.TLorentzVector(1e-9,1e-9,1e-9,1e-9)
    for jet in jets:
#        if(e.jetPt[ij] > 30.):
            tlvaux = ROOT.TLorentzVector(1e-9,1e-9,1e-9,1e-9)
            tlvaux.SetPtEtaPhiM(jet['pt'],0.,jet['phi'],0.)
            wwwtlv -= tlvaux
    mettlv.SetPtEtaPhiM(met['pt'],0.,met['phi'],0.)
    leptlv.SetPtEtaPhiM(lep['pt'],lep['eta'],lep['phi'], 0.)
#    leptlv.SetPtEtaPhiM(e.muPt[0],e.muEta[0],e.muPhi[0],0.)
# calculate eta(W) estimate; take the + solution
    ptl = (wwwtlv - mettlv).Pt()
    ptn = mettlv.Pt()
    ptw = wwwtlv.Pt()
    etal = leptlv.Eta()
    A = (mw*mw + ptw*ptw - ptl*ptl - ptn*ptn) / (2.*ptl*ptn)
    if(A<1.): A=1.
    etaw = asinh((ptl*sinh(etal)+ptn*sinh(etal+acosh(A)))/ptw)
    if(abs(etaw)>10.): etaw=10*etaw/abs(etaw) # avoid too large values
    wwwtlv.SetPtEtaPhiM(wwwtlv.Pt(),etaw,wwwtlv.Phi(),mw)
# calulate boosted lepton momentum
    beta = wwwtlv.BoostVector()
    leptlv.Boost(-beta)
    return leptlv.P()
Пример #13
0
    def compute(self, plug, data):

        #   Check if output value is connected
        if plug == self.aOutputVaue:

            #    Get input datas
            operationTypeHandle = data.inputValue(self.aOperationType)
            operationType = operationTypeHandle.asInt()

            inputValueHandle = data.inputValue(self.aInputValue)
            inputValue = inputValueHandle.asFloat()
            
            #   Math Sinus
            outputValue = 0
            if operationType == 0:
                outputValue = math.asin(inputValue)
            if operationType == 1:
                outputValue = math.sin(inputValue)
            if operationType == 2:
                outputValue = math.asinh(inputValue)
            if operationType == 3:
                outputValue = math.sinh(inputValue)

            #   Output Value
            output_data = data.outputValue(self.aOutputVaue)
            output_data.setFloat(outputValue)

        #   Clean plug
        data.setClean(plug)
Пример #14
0
  def test_funcs_multi(self):
    pi = math.pi

    # sin family
    self.assertQuantity(data.sin(Quantity( (0,pi/2), (2,2))), (0,1), (2,0)) 
    self.assertQuantity(data.sinh(Quantity((0,1), (2,2))), (0, math.sinh(1)), (2, math.cosh(1)*2)) 
    self.assertQuantity(data.asin(Quantity((0,0.5), (2,2))), (0,math.asin(0.5)), (2,2/math.sqrt(1-0.5**2))) 
    self.assertQuantity(data.asinh(Quantity((0,1), (2,2))), (0,math.asinh(1)), (2,2/math.sqrt(1+1**2))) 

    # cos family
    self.assertQuantity(data.cos(Quantity((0,pi/2), (2,2))), (1,0), (0,-2)) 
    self.assertQuantity(data.cosh(Quantity((0,1), (2,2))), (1,math.cosh(1)), (0,math.sinh(1)*2)) 
    self.assertQuantity(data.acos(Quantity((0,0.5), (2,2))), (math.acos(0),math.acos(0.5)), (-2,-2/math.sqrt(1-0.5**2)))
    self.assertQuantity(data.acosh(Quantity((2,3), (2,2))), (math.acosh(2), math.acosh(3)), (2/math.sqrt(2**2-1),2/math.sqrt(3**2-1)))

    # tan family
    self.assertQuantity(data.tan(Quantity((0,1), (2,2))), (0,math.tan(1)), (2,2/math.cos(1)**2))
    self.assertQuantity(data.tanh(Quantity((0,1), (2,2))), (0,math.tanh(1)), (2,2/math.cosh(1)**2)) 
    self.assertQuantity(data.atan(Quantity((0,1), (2,2))), (0, math.atan(1)), (2,2/(1+1**2))) 
    self.assertQuantity(data.atan2(Quantity((0,1), (2,2)), Quantity((1,1), (0,0))), (0,math.atan(1)), (2,2/(1+1**2))) 
    self.assertQuantity(data.atanh(Quantity((0,0.5), (2,2))), (0,math.atanh(0.5)), (2,2/(1-0.5**2)))

    #misc
    self.assertQuantity(data.sqrt(Quantity((1,4), (2,2))), (1,2), (1,1/2))
    self.assertQuantity(data.exp(Quantity((1,4), (2,2))), (math.e, math.e**4), (2 * math.e,2*math.e**4))
    self.assertQuantity(data.log(Quantity((1,4), (2,2))), (0, math.log(4)), (2,1/2))
Пример #15
0
    def test_arcsinh(self):
        import math
        from _numpypy import arcsinh

        for v in [float('inf'), float('-inf'), 1.0, math.e]:
            assert math.asinh(v) == arcsinh(v)
        assert math.isnan(arcsinh(float("nan")))
Пример #16
0
    def test_arcsinh(self):
        import math
        from numpypy import arcsinh, inf

        for v in [inf, -inf, 1.0, math.e]:
            assert math.asinh(v) == arcsinh(v)
        assert math.isnan(arcsinh(float("nan")))
Пример #17
0
    def test_acosh(self):
        import math

        self.ftest(math.acosh(1), 0)
        self.ftest(math.acosh(2), 1.3169578969248168)
        assert math.isinf(math.asinh(float("inf")))
        raises(ValueError, math.acosh, 0)
Пример #18
0
def chebyshev1(cutoff_frequency, ripple, order, highpass):
    """A helper function for creating the transfer function of a Chebyshev Type 1 filter.

    :param cutoff_frequency: the cutoff frequency of the filter in Hz
    :param ripple: the allowed passband ripple in dB
    :param order: the filter order as an integer
    :param highpass: True, if a lowpass-to-highpass-transformation shall be done, False otherwise
    """
    k = frequency_scaling(cutoff_frequency=cutoff_frequency, highpass=highpass)
    k2 = k ** 2
    factors = []
    # precompute coefficients
    g = math.asinh(1.0 / math.sqrt(10.0 ** (abs(ripple) / 10.0) - 1.0)) / order
    sinhg = math.sinh(g)
    cosh2g = math.cosh(g) ** 2
    # generate the transfer function
    if order % 2 == 0:
        pb2o = math.pi / (2 * order)
        for i in range(1, order // 2 + 1):
            b2 = 1.0 / (cosh2g - (math.cos((2 * i - 1) * pb2o) ** 2))
            b1 = 2.0 * b2 * sinhg * math.cos((2 * i - 1) * pb2o)
            factors.append(Chebyshev1Filter.Polynomial((b2 * k2, b1 * k, 1.0)))
    else:
        pbo = math.pi / order
        b1 = 1.0 / sinhg
        factors.append(Chebyshev1Filter.Polynomial((b1 * k, 1.0)))
        for i in range(2, (order + 1) // 2 + 1):
            b2 = 1.0 / (cosh2g - (math.cos((i - 1) * pbo) ** 2))
            b1 = 2.0 * b2 * sinhg * math.cos((i - 1) * pbo)
            factors.append(Chebyshev1Filter.Polynomial((b2 * k2, b1 * k, 1.0)))
    return ~Chebyshev1Filter.Product(factors=factors, transform=highpass)
Пример #19
0
  def zetainv(self, taup, lam):
    psi = math.asinh(taup)
    
    scal = 1.0 / math.hypot(1.0, taup);

    (u, v, flag) = self.zetainv0(psi, lam)
    if flag:
      return [u, v]

    stol2 = self.tolerance2 / max(psi, 1.0)**2.0
    # min iterations = 2, max iterations = 6; mean = 4.0
    trip = 0
    
    for i in range(100):
      (snu, cnu, dnu, ph) = ellipj(u, self.mu)
      (snv, cnv, dnv, ph) = ellipj(v, self.mv)
      (tau1, lam1) =  self.zeta(snu, cnu, dnu, snv, cnv, dnv);
      (du1, dv1) = self.dwdzeta(snu, cnu, dnu, snv, cnv, dnv)
      
      tau1 -= taup;  lam1 -= lam;
      tau1 *= scal;
      delu = tau1 * du1 - lam1 * dv1
      delv = tau1 * dv1 + lam1 * du1
      u -= delu;  v -= delv;
      if trip > 0:
        break;
      delw2 = delu*delu + delv*delv;
      if delw2 < stol2 :
        trip += 1
    return [u, v]
Пример #20
0
    def eccentric_anomaly(self, time):
        """Eccentric anomaly at a given time (s)"""
        M = self.mean_anomaly(time)
        e = self.eccentricity

        if e < 1:  # M = E - e sin E
            M %= (2*math.pi)

            # sin(E) = E -> M = (1 - e) E
            if abs(M) < 2**-26:
                return M / (1 - e)

            return analysis.newton_raphson(
                x_0=math.pi,
                f=lambda E: E - e*math.sin(E) - M,
                f_prime=lambda E: 1 - e*math.cos(E),
            )
        else:  # M = e sinh E - E
            # sinh(E) = E -> M = (e - 1) E
            if abs(M) < 2**-26:
                return M / (e - 1)

            return analysis.newton_raphson(
                x_0=math.asinh(M),
                f=lambda E: e*math.sinh(E) - E - M,
                f_prime=lambda E: e*math.cosh(E) - 1,
            )
Пример #21
0
def hyperbolic_fun_cal(inp_val1, opn_type):
     oprn_dic = {
        '1': 'inverse hyperbolic cosine of x', '2':'inverse hyperbolic sine of x',
        '3':' inverse hyperbolic tangent of x', '4':'hyperbolic cosine of x',
        '5':'hyperbolic sine of x', '6':'hyperbolic tangent of x'}
     if int(opn_type) == 1:
         output = math.acosh(float(inp_val1))
         return str(output)
     if int(opn_type) == 2:
         output = math.asinh(float(inp_val1))
         return str(output)
     if int(opn_type) == 3:
         output = math.atanh(float(inp_val1))
         return str(output)
     if int(opn_type) == 4:
         output = math.cosh(float(inp_val1))
         return str(output)
     if int(opn_type) == 5:
         output = math.sinh(float(inp_val1))
         return str(output)
     if int(opn_type) == 6:
         output = math.tanh(float(inp_val1))
         return str(output)
     else:
         return "Invalid Operation"
Пример #22
0
    def sinh_effective_mass_errors(self, dt, fast=True, period=None):
        if fast: logging.info("sinh emass computed fast method")

        T = self.period_check(period)

        jkasv = self.jackknife_average_sub_vev()
        jkemass = {}
        for cfg in self.configs:
            asvc = jkasv[cfg]
            emass = {}
            for t in self.times[dt:-dt]:
                if t in self.emass_skip_times:
                    emass[t] = 0.0
                    continue
                try:
                    guess = (1.0 / float(dt))*math.asinh((asvc[t+dt] + asvc[t-dt])/(2.0*asvc[t]))
                    if fast:
                        emass[t] = guess
                    else:
                        emass[t] = newton.newton_sinh_for_m(t,t+dt,asvc, guess, T)
                except ValueError:
                    #logging.debug("invalid argument to log, setting to zero")
                    emass[t] = 0.0
                except ZeroDivisionError:
                    logging.debug("div by zero, setting to zero")
                    emass[t] = 0.0
                except KeyError:
                    logging.error("index out of range")
            jkemass[cfg] = emass
        jkemassobj = configtimeobj.Cfgtimeobj.fromDataDict(jkemass)
        effmass_dt = self.sinh_effective_mass(dt, fast=fast, period=T)
        return {t: jackknife.errorbars(effmass_dt[t], jkemassobj.get(time=t))
                for t in self.times[dt:-dt]}
Пример #23
0
 def calculateLockTime(self, radius):
     scanRes = self.ship.getModifiedItemAttr("scanResolution")
     if scanRes is not None and scanRes > 0:
         # Yes, this function returns time in seconds, not miliseconds.
         # 40,000 is indeed the correct constant here.
         return min(40000 / scanRes / asinh(radius)**2, 30*60)
     else:
         return self.ship.getModifiedItemAttr("scanSpeed") / 1000.0
Пример #24
0
	def get_x_by_s(self, x0, s):
		"""get_x_by_s(self, x0, s) -> x

		Gives x such that self.arc_length(x0, x) == s.
		"""
		s += self.arc_length_indef(x0)
		x = self.xm + self.a * math.asinh(s / self.a)
		return x
Пример #25
0
def asinh(space, d):
    """ asinh - Inverse hyperbolic sine """
    try:
        return space.wrap(math.asinh(d))
    except OverflowError:
        return space.wrap(rfloat.INFINITY)
    except ValueError:
        return space.wrap(rfloat.NAN)
Пример #26
0
 def _getxy(self, coords, zoom):
     n = 2**zoom
     lat = coords[1] * pi / 180.0
     lon = coords[0] * pi / 180.0
     yp = math.asinh(math.tan(lat))
     x = int(floor((1 + (lon / pi)) / 2 * n))
     y = int(floor((1 - (yp / pi)) / 2 * n))
     return x, y
Пример #27
0
def calculateMprime(k):
    """
    Wyznacza odległość m' od środka cięgna do miejsca osiągnięcia ekstremum
    przez funkcję zwisu
    :param k:
    :return:
    """
    return k * math.asinh(SPAD_B / SPAN_A)
Пример #28
0
	def from_x0y0ddd(x0, y0, d, dd):
		"""from_x0y0ddd(x0, y0, d, dd) -> Catenary

		The returned catenary passes through the given point with derivative d, and second derivative dd.
		"""
		# FullSimplify[Solve[catenary == y0 && D[catenary, x] == d && D[catenary, {x, 2}] == dd, {xm, ym, a}, Reals]]
		a = (1 + d**2)**0.5 / dd
		xm = x0 - (1 + d**2)**0.5 * math.asinh(d) / dd
		ym = y0 - (1 + d**2.0) / dd
		return Catenary(xm, ym, a)
Пример #29
0
def calculateM(k):
    """
    Wylicza wielkość mimośrodu m [m] na podstawie parametru
    lini zwisu k [m]

    :param k: parametr lini zwisu [m]
    :return: wartośc mimośrodu [m]
    """
    m = k * math.asinh(SPAD_B / (2 * k * math.sinh(SPAN_A / (2 * k))))
    return m
Пример #30
0
def tileXY(latitude, longitude, zoom):
	x = longitude * math.pi / 180.0;
	y = math.asinh(math.tan(latitude * math.pi / 180.0))

	# In Google Maps projected sphere is the square [-pi..pi]x[-pi..pi]
	# This square is then divided on (2^zoom)x(2^zoom) tiles. Tile
	# coordinates are counting from upper left corner of the grid.
	x = (x / math.pi / 2.0 + 0.5) * 2**zoom
	y = (-y/ math.pi / 2.0 + 0.5) * 2**zoom
	return (int(x), int(y))
Пример #31
0
# of dimension [Nx columns] by [Ny rows]
u = np.zeros([Ny, Nx])
v = np.zeros([Ny, Nx])
# u is a 2D array of nondimensional x-velocities at all spatial locations
# v is a 2D array of nondimensional y-velocities at all spatial locations

# %% Apply boundary conditions to u matrix

# Set u(x, 0) to be 0 from no-slip boundary condition
u[0, :] = 0  # Set 0th row, all columns to be 0

# Set u(x, 1) to be 1 from Dirichlet boundary condition
u[-1, :] = 1  # Set last row, all columns to be 1

# Set u(0, eta) to starting profile
etaY1 = asinh(
    1 * sinh(s) / yMax) / s  # Determine eta value corresponding to y = 1
for n in range(len(y)):
    # u(0, y <= 1) = sin(pi*y/2)
    if eta[n] <= etaY1:
        u[n, 0] = sin(pi * y[n] / 2)
    # u(0, y > 1) = 1
    elif y[n] > etaY1:
        u[n, 0] = 1

# %% Apply boundary condition to v matrix
# Set v(x, eta=0) to be 0 from impermeable wall condition
v[0, :] = 0

# %% Loop over each x-step
for i in range(len(x) - 1):
    # Set up matrix and RHS "b" matrix (knowns)
Пример #32
0
    def ejecutar(self, ts = None):            
        if self.parametro2 != None: # 2 PARAMETROS
            nodoSyn1 = self.parametro1.ejecutar(ts)
            if isinstance(nodoSyn1 , ErrorReport):
                return nodoSyn1
            nodoSyn2 = self.parametro2.ejecutar(ts)
            if isinstance(nodoSyn2 , ErrorReport):
                return nodoSyn2

            if isinstance(nodoSyn1 , ExpresionNumero) and isinstance(nodoSyn2 , ExpresionNumero):
                
                if self.funcion == "ATAN2":
                    rads = math.atan2(nodoSyn1.val,nodoSyn2.val)
                    return ExpresionNumero(rads,self.getTipo(rads),self.linea) 
                
                if self.funcion == "ATAN2D":
                    rads = math.atan2(nodoSyn1.val,nodoSyn2.val)
                    grados = (rads * 180/math.pi)
                    return ExpresionNumero(grados,self.getTipo(grados),self.linea)
                
                if self.funcion == "DIV":
                    
                    izq = nodoSyn1.val
                    der = nodoSyn2.val
                    if der == 0:
                        return ErrorReport('semantico', 'error DIVISION entre 0' ,self.linea)
                    valor = izq/der
                    return ExpresionNumero(valor,self.getTipo(valor),self.linea)
                
                if self.funcion =="GCD":
                    valor = math.gcd(nodoSyn1.val , nodoSyn2.val)
                    return ExpresionNumero(valor,self.getTipo(valor),self.linea)
                
                if self.funcion =="MOD":
                    try:
                        valor = (nodoSyn1.val % nodoSyn2.val)
                        return ExpresionNumero(valor,self.getTipo(valor),self.linea)                  
                    except:
                        return ErrorReport('semantico', 'error en MODULO' ,self.linea) 
                
                if self.funcion =="POWER":
                    try:
                        valor = (nodoSyn1.val ** nodoSyn2.val)
                        return ExpresionNumero(valor,self.getTipo(valor),self.linea)                  
                    except:
                        return ErrorReport('semantico', 'error en MODULO' ,self.linea)
                
                if self.funcion =="ROUND":
                    valor = round(nodoSyn1.val , nodoSyn2.val)
                    return ExpresionNumero(valor,self.getTipo(valor),self.linea)
                
                if self.funcion == "TRUNC": 
                    if self.getTipo(nodoSyn2.val) != TIPO_DE_DATO.ENTERO:
                        return ErrorReport('semantico', 'error en Metodo TRUNC el segundo parametro tiene que ser un entero' ,self.linea)
                    cadenaInt = str(nodoSyn1.val)
                    numero_truncado = ''
                    indice = 0
                    decimalesAdjuntados = 0
                    for i in range(len(cadenaInt)):
                        if cadenaInt[i] == '.':
                            numero_truncado += cadenaInt[i]
                            indice = i
                            break
                        else:
                            numero_truncado += cadenaInt[i]
                    indice+=1        
                    while(decimalesAdjuntados < nodoSyn2.val):
                        
                        if  indice < len(cadenaInt):
                            numero_truncado += cadenaInt[indice]
                        else:
                            numero_truncado += '0'
                        
                        indice+=1
                        decimalesAdjuntados+=1
                    valor = float(numero_truncado)
                    return ExpresionNumero(valor,self.getTipo(valor),self.linea) 
                    
                        
                    
                    

                    
                    
            
            else:
                return ErrorReport('semantico', 'error de tipo, se esperaba un ENTERO O DECIMAL' ,self.linea)
        elif self.parametro1 != None: # 1 PARAMETRO
            
            if  isinstance(self.parametro1,list):
                if self.funcion =="WIDTH_BUCKET":
                    return self.metodo_width_bucket(self.parametro1,ts)
            
            
            nodoSyn1 = self.parametro1.ejecutar(ts)
            if isinstance(nodoSyn1 , ErrorReport):
                return nodoSyn1
            
            if isinstance(nodoSyn1 , ExpresionNumero): # decimales y eneteros
                if self.funcion == "ACOS": # RADIANEES
                    if nodoSyn1.val > 1 or nodoSyn1.val < 1:
                        return ErrorReport('semantico', 'Error en ACOS ,el parametro debe estar entre -1 y 1' ,self.linea)   
                    return ExpresionNumero(math.acos(nodoSyn1.val),self.getTipo(nodoSyn1.val),self.linea)
                
                if self.funcion == "ACOSD": # GRADOS 
                    if nodoSyn1.val > 1 or nodoSyn1.val < 1:
                        return ErrorReport('semantico', 'Error en ACOSD , el parametro debe estar entre -1 y 1' ,self.linea)   
                    rads = math.acos(nodoSyn1.val)
                    grados = (rads * 180/math.pi)
                    return ExpresionNumero(grados,self.getTipo(grados),self.linea)
                
                if self.funcion == "ASIN":
                    if nodoSyn1.val > 1 or nodoSyn1.val < 1:
                        return ErrorReport('semantico', 'Error en ASIN ,el parametro debe estar entre -1 y 1' ,self.linea)   
                    valor = math.asin(nodoSyn1.val)
                    return ExpresionNumero(valor,self.getTipo(valor),self.linea)
                
                if self.funcion == "ASIND":
                    if nodoSyn1.val > 1 or nodoSyn1.val < 1:
                        return ErrorReport('semantico', 'Error en ASIND ,el parametro debe estar entre -1 y 1' ,self.linea)   
                    rads = math.asin(nodoSyn1.val)
                    grados = (rads * 180/math.pi)
                    return ExpresionNumero(grados,self.getTipo(grados),self.linea)
                
                if self.funcion == "ATAN":
                    try:
                        rads = math.atan(nodoSyn1.val)
                        return ExpresionNumero(rads,self.getTipo(rads),self.linea)
                    except:
                        return ErrorReport('semantico', 'Error en ATAN por el valor del parametro ' ,self.linea)

                if self.funcion == "ATAND":    
                    try:
                        rads = math.atan(nodoSyn1.val)
                        grados = (rads * 180/math.pi)
                        return ExpresionNumero(grados,self.getTipo(grados),self.linea)
                    except:
                        return ErrorReport('semantico', 'Error en ATAND por el valor del parametro ' ,self.linea)

                if self.funcion == "COS":
                    valor = math.cos(nodoSyn1.val)
                    return ExpresionNumero(valor,self.getTipo(valor),self.linea)
                
                if self.funcion == "COSD":
                    rads = math.cos(nodoSyn1.val)
                    grados = (rads * 180/math.pi)
                    return ExpresionNumero(grados,self.getTipo(grados),self.linea)
                
                if self.funcion == "COT":
                    tangente=math.tan(nodoSyn1.val)
                    if tangente == 0:
                        return ErrorReport('semantico', 'Error en COT por el valor del parametro ' ,self.linea)
                    cot = 1 / tangente   
                    return ExpresionNumero(cot,self.getTipo(cot),self.linea)
                
                if self.funcion == "COTD":
                    tangente=math.tan(nodoSyn1.val)
                    if tangente == 0:
                        return ErrorReport('semantico', 'Error en COTD por el valor del parametro ' ,self.linea)
                    cot =math.degrees(1 / tangente)    
                    return ExpresionNumero(cot,self.getTipo(cot),self.linea)  

                if self.funcion == "SIN":
                    radianes=math.sin(nodoSyn1.val)
                    return ExpresionNumero(radianes,self.getTipo(radianes),self.linea)  
            
                if self.funcion == "SIND":
                    grados=math.degrees(math.sin(nodoSyn1.val))
                    return ExpresionNumero(grados,self.getTipo(grados),self.linea)
            
                if self.funcion == "TAN":
                    try:
                        radianes=math.tan(nodoSyn1.val)
                        return ExpresionNumero(radianes,self.getTipo(radianes),self.linea) 
                    except:
                        return ErrorReport('semantico', 'Error en TAN por el valor del parametro ' ,self.linea)

                if self.funcion == "TAND":
                    try:
                        grados=math.degrees(math.tan(nodoSyn1.val))
                        return ExpresionNumero(grados,self.getTipo(grados),self.linea) 
                    except:
                        return ErrorReport('semantico', 'Error en TAND por el valor del parametro ' ,self.linea)
                
                if self.funcion == "COSH":
                    try:
                        valor=math.cosh(nodoSyn1.val)
                        return ExpresionNumero(valor,self.getTipo(valor),self.linea) 
                    except:
                        return ErrorReport('semantico', 'Error en COSH por el valor del parametro ' ,self.linea)
                    
                
                if self.funcion == "SINH":
                    try:
                        valor=math.sinh(nodoSyn1.val)
                        return ExpresionNumero(valor,self.getTipo(valor),self.linea) 
                    except:
                        return ErrorReport('semantico', 'Error en SINH por el valor del parametro ' ,self.linea)
                    
                if self.funcion == "TANH":
                    try:
                        valor=math.tanh(nodoSyn1.val)
                        return ExpresionNumero(valor,self.getTipo(valor),self.linea) 
                    except:
                        return ErrorReport('semantico', 'Error en TANH por el valor del parametro ' ,self.linea)
                    
                    
                if self.funcion == "ACOSH":
                    if nodoSyn1.val < 1:
                        return ErrorReport('semantico', 'Error en ACOSH, el parametro debe de ser mayor o igual a 1 ' ,self.linea)
                    valor=math.acosh(nodoSyn1.val)
                    return ExpresionNumero(valor,self.getTipo(valor),self.linea)
                
                if self.funcion == "ASINH":
                    valor=math.asinh(nodoSyn1.val)
                    return ExpresionNumero(valor,self.getTipo(valor),self.linea)
                
                if self.funcion == "ATANH":
                    if nodoSyn1.val > 0.99 or nodoSyn1.val < -0.99:
                        return ErrorReport('semantico', 'Error en ATANH, el parametro debe estar entre 0.99 y -0.99 ' ,self.linea)
                    valor=math.atanh(nodoSyn1.val)
                    return ExpresionNumero(valor,self.getTipo(valor),self.linea)
                
                #_________________________________ fin de trigonometricas
                
                if self.funcion == "ABS":
                    valor=math.fabs(nodoSyn1.val)                    
                    return ExpresionNumero(valor,self.getTipo(valor),self.linea)

                    
                if self.funcion == "CBRT": #RAIZ CUBICA SOLO PARA ENTREROS
                    if (nodoSyn1.val) < 0 :
                        return ErrorReport('semantico', 'error SQRT solo recibe enteros POSITIVOS :D' ,self.linea)
                    if (nodoSyn1.val % 1) == 0:
                        valor = nodoSyn1.val**(1/3)
                        return ExpresionNumero(valor,self.getTipo(valor),self.linea)  
                    else:
                        return ErrorReport('semantico', 'error CBRT solo recibe enteros, NO decimales' ,self.linea)
                
                if self.funcion =="CEIL" or self.funcion == "CEILING":
                    valor = math.ceil(nodoSyn1.val)
                    return ExpresionNumero(valor,self.getTipo(valor),self.linea)
                
                if self.funcion =="DEGREES":
                    valor = math.degrees(nodoSyn1.val)
                    return ExpresionNumero(valor,self.getTipo(valor),self.linea)
                
                if self.funcion =="FACTORIAL":
                    valor = math.factorial(nodoSyn1.val)
                    return ExpresionNumero(valor,self.getTipo(valor),self.linea)
                
                if self.funcion =="FLOOR":# POR SI VIENE EN UN INSERT  
                    valor = math.floor(nodoSyn1.val)
                    return ExpresionNumero(valor,self.getTipo(valor),self.linea)
                
                                
                if self.funcion =="LN":
                    try:
                        valor = math.log(nodoSyn1.val)
                        return  ExpresionNumero(valor,self.getTipo(valor),self.linea)
                    except :
                        return ErrorReport('semantico', 'error en el paramtro de LN' ,self.linea)

                
                if self.funcion =="LOG":
                    try:
                        valor = math.log10(nodoSyn1.val)
                        return  ExpresionNumero(valor,self.getTipo(valor),self.linea)    
                    except :
                        return ErrorReport('semantico', 'error en el paramtro de LOG' ,self.linea)
                
                if self.funcion =="EXP":
                    try:
                        valor = math.exp(nodoSyn1.val)
                        return  ExpresionNumero(valor,self.getTipo(valor),self.linea)    
                    except :
                        return ErrorReport('semantico', 'error en el paramtro de EXP' ,self.linea) 
                    
                if self.funcion =="RADIANS":
                    valor = math.radians(nodoSyn1.val)
                    return ExpresionNumero(valor,self.getTipo(valor),self.linea)

                if self.funcion =="ROUND":
                    valor = round(nodoSyn1.val)
                    return ExpresionNumero(valor,self.getTipo(valor),self.linea)
                    
                if self.funcion =="SIGN":
                    if nodoSyn1.val > 0:
                        valor = 1
                        return ExpresionNumero(valor,TIPO_DE_DATO.ENTERO,self.linea)
                    if nodoSyn1.val < 0:
                        valor = -1
                        return ExpresionNumero(valor,TIPO_DE_DATO.ENTERO,self.linea)
                    else:
                        return ErrorReport('semantico', 'error en funcion SING , EL 0 no tiene signo ' ,self.linea)
                if self.funcion == "SQRT":
                    if (nodoSyn1.val) < 0 :
                        return ErrorReport('semantico', 'error SQRT solo recibe enteros POSITIVOS' ,self.linea)
                    if (nodoSyn1.val % 1) == 0:
                        valor = nodoSyn1.val**(1/2)
                        return ExpresionNumero(valor,self.getTipo(valor),self.linea)  
                    else:
                        return ErrorReport('semantico', 'error SQRT solo recibe enteros, NO decimales' ,self.linea)
                
                if self.funcion == "TRUNC":
                    valor = math.trunc(nodoSyn1.val)
                    return ExpresionNumero(valor,TIPO_DE_DATO.ENTERO,self.linea)
 
                
                    
                    

            else:
                return ErrorReport('semantico', 'error de tipo, se esperaba un ENTERO O DECIMAL' ,self.linea)    
                
        
        else:# SIN PARAMETROS
            
            if self.funcion == 'PI':
                return ExpresionNumero(math.pi,TIPO_DE_DATO.DECIMAL,self.linea)
            elif self.funcion == "RANDOM":
                valor = random.choice((1,0))
                return ExpresionNumero(valor,TIPO_DE_DATO.ENTERO,self.linea)
Пример #33
0
def asinh(x):
    return math.asinh(x)
Пример #34
0
def ExactSolution(xL):
    Term1 = m.sqrt((xL - L)**2 + 1) - xL * m.asinh(xL - L)  # z = L
    Term2 = m.sqrt((xL - 0)**2 + 1) - xL * m.asinh(xL - 0)  # z = 0
    return Term1 - Term2
Пример #35
0
import math

x = math.pi

a = math.acos(x)
b = math.acosh(x)
c = math.asin(x)
d = math.asinh(x)
e = math.atan(x)
f = math.atan2(x, a)
g = math.atanh(x)
h = math.ceil(x)
i = math.copysign(x, f)
j = math.cos(x)
k = math.cosh(x)
l = math.degrees(x)
m = math.erf(x)
n = math.erfc(x)
o = math.exp(x)
p = math.expm1(x)
q = math.fabs(x)
r = math.factorial(math.floor(x))
s = math.fmod(x, n)
t, u = math.frexp(x)
v = math.fsum([a, b, c, d])
w = math.gamma(x)
gcd = math.gcd(r, u)
y = math.hypot(x, a)
z = math.isclose(x, y)
aa = math.isclose(x, y)
ab = math.isfinite(x)
Пример #36
0
 def get_dist_pct(self, pct):
     # calculate inverse of dist fn
     val_inv = math.asinh(self.nonlinearity * pct) / self.factor
     val = min(max(float(val_inv), 0.0), 1.0)
     return val
def _intSecAtan(x):
    # In : sympy.integrate(sp.sec(sp.atan(x)))
    # Out: x*sqrt(x**2 + 1)/2 + asinh(x)/2
    return x * math.sqrt(x**2 + 1) / 2 + math.asinh(x) / 2
Пример #38
0
def math_asinh(A, B):
    i = cuda.grid(1)
    B[i] = math.asinh(A[i])
Пример #39
0
 param_dct["param_1"] + param_dct["param_2"] * 30.0 - param_dct["param_5"],
 (param_dct["param_1"] + 1) / param_dct["param_2"],
 math.sqrt(param_dct["param_2"]),
 math.fmod(param_dct["param_4"], param_dct["param_1"]),
 math.sin(param_dct["param_7"]),
 math.cos(param_dct["param_7"]),
 math.tan(param_dct["param_7"]),
 math.asin(param_dct["param_7"]),
 math.acos(param_dct["param_7"]),
 math.atan(param_dct["param_7"]),
 math.atan2(param_dct["param_7"], 2.0),
 math.hypot(3.0, 4.0),
 math.sinh(param_dct["param_7"]),
 math.cosh(param_dct["param_7"]),
 math.tanh(param_dct["param_7"]),
 math.asinh(param_dct["param_7"]),
 math.acosh(param_dct["param_2"]),
 math.atanh(param_dct["param_7"]),
 math.degrees(math.radians(param_dct["param_7"])),
 math.log(param_dct["param_3"]),
 math.log10(param_dct["param_3"]),
 math.log2(param_dct["param_3"]),
 math.fabs(param_dct["param_5"]),
 math.ceil(param_dct["param_5"]),
 math.floor(param_dct["param_5"]),
 round(param_dct["param_5"]),
 math.exp(param_dct["param_1"]),
 2.0 * math.e,
 math.pi + 1,
 2.0,
 param_dct["param_5"] % param_dct["param_6"],
Пример #40
0
    def f_asinh(x: (int, float)):
        """Inverse Hyperbolic Sine"""

        return math.asinh(x)
Пример #41
0
 def test_gh1284(self):
     import math
     self.assertEqual(round(math.asinh(4.),12),round(math.log(math.sqrt(17.)+4.),12))
     self.assertEqual(round(math.asinh(.4),12),round(math.log(math.sqrt(1.16)+.4),12))
     self.assertEqual(round(math.asinh(-.5),12),round(math.log(math.sqrt(1.25)-.5),12))
     self.assertEqual(round(math.asinh(-6.),12),round(math.log(math.sqrt(37.)-6.),12))
Пример #42
0
 def ppf(r, k, l, s, q):
     return s * math.asinh(-math.log((math.pow(q, -1 / r) - 1) / k)) + l
Пример #43
0
 def eta(self):
     return math.asinh(self.z / math.sqrt(self.x**2 + self.y**2))
Пример #44
0
def coords2tilexy(lat_deg, lon_deg, zoom):
    lat_rad = math.radians(lat_deg)
    n = 2.0**zoom
    xtile = int((lon_deg + 180.0) / 360.0 * n)
    ytile = int((1.0 - math.asinh(math.tan(lat_rad)) / math.pi) / 2.0 * n)
    return (xtile, ytile)
Пример #45
0
 def acaSchroeder_scalar(f):
     return 7 * math.asinh(f / 650)
Пример #46
0
    def FunctionWithOneParameter(self, funcion, parametros, exp):
        if (parametros == 1):
            if (funcion == "abs"):
                if (exp < 0):
                    return exp * -1
                else:
                    return exp
            elif (funcion == "cbrt"):
                return math.pow(exp, 3)
            elif (funcion == "ceil"):
                return math.ceil(exp)
            elif (funcion == "ceiling"):
                return math.ceil(exp)
            elif (funcion == "degrees"):
                return math.degrees(exp)
            elif (funcion == "exp"):
                return math.exp(exp)
            elif (funcion == "factorial"):
                return math.factorial(exp)
            elif (funcion == "floor"):
                return math.floor(exp)
            elif (funcion == "ln"):
                return math.log(exp)
            elif (funcion == "log"):
                return math.log10(exp)
            elif (funcion == "radians"):
                return math.radians(exp)
            elif (funcion == "sing"):
                if (exp > 0):
                    return 1
                else:
                    return -1
            elif (funcion == "sqrt"):
                return math.sqrt(exp)
            elif (funcion == "trunc"):
                return math.trunc(exp)
            elif (funcion == "acos"):
                return math.acos(exp)
            elif (funcion == "acosd"):
                return math.degrees(math.acos(exp))
            elif (funcion == "asin"):
                return math.asin(exp)
            elif (funcion == "asind"):
                return math.degrees(math.asin(exp))
            elif (funcion == "atan"):
                return math.atan(exp)
            elif (funcion == "atand"):
                return math.degrees(math.atan(exp))
            elif (funcion == "cos"):
                return math.cos(exp)
            elif (funcion == "cosd"):
                return math.degrees(math.cos(exp))
            elif (funcion == "cot"):
                return (1 / math.tan(exp))
            elif (funcion == "cotd"):
                return math.degrees(1 / math.tan(exp))
            elif (funcion == "sin"):
                return math.sin(exp)
            elif (funcion == "sind"):
                return math.degrees(math.sin(exp))
            elif (funcion == "sin"):
                return math.sin(exp)
            elif (funcion == "sind"):
                return math.degrees(math.sin(exp))
            elif (funcion == "tan"):
                return math.tan(exp)
            elif (funcion == "tand"):
                return math.degrees(math.tan(exp))
            elif (funcion == "sinh"):
                return math.sinh(exp)
            elif (funcion == "cosh"):
                return math.cosh(exp)
            elif (funcion == "tanh"):
                return math.tanh(exp)
            elif (funcion == "asinh"):
                return math.asinh(exp)
            elif (funcion == "acosh"):
                return math.acosh(exp)
            elif (funcion == "atanh"):
                return math.atanh(exp)
            elif (funcion == "length"):
                leng = len(exp)
                return leng
            elif (funcion == "md5"):
                m = exp
                result = hashlib.md5(m.encode())
                return result.hexdigest()
            elif (funcion == "sha256"):
                m = exp
                result = hashlib.sha256(m.encode()).hexdigest()
                return result
            elif (funcion == "convert"):
                print("convert")

        else:
            reporteerrores.append(
                Lerrores("Error Semantico",
                         "La funcion" + funcion + "solo recibe 2 parametros",
                         0, 0))
            return "Error: La funcion: " + funcion + " recibe un parametro"
Пример #47
0
def run_arcsinh_test():
    # for x in [-100000, -1000, -10, -1, 0, 1, 10, 1000, 1000000]:
    for x in [-100, -10, -1, 0, 1, 10, 100]:
        print("Doing arcsinh({})".format(x))
        assert_close(asinh(x), Arcsinh(x), "arcsinh({})".format(x))
Пример #48
0
def f(p):
    x, y, z = abs(p[0]), abs(p[1]), abs(p[2])
    return + y / 2.0 * (z**2 - x**2) * asinh(y / (sqrt(x**2 + z**2) + eps)) \
           + z / 2.0 * (y**2 - x**2) * asinh(z / (sqrt(x**2 + y**2) + eps)) \
           - x*y*z * atan(y*z / (x * sqrt(x**2 + y**2 + z**2) + eps))       \
           + 1.0 / 6.0 * (2*x**2 - y**2 - z**2) * sqrt(x**2 + y**2 + z**2)
Пример #49
0
def geo_utm(lat, lon):

    a, f = 6378137.0, 1 / 298.257223563  #datum WGS84 and flatening
    ko = 0.9996  # UTM scale factor on the central meridian
    ns = 'N'
    ew = 'E'

    # identifying North or South
    if lat < 0:
        ns = 'S'
        lat = abs(lat)

    # identifying East or West and calculating meridian centre
    if lon < 0:
        bo = int(lon / 6) * 6 - 3  # for western
        ew = 'W'
    else:
        bo = int(lon / 6) * 6 + 3  # for eastern

    # Converting to radians
    λo = radians(bo)
    φ = radians(lat)
    λ = radians(lon) - λo

    #computtion
    e = sqrt(f * (2 - f))

    n = f / (2 - f)
    n2 = n * n
    n3 = n2 * n
    n4 = n3 * n
    n5 = n4 * n
    n6 = n5 * n
    n7 = n6 * n
    n8 = n7 * n

    cosλ = cos(λ)
    sinλ = sin(λ)
    tanλ = tan(λ)

    τ = tan(φ)
    σ = sinh(e * atanh(e * τ / sqrt(1 + τ * τ)))
    τ1 = τ * sqrt(1 + σ * σ) - σ * sqrt(1 + τ * τ)
    ξ1 = atan2(τ1, cosλ)
    η1 = asinh(sinλ / sqrt(τ1 * τ1 + cosλ * cosλ))

    A = a / (1 + n) * (1 + 1 / 4 * n2 + 1 / 64 * n4 + 1 / 256 * n6 +
                       25 / 16384 * n8)

    α1 = 1 / 2 * n - 2 / 3 * n2 + 5 / 16 * n3 + 41 / 180 * n4 - 127 / 288 * n5 + 7891 / 37800 * n6 + 72161 / 387072 * n7 - 18975107 / 50803200 * n8
    α2 = 13 / 48 * n2 - 3 / 5 * n3 + 557 / 1440 * n4 + 281 / 630 * n5 - 1983433 / 1935360 * n6 + 13769 / 28800 * n7 + 148003883 / 174182400 * n8
    α3 = 61 / 240 * n3 - 103 / 140 * n4 + 15061 / 26880 * n5 + 167603 / 181440 * n6 - 67102379 / 29030400 * n7 + 79682431 / 79833600 * n8
    α4 = 49561 / 161280 * n4 - 179 / 168 * n5 + 6601661 / 7257600 * n6 + 97445 / 49896 * n7 + 40176129013 / 7664025600 * n8
    α5 = 34729 / 80640 * n5 - 3418889 / 1995840 * n6 + 14644087 / 9123840 * n7 + 2605413599 / 622702080 * n8
    α6 = 212378941 / 319334400 * n6 - 30705481 / 10378368 * n7 + 175214326799 / 58118860800 * n8
    α7 = 1522256789 / 1383782400 * n7 - 16759934899 / 3113510400 * n8
    α8 = 1424729850961 / 743921418240 * n8

    ξ = ξ1 + α1 * sin(2 * ξ1) * cosh(2 * η1) + α2 * sin(4 * ξ1) * cosh(
        4 * η1) + α3 * sin(6 * ξ1) * cosh(6 * η1) + α4 * sin(8 * ξ1) * cosh(
            8 * η1) + α5 * sin(10 * ξ1) * cosh(10 * η1) + α6 * sin(
                12 * ξ1) * cosh(12 * η1) + α7 * sin(14 * ξ1) * cosh(
                    14 * η1) + α8 * sin(16 * ξ1) * cosh(16 * η1)
    η = η1 + α1 * cos(2 * ξ1) * sinh(2 * η1) + α2 * cos(4 * ξ1) * sinh(
        4 * η1) + α3 * cos(6 * ξ1) * sinh(6 * η1) + α4 * cos(8 * ξ1) * sinh(
            8 * η1) + α5 * cos(10 * ξ1) * sinh(10 * η1) + α6 * cos(
                12 * ξ1) * sinh(12 * η1) + α7 * cos(14 * ξ1) * sinh(
                    14 * η1) + α8 * cos(16 * ξ1) * sinh(16 * η1)

    # UTM Coordinate
    x = 500000 + ko * A * η
    y = ko * A * ξ
    if (ns == 'S'):
        y = 10000000 - y

    # UTM Meridian Convergency
    p1 = 1
    q1 = 0
    p1 = p1 + 2 * α1 * cos(2 * ξ1) * cosh(2 * η1) + 4 * α2 * cos(
        4 * ξ1) * cosh(4 * η1) + 6 * α3 * cos(6 * ξ1) * cosh(
            6 * η1) + 8 * α4 * cos(8 * ξ1) * cosh(8 * η1) + 10 * α5 * cos(
                10 * ξ1) * cosh(10 * η1) + 12 * α6 * cos(12 * ξ1) * cosh(
                    12 * η1)
    q1 = q1 + 2 * α1 * sin(2 * ξ1) * sinh(2 * η1) + 4 * α2 * sin(
        4 * ξ1) * sinh(4 * η1) + 6 * α3 * sin(6 * ξ1) * sinh(
            6 * η1) + 8 * α4 * sin(8 * ξ1) * sinh(8 * η1) + 10 * α5 * sin(
                10 * ξ1) * sinh(10 * η1) + 12 * α6 * sin(12 * ξ1) * sinh(
                    12 * η1)
    γ1 = atan(τ1 / sqrt(1 + τ1 * τ1) * tanλ)
    γ2 = atan2(q1, p1)
    γ = degrees(γ1 + γ2)
    if ((lon < bo and lat > 0) or (lon > bo and lat < 0)):
        γ = -1 * γ

    # UTM Scale Factor
    sinφ = sin(φ)
    k1 = sqrt(1 - e * e * sinφ * sinφ) * sqrt(1 + τ * τ) / sqrt(τ1 * τ1 +
                                                                cosλ * cosλ)
    k2 = A / a * sqrt(p1 * p1 + q1 * q1)
    k = ko * k1 * k2

    # UTM Zone Number
    zone = round((lon + 180) / 6 + 0.5)

    return (x, y, zone, bo, k, γ)
Пример #50
0
    '+': Operator(2, 1, lambda a, b: [a + b]),
    '-': Operator(2, 1, lambda a, b: [a - b]),
    '^': Operator(2, 1, lambda a, b: [a**b]),
    'sin': Operator(1, 1, lambda a: [math.sin(
        a)]),  #change from (a) to (a*(math.pi/180)) to give answer in degrees
    'cos': Operator(1, 1, lambda a: [math.cos(a)]),
    'tan': Operator(1, 1, lambda a: [math.tan(a)]),
    'sinh': Operator(1, 1, lambda a: [math.sinh(a)]),
    'cosh': Operator(1, 1, lambda a: [math.cosh(a)]),
    'tanh': Operator(1, 1, lambda a: [math.tanh(a)]),
    'exp': Operator(1, 1, lambda a: [math.exp(a)]),
    'sqrt': Operator(1, 1, lambda a: [math.sqrt(a)]),
    'asin': Operator(1, 1, lambda a: [math.asin(a)]),
    'acos': Operator(1, 1, lambda a: [math.acos(a)]),
    'atan': Operator(1, 1, lambda a: [math.atan(a)]),
    'asinh': Operator(1, 1, lambda a: [math.asinh(a)]),
    'acosh': Operator(1, 1, lambda a: [math.acosh(a)]),
    'atanh': Operator(1, 1, lambda a: [math.atanh(a)])
}

OPERATORS = set(['+', '-', '*', '/', '(', ')',
                 '^'])  #establish the operators for infix_to_postfix function
OPERATORS_STRING = [
    'sin', 'cos', 'tan', 'sinh', 'cosh', 'tanh', 'exp', 'sqrt', 'asin', 'acos',
    'atan', 'asinh', 'acosh', 'atanh'
]  #establish the trigonometric, hyperbolic functions
#PRIORITY --> sets the priority of operations for the 'infix_to_postfix' function, according to the BIDMAS rule
PRIORITY = {
    '+': 1,
    '-': 1,
    '*': 2,
Пример #51
0
}

output_step = 20
DEM.dt = dt
DEM.sim_params = sim_params
DEM.particles = particles
inv_sinh = 1.0 / sinh(particles["mu_ref"] / particles["a_tilde"])
DEM.particles["inv_sinh_mu_ref"] = inv_sinh
DEM.saved_data = []

DEM.render_mesh()
# DEM.draw_scene(tri=True)

s = np.zeros_like(t)
mu = np.zeros_like(t)
mu_ss = particles["a_tilde"] * asinh(vy_p[0] /
                                     (particles["vc_ref"] * inv_sinh))

for i in range(len(t)):
    DEM.t = t[i]
    DEM.particles["coords"][1] = x_p[i], y_p[i]
    DEM.particles["v"][1] = vx_p[i], vy_p[i]
    DEM.check_remesh()
    DEM.init_step()
    DEM.update_particle_forces()

    if i % output_step == 0:
        data = {
            "particles": copy.deepcopy(DEM.particles),
            "contacts": copy.deepcopy(DEM.contacts),
        }
        DEM.saved_data.append(data)
Пример #52
0
 def asinh(self):
    # self.result=False
     self.current=math.asinh(float(txtDisplay.get()))
     self.expression = "asinh(" + str(txtDisplay.get()) +")=" + str(self.current)
     self.display(self.expression)
Пример #53
0
math.expml(x)  # $e ^ x-1$
math.log(x)  # xの自然対数
math.log(x, y)  # yを底とする xの対数
math.log1p
math.log2(x)  # 2を底とする xの対数
math.log10(x)  # xの常用対数
math.sqrt(x)  # xの平方根
math.cos(x)  # xの余弦
math.dist(x)  # xとxのユークリッド距離
math.hypot(x, y)  # xとyのノルム
math.sin(x)  # xの正弦
math.tan(x)  # xの正接
math.degrees(x)  # xの角度
math.radians(x)  # xのラジアン
math.acosh(x)  # xの逆双曲線余弦
math.asinh(x)  # xの逆双曲線正弦
math.atanh(x)  # xの逆双曲線正接
math.cosh(x)  # xの双曲線余弦
math.sinh(x)  # xの双曲線正弦
math.tanh(x)  # xの双曲線正接
math.gamma(x)  # xのガンマ関数
math.lgamma(x)  # xのガンマ関数の絶対値の自然対数
math.pi  # 円周率
math.e  # ネイピア数
math.inf  # 無限大
math.nan  # NaN

_マッチする = 'マッチする|含まれる|マッチする'

re.search(x, y)  # x(正規表現)がyにマッチする 最初の位置 -> int
re.match(x, y)  # yに x(正規表現)がマッチするかどうか -> bool
Пример #54
0
 def asinh(self):
     self.result = False
     self.current = math.asinh(float(txtDisplay.get()))
     self.display(self.current)
Пример #55
0
#In this we will see import function 
import math as mt     #importing math to solve complex mathematical operation
import random as rd   #imporing rand to select value randmoly

a=mt.asinh(90)
print(a)

b=rd.randint(100000,900000)
print(b)
Пример #56
0
  def cMathOperations(inputFromUser, outputFromUser):
  # TO OPERATE SIMPLE ARITHMETIC OPERATIONS
    arithmaticOperations = [float(index) for index in inputFromUser.split(' ')]
    if len(arithmaticOperations)>1:
      if (sum(arithmaticOperations)==float(outputFromUser)):
        f= open("Program.c","w+")
        f.write('/*Add this in int main()\n\tfloat variable2;\n\tscanf("%f", &variable2);\n*/\n\n')
        f.close
        function = 'variable1+variable2'
        return str(function)
      elif (float(arithmaticOperations[0]-arithmaticOperations[1])==float(outputFromUser)):
        f= open("Program.c","w+")
        f.write('/*Add this in int main()\n\tfloat variable2;\n\tscanf("%f", &variable2);\n*/\n\n')
        f.close
        function = 'variable1-variable2'
        return str(function)
      elif (float(arithmaticOperations[0]*arithmaticOperations[1])==float(outputFromUser)):
        f= open("Program.c","w+")
        f.write('/*Add this in int main()\n\tfloat variable2;\n\tscanf("%f", &variable2);\n*/\n\n')
        f.close
        function = 'variable1*variable2'
        return str(function)
      elif (float(arithmaticOperations[0]/arithmaticOperations[1])==float(outputFromUser)) or (float(arithmaticOperations[1]/arithmaticOperations[0])==float(outputFromUser)):
        f= open("Program.c","w+")
        f.write('/*Add this in int main()\n\tfloat variable2;\n\tscanf("%f", &variable2);\n*/\n\n')
        f.close
        function = 'variable1/variable2'
        return str(function)
      elif max(arithmaticOperations[0], arithmaticOperations[1])==float(outputFromUser):
        f= open("Program.c","w+")
        f.write('/*Add this in int main()\n\tfloat variable2;\n\tscanf("%f", &variable2);\n*/\n\n')
        f.close
        function = '{ variable1 > variable2 ? variable1:variable2 }'
        return str(function)
      elif min(arithmaticOperations[0], arithmaticOperations[1])==float(outputFromUser):
        f= open("Program.c","w+")
        f.write('/*Add this in int main()\n\tfloat variable2;\n\tscanf("%f", &variable2);\n*/\n\n')
        f.close
        function = '{ variable1 < variable2 ? variable1:variable2 }'
        return str(function)
      else:
        return str('0')

    inputFromUser=float(inputFromUser)
    outputFromUser=float(outputFromUser)
    try:
      while True:
        if (round(inputFromUser**(access_iter.__next__()), 3)==outputFromUser):
          function = 'pow(variable1, '+ str(access_iter.__next__()-1) +')'
          return str(function)
    except:
      pass
    access_iter.reset()
    try:
      while True:
        if (round(outputFromUser**(access_iter.__next__()), 3)==inputFromUser):
          function = 'pow(variable1, '+ str(float(1/(access_iter.__next__()-1))) +')'
          return str(function)
    except:
      pass
    access_iter.reset()
    # REMOVE 1 FROM accessNaturalNumbers to operate log
    try:
      while True:
        base=int(logarithmic_iter.__next__())
        if (math.log(inputFromUser, base)==outputFromUser):
          function = 'log(variable1, '+ str(base) +')'
          return str(function)
    except:
      pass
    if(math.floor(inputFromUser)==outputFromUser):
      return 'floor(variable1)'
    elif(math.ceil(inputFromUser)==outputFromUser):
      return 'ceil(variable1)'
    elif(abs(inputFromUser)==outputFromUser):
      return 'abs(variable1)'
    elif(1/inputFromUser==outputFromUser):
      return '1/variable1'
    elif(round(math.sin(inputFromUser), 2)==outputFromUser):
      return 'sin(variable1)'
    elif(round(math.cos(inputFromUser), 2)==outputFromUser):
      return 'cos(variable1)'
    elif(round(math.tan(inputFromUser), 2)==outputFromUser):
      return 'tan(variable1)'
    elif(round(math.sinh(inputFromUser), 2)==outputFromUser):
      return 'sinh(variable1)'
    elif(round(math.cosh(inputFromUser), 2)==outputFromUser):
      return 'cosh(variable1)'
    elif(round(math.tanh(inputFromUser), 2)==outputFromUser):
      return 'tanh(variable1)'
    elif(round(math.asinh(inputFromUser), 2)==outputFromUser):
      return 'asinh(variable1)'
    elif(round(math.acosh(inputFromUser), 2)==outputFromUser):
      return 'acosh(variable1)'
    elif(round(math.atanh(inputFromUser), 2)==outputFromUser):
      return 'atanh(variable1)'
    else:
      return '0'
def modelo(dr):
    pi = math.pi
    rho_c = 3 * 10**17  #densidad central
    m_n = 1.68 * 10**(-27)  #masa neutron
    h = 6.62 * 10**-34  #constante de planck
    c = 5.9 * 10**8  #velocidad luz
    G = 6.67 * 10**(-11)  #constante universal
    M_sun = 1.989 * 10**(30)
    p_f = ((3 / (8 * pi)) * (rho_c / m_n))**(1.0 / 3) * h  #momento de fermi
    x = float(((p_f)) / (m_n * c))  #x
    e_c = rho_c * c**2

    m = 0.0  #masa inicial
    dm = 0
    dP = 0
    r = 1  #radio inicial

    #listas

    lista_P = []
    lista_E = []
    lista_m = []
    lista_r = []

    E = (((pi * m_n**4 * c**5) / h**3) * ((((x**2) + 1)**0.5 *
                                           (2 * x**3 + x) - math.asinh(x))))
    P = ((pi * m_n**4 * c**5) /
         (3 * h**3)) * ((((x**2) + 1)**0.5 *
                         (2 * x**3 - 3 * x) + 3 * math.asinh(x)))

    while P > 0:

        dP_dr = -(
            (G * (E / c**2.0 + P / c**2.0)) *
            (m + 4.0 * pi * r**3 * P / c**2.0)) / (r * (r - 2 * G * m / c**2))

        dP_dx = (((pi * m_n**4 * c**5) / (3 * h**3)) * ((8 * x**4) /
                                                        (x**2 + 1)**0.5))

        dx = ((dP_dr) / (dP_dx)) * dr

        dP = (((pi * m_n**4 * c**5) / (3 * h**3)) * ((8 * x**4) /
                                                     (x**2 + 1)**0.5)) * dx
        dE_dx = (((pi * m_n**4 * c**5) / h**3) * ((8 * (x**4 + x**2)) /
                                                  (x**2 + 1)**0.5))

        dE = (((pi * m_n**4 * c**5) / h**3) * ((8 * (x**4 + x**2)) /
                                               (x**2 + 1)**0.5)) * dx

        dm = ((4 * pi * E * r**2) / (c**2)) * dr

        x = x + dx
        m = m + dm
        P = P + dP
        r = r + dr
        E = E + dE
        lista_P.append(P)
        lista_m.append(m)
        lista_r.append(r)
        lista_E.append(E)

    return (np.array(lista_P), np.array(lista_m) / M_sun, np.array(lista_r),
            np.array(lista_E) / e_c)
Пример #58
0
def NormalizeColumn(df, formant):
    colIndex = range(1, 22)
    cols = []
    for i in colIndex:
      col = formant + '_' + str(i)
      cols.append(col)
      df[col + '_Z'] = (df[col] - df[formant+ '_mean']) / df[formant+ '_stdev']
    print(cols)

    F_a = []
    F_i = []
    F_u = []
    Z_a = []
    Z_i = []
    Z_u = []
    for _, row in df.iterrows():
        comps = row['Filename'].split('_')
        age_gender = int(row['Filename'].split('_')[2])
        if not age_gender % 2 == 1:  # not male
            continue
        if not comps[0].startswith('norm'):
            continue
        if row['Annotation'] == 'a':
          AddDataPoint(F_a, Z_a, row, cols)
          continue
        if row['Annotation'] == 'i':
          AddDataPoint(F_i, Z_i, row, cols)
          continue
        if row['Annotation'] == 'u':
          AddDataPoint(F_u, Z_u, row, cols)
          continue
    F_bar_a = mean(F_a)
    F_bar_i = mean(F_i)
    F_bar_u = mean(F_u)
    F_bar = mean(F_a + F_i + F_u)
    Z_bar_a = mean(Z_a)
    Z_bar_i = mean(Z_i)
    Z_bar_u = mean(Z_u)
    Z_bar = mean(Z_a + Z_i + Z_u)

    numerator = 0
    numerator += abs(F_bar_a - F_bar)
    numerator += abs(F_bar_i - F_bar)
    numerator += abs(F_bar_u - F_bar)
    denominator = 0
    denominator = abs(Z_bar_a - Z_bar)
    denominator += abs(Z_bar_i - Z_bar)
    denominator += abs(Z_bar_u - Z_bar)
    R = numerator / denominator
    df[formant+'_R'] = R
    for col in cols:
      df[col + '_p'] = df[col + '_Z'] * df[formant + '_R']
    F_p = []
    for _, row in df.iterrows():
        comps = row['Filename'].split('_')
        age_gender = int(row['Filename'].split('_')[2])
        if not age_gender % 2 == 1:  # not male
            continue
        if not comps[0].startswith('norm'):
            continue
        for col in cols:
          F_p.append(float(row[col+'_p']))
    F_p_bar = mean(F_p)
    df[formant+'_bar'] = F_bar
    df[formant+'_p_bar'] = F_p_bar
    for col in cols:
      df[col + '_pp'] = df[col + '_p'] - \
        (df[formant + '_p_bar'] - df[formant + '_bar'])
      df[col + '_pp_bark'] = df[col+'_pp'].apply(lambda x:7 * math.asinh(x/650))
    return df
Пример #59
0
def deg2num(lat_deg, lon_deg, zoom):
    lat_rad = math.radians(lat_deg)
    n = 2.0**zoom
    xtile = (n / 360) * (lon_deg + 180)
    ytile = (n / 2) * (1.0 - math.asinh(math.tan(lat_rad)) / math.pi)
    return int(xtile), int(ytile)
Пример #60
0
 def _deg2num(self, lat_deg, lon_deg, zoom):
     lat_rad = radians(lat_deg)
     n = 2.0**zoom
     xtile = (lon_deg + 180.0) / 360.0 * n
     ytile = (1.0 - asinh(tan(lat_rad)) / pi) / 2.0 * n
     return (xtile, ytile)