Python math.atanh() Examples

The following are code examples for showing how to use math.atanh(). They are extracted from open source Python projects. You can vote up the examples you like or vote down the ones you don't like. You can also save this page to your account.

Example 1
Project: duct   Author: ducted   File: generator.py    (license) View Source Project 6 votes vote down vote up
def get(self):
        self.x += self.config.get('dx', 0.1)

        val = eval(self.config.get('function', 'sin(x)'), {
            'sin': math.sin,
            'sinh': math.sinh,
            'cos': math.cos,
            'cosh': math.cosh,
            'tan': math.tan,
            'tanh': math.tanh,
            'asin': math.asin,
            'acos': math.acos,
            'atan': math.atan,
            'asinh': math.asinh,
            'acosh': math.acosh,
            'atanh': math.atanh,
            'log': math.log,
            'abs': abs,
            'e': math.e,
            'pi': math.pi,
            'x': self.x
        })

        return self.createEvent('ok', 'Sine wave', val) 
Example 2
Project: qgis-shapetools-plugin   Author: NationalSecurityAgency   File: geomath.py    (GNU General Public License v2.0) View Source Project 5 votes vote down vote up
def atanh(x):
    """atanh(x) (missing from python 2.5.2)"""

    if sys.version_info > (2, 6):
      return math.atanh(x)

    y = abs(x)                  # Enforce odd parity
    y = Math.log1p(2 * y/(1 - y))/2
    return -y if x < 0 else y 
Example 3
Project: bpy_lambda   Author: bcongdon   File: transverse_mercator.py    (license) View Source Project 5 votes vote down vote up
def fromGeographic(self, lat, lon):
        lat_rad = radians(lat)
        lon_rad = radians(lon)
        B = cos(lat_rad) * sin(lon_rad - self.lon_rad)
        x = self.radius * atanh(B)
        y = self.radius * (atan(tan(lat_rad) / cos(lon_rad - self.lon_rad)) - self.lat_rad)
        return x, y 
Example 4
Project: PyGLM   Author: Zuzu-Typ   File: reciprocal.py    (license) View Source Project 5 votes vote down vote up
def acoth(x):
	if type(x) in dtypes:
		return math.atanh(1. / x)

	return functor1(acoth, x) 
Example 5
Project: zippy   Author: securesystemslab   File: test_math.py    (license) View Source Project 5 votes vote down vote up
def testAtanh(self):
        self.assertRaises(TypeError, math.atan)
        self.ftest('atanh(0)', math.atanh(0), 0)
        self.ftest('atanh(0.5)', math.atanh(0.5), 0.54930614433405489)
        self.ftest('atanh(-0.5)', math.atanh(-0.5), -0.54930614433405489)
        self.assertRaises(ValueError, math.atanh, 1)
        self.assertRaises(ValueError, math.atanh, -1)
        self.assertRaises(ValueError, math.atanh, INF)
        self.assertRaises(ValueError, math.atanh, NINF)
        self.assertTrue(math.isnan(math.atanh(NAN))) 
Example 6
Project: oil   Author: oilshell   File: test_math.py    (license) View Source Project 5 votes vote down vote up
def testAtanh(self):
        self.assertRaises(TypeError, math.atan)
        self.ftest('atanh(0)', math.atanh(0), 0)
        self.ftest('atanh(0.5)', math.atanh(0.5), 0.54930614433405489)
        self.ftest('atanh(-0.5)', math.atanh(-0.5), -0.54930614433405489)
        self.assertRaises(ValueError, math.atanh, 1)
        self.assertRaises(ValueError, math.atanh, -1)
        self.assertRaises(ValueError, math.atanh, INF)
        self.assertRaises(ValueError, math.atanh, NINF)
        self.assertTrue(math.isnan(math.atanh(NAN))) 
Example 7
Project: python2-tracer   Author: extremecoders-re   File: test_math.py    (license) View Source Project 5 votes vote down vote up
def testAtanh(self):
        self.assertRaises(TypeError, math.atan)
        self.ftest('atanh(0)', math.atanh(0), 0)
        self.ftest('atanh(0.5)', math.atanh(0.5), 0.54930614433405489)
        self.ftest('atanh(-0.5)', math.atanh(-0.5), -0.54930614433405489)
        self.assertRaises(ValueError, math.atanh, 1)
        self.assertRaises(ValueError, math.atanh, -1)
        self.assertRaises(ValueError, math.atanh, INF)
        self.assertRaises(ValueError, math.atanh, NINF)
        self.assertTrue(math.isnan(math.atanh(NAN))) 
Example 8
Project: web_ctp   Author: molebot   File: test_math.py    (license) View Source Project 5 votes vote down vote up
def testAtanh(self):
        self.assertRaises(TypeError, math.atan)
        self.ftest('atanh(0)', math.atanh(0), 0)
        self.ftest('atanh(0.5)', math.atanh(0.5), 0.54930614433405489)
        self.ftest('atanh(-0.5)', math.atanh(-0.5), -0.54930614433405489)
        self.assertRaises(ValueError, math.atanh, 1)
        self.assertRaises(ValueError, math.atanh, -1)
        self.assertRaises(ValueError, math.atanh, INF)
        self.assertRaises(ValueError, math.atanh, NINF)
        self.assertTrue(math.isnan(math.atanh(NAN))) 
Example 9
Project: hyper-engine   Author: maxim5   File: sugar.py    (license) View Source Project 5 votes vote down vote up
def atanh(node): return merge([node], math.atanh) 
Example 10
Project: blender-addons   Author: scorpion81   File: transverse_mercator.py    (license) View Source Project 5 votes vote down vote up
def fromGeographic(self, lat, lon):
        lat_rad = radians(lat)
        lon_rad = radians(lon)
        B = cos(lat_rad) * sin(lon_rad - self.lon_rad)
        x = self.radius * atanh(B)
        y = self.radius * (atan(tan(lat_rad) / cos(lon_rad - self.lon_rad)) - self.lat_rad)
        return x, y 
Example 11
Project: biling-survey   Author: shyamupa   File: corrstats.py    (license) View Source Project 5 votes vote down vote up
def rz_ci(r, n, conf_level = 0.95):
    zr_se = pow(1/(n - 3), .5)
    moe = norm.ppf(1 - (1 - conf_level)/float(2)) * zr_se
    zu = atanh(r) + moe
    zl = atanh(r) - moe
    return tanh((zl, zu)) 
Example 12
Project: pefile.pypy   Author: cloudtracer   File: test_math.py    (license) View Source Project 5 votes vote down vote up
def testAtanh(self):
        self.assertRaises(TypeError, math.atan)
        self.ftest('atanh(0)', math.atanh(0), 0)
        self.ftest('atanh(0.5)', math.atanh(0.5), 0.54930614433405489)
        self.ftest('atanh(-0.5)', math.atanh(-0.5), -0.54930614433405489)
        self.assertRaises(ValueError, math.atanh, 1)
        self.assertRaises(ValueError, math.atanh, -1)
        self.assertRaises(ValueError, math.atanh, INF)
        self.assertRaises(ValueError, math.atanh, NINF)
        self.assertTrue(math.isnan(math.atanh(NAN))) 
Example 13
Project: ouroboros   Author: pybee   File: test_math.py    (license) View Source Project 5 votes vote down vote up
def testAtanh(self):
        self.assertRaises(TypeError, math.atan)
        self.ftest('atanh(0)', math.atanh(0), 0)
        self.ftest('atanh(0.5)', math.atanh(0.5), 0.54930614433405489)
        self.ftest('atanh(-0.5)', math.atanh(-0.5), -0.54930614433405489)
        self.assertRaises(ValueError, math.atanh, 1)
        self.assertRaises(ValueError, math.atanh, -1)
        self.assertRaises(ValueError, math.atanh, INF)
        self.assertRaises(ValueError, math.atanh, NINF)
        self.assertTrue(math.isnan(math.atanh(NAN))) 
Example 14
Project: ndk-python   Author: gittor   File: test_math.py    (license) View Source Project 5 votes vote down vote up
def testAtanh(self):
        self.assertRaises(TypeError, math.atan)
        self.ftest('atanh(0)', math.atanh(0), 0)
        self.ftest('atanh(0.5)', math.atanh(0.5), 0.54930614433405489)
        self.ftest('atanh(-0.5)', math.atanh(-0.5), -0.54930614433405489)
        self.assertRaises(ValueError, math.atanh, 1)
        self.assertRaises(ValueError, math.atanh, -1)
        self.assertRaises(ValueError, math.atanh, INF)
        self.assertRaises(ValueError, math.atanh, NINF)
        self.assertTrue(math.isnan(math.atanh(NAN))) 
Example 15
Project: kbe_server   Author: xiaohaoppy   File: test_math.py    (license) View Source Project 5 votes vote down vote up
def testAtanh(self):
        self.assertRaises(TypeError, math.atan)
        self.ftest('atanh(0)', math.atanh(0), 0)
        self.ftest('atanh(0.5)', math.atanh(0.5), 0.54930614433405489)
        self.ftest('atanh(-0.5)', math.atanh(-0.5), -0.54930614433405489)
        self.assertRaises(ValueError, math.atanh, 1)
        self.assertRaises(ValueError, math.atanh, -1)
        self.assertRaises(ValueError, math.atanh, INF)
        self.assertRaises(ValueError, math.atanh, NINF)
        self.assertTrue(math.isnan(math.atanh(NAN))) 
Example 16
Project: femtocode   Author: diana-hep   File: test_libstandard.py    (license) View Source Project 5 votes vote down vote up
def test_atanh(self):
        self.assertEqual(session.source("Test", x=real(0.1, 0.5)).type("atanh(x)"), real(math.atanh(0.1), math.atanh(0.5)))
        self.assertEqual(session.source("Test", x=real(0.1, almost(0.5))).type("atanh(x)"), real(math.atanh(0.1), almost(math.atanh(0.5))))
        self.assertEqual(session.source("Test", x=real(0.1, 1.0)).type("atanh(x)"), real(math.atanh(0.1), inf))
        self.assertEqual(session.source("Test", x=real(0.1, almost(1.0))).type("atanh(x)"), real(math.atanh(0.1), almost(inf)))
        self.assertEqual(session.source("Test", x=real(-1.0, 0.5)).type("atanh(x)"), real(-inf, math.atanh(0.5)))
        self.assertEqual(session.source("Test", x=real(almost(-1.0), 0.5)).type("atanh(x)"), real(almost(-inf), math.atanh(0.5)))
        self.assertRaises(FemtocodeError, lambda: session.source("Test", x=real(0.1, 1.1)).type("atanh(x)"))
        self.assertRaises(FemtocodeError, lambda: session.source("Test", x=real(0.1, almost(1.1))).type("atanh(x)"))
        self.assertRaises(FemtocodeError, lambda: session.source("Test", x=real(-1.1, 0.5)).type("atanh(x)"))
        self.assertRaises(FemtocodeError, lambda: session.source("Test", x=real(almost(-1.1), 0.5)).type("atanh(x)"))
        for entry in numerical.toPython(ylim2 = "ylim2", a = "atanh(ylim2 / 10)").submit():
            self.assertEqual(entry.a, math.atanh(entry.ylim2 / 10)) 
Example 17
Project: pyomo   Author: Pyomo   File: expr.py    (license) View Source Project 5 votes vote down vote up
def atanh(arg):
    return generate_intrinsic_function_expression(arg, 'atanh', math.atanh) 
Example 18
Project: srcsim2017   Author: ZarjRobotics   File: task3.py    (license) View Source Project 4 votes vote down vote up
def start(self, _=None):
        """ Start the macro """
        anchor = self.fc.assure_anchor("center")
        if anchor is None:
            log('Click on the 2 farthest parts of the side of the table '
                'you want to approach')
            return False

        self.fc.zarj.walk.fix_stance()
        zarj.utils.wait_for_walk(self.fc.zarj)

        r_x = anchor.adjusted[0]
        r_y = anchor.adjusted[1]
        r_a = anchor.angle

        log('Table is {},{} at angle {}'.format(r_x, r_y, r_a))

        off_a = 90 - r_a
        off_x = sin(radians(off_a))*0.75
        off_y = cos(radians(off_a))*0.75

        tgt_x = r_x - off_x
        tgt_y = r_y + off_y

        log('Approach point is {},{}'.format(tgt_x, tgt_y))

        heading = degrees(atanh(tgt_y/tgt_x))
        distance = sqrt(tgt_x**2 + tgt_y**2)

        log('Path has a heading of {} and distance {}m'.format(heading,
                                                               distance))

        self.fc.zarj.walk.turn(heading, snap_to=0.0)
        zarj.utils.wait_for_walk(self.fc.zarj)
        if self.stop:
            return

        self.fc.zarj.walk.forward(distance)
        zarj.utils.wait_for_walk(self.fc.zarj)
        if self.stop:
            return

        turn = r_a + heading

        if abs(turn) > 45:
            self.fc.zarj.walk.turn(-turn/2.0, snap_to=0.0)
            zarj.utils.wait_for_walk(self.fc.zarj)
            if self.stop:
                return
            self.fc.zarj.walk.turn(-turn/2.0, snap_to=0.0)
        else:
            self.fc.zarj.walk.turn(-turn, snap_to=0.0)
        zarj.utils.wait_for_walk(self.fc.zarj)
        if self.stop:
            return

        self.fc.zarj.walk.forward(0.2)
        zarj.utils.wait_for_walk(self.fc.zarj) 
Example 19
Project: bge-logic-nodes-add-on   Author: thepgi   File: bgelogic.py    (license) View Source Project 4 votes vote down vote up
def __init__(self):
        ParameterCell.__init__(self)
        self.a = None
        self.b = None
        self.c = None
        self.d = None
        self.formula = ""
        self._previous_values = [None, None, None, None]
        self._formula_globals = globals();
        self._formula_locals = {
            "exp":math.exp,
            "pow":math.pow,
            "log":math.log,
            "log10":math.log10,
            "acos":math.acos,
            "asin":math.asin,
            "atan":math.atan,
            "atan2":math.atan2,
            "cos":math.cos,
            "hypot":math.hypot,
            "sin":math.sin,
            "tan":math.tan,
            "degrees":math.degrees,
            "radians":math.radians,
            "acosh":math.acosh,
            "asinh":math.asinh,
            "atanh":math.atanh,
            "cosh":math.cosh,
            "sinh":math.sinh,
            "tanh":math.tanh,
            "pi":math.pi,
            "e":math.e,
            "ceil":math.ceil,
            "sign":ParameterMathFun.signum,
            "abs":math.fabs,
            "floor":math.floor,
            "mod":math.fmod,
            "sqrt":math.sqrt,
            "curt":ParameterMathFun.curt,
            "str":str,
            "int":int,
            "float":float
        } 
Example 20
Project: scikit-discovery   Author: MITHaystack   File: astro_tools.py    (license) View Source Project 4 votes vote down vote up
def nfw(R, norm_constant, Rs, Rcore):
    '''
    2D Navarro-Frenk-White surface radial profile probability density

    See:
    Navarro, J. F., Frenk, C. S., & White, S. D. M. 1996, ApJ, 462, 563
    Bartelmann, M., A&A, 1996, 313, 697
    Rykoff, E.S., et al., ApJ, 746, 178

    @param R: Radius
    @param norm_constant: Normalization constant
    @param Rs: Scale radius
    @param Rcore: Since NFW profile diverges at R=0, the value at the center is held fixed starting at Rcore

    @return probability density of profile at R
    '''

    def compute_nfw(R):
        if R < Rcore:
            R2 = Rcore
        else:
            R2 = R

        if (R2/Rs) < 0.999:
            func = (1 - 2 * math.atanh(math.sqrt((1 - R2/Rs) / (R2/Rs + 1))) / math.sqrt(1 - (R2/Rs)**2)) / ((R2/Rs)**2 - 1)

        # There are some computational issues as R2/Rs -> 1, using taylor expansion of the function
        # around this point
        elif (R2/Rs) < 1.001:
            func = -(20/63)*((R2/Rs)**3 - 1) + (13/35)*((R2/Rs)**2 - 1) - (2/5)*(R2/Rs) + (11/15)

        else:
            func = (1 - 2 * math.atan(math.sqrt((R2/Rs - 1) / (R2/Rs + 1))) / math.sqrt((R2/Rs)**2 - 1)) / ((R2/Rs)**2 - 1)


        return norm_constant * 2 * math.pi * R * func

    if np.isscalar(R):
        return compute_nfw(R)

    else:
        return np.fromiter(map(compute_nfw, R), np.float, count = len(R)) 
Example 21
Project: SparseArray   Author: INGEOTEC   File: test_sparse_array.py    (license) View Source Project 4 votes vote down vote up
def test_one():
    from math import sin, cos, tan, asin, acos, atan
    from math import sinh, cosh, tanh, asinh, acosh, atanh
    from math import exp, expm1, log, log10, log1p, sqrt, lgamma
    from math import fabs, ceil, floor, trunc, erf, erfc
    try:
        from math import log2
    except ImportError:
        def log2(x):
            return log(x) / log(2)

    def wrapper(f, v):
        try:
            return f(v)
        except ValueError:
            if f == sqrt:
                return float('nan')
            if v >= 0:
                return float('inf')
            else:
                return -float('inf')

    def compare(a, b):
        if isfinite(a) and isfinite(b):
            return assert_almost_equals(a, b)
        return str(a) == str(b)

    for f in [sin, cos, tan, asin, acos, atan,
              sinh, cosh, tanh, asinh, acosh, atanh,
              exp, expm1, log, log2, log10, log1p, sqrt,
              lgamma,
              fabs, ceil, floor, trunc,
              erf, erfc]:
        for p in [0.5, 1]:
            a = random_lst(p=p)
            b = SparseArray.fromlist(a)
            c = getattr(b, f.__name__)()
            res = [wrapper(f, x) for x in a]
            index = [k for k, v in enumerate(res) if v != 0]
            res = [x for x in res if x != 0]
            print(f, p, c.non_zero, len(res))
            assert c.non_zero == len(res)
            [assert_almost_equals(v, w) for v, w in zip(index,
                                                        c.index)]
            [compare(v, w) for v, w in zip(res,
                                           c.data)]