UNPKG

1.27 kBJavaScriptView Raw
1'use strict'
2
3const deepMap = require('../../utils/collection/deepMap')
4
5function factory (type, config, load, typed) {
6 /**
7 * Calculate the hyperbolic arccotangent of a value,
8 * defined as `acoth(x) = atanh(1/x) = (ln((x+1)/x) + ln(x/(x-1))) / 2`.
9 *
10 * For matrices, the function is evaluated element wise.
11 *
12 * Syntax:
13 *
14 * math.acoth(x)
15 *
16 * Examples:
17 *
18 * math.acoth(0.5) // returns 0.8047189562170503
19 *
20 * See also:
21 *
22 * acsch, asech
23 *
24 * @param {number | Complex | Array | Matrix} x Function input
25 * @return {number | Complex | Array | Matrix} Hyperbolic arccotangent of x
26 */
27 const acoth = typed('acoth', {
28 'number': function (x) {
29 if (x >= 1 || x <= -1 || config.predictable) {
30 return isFinite(x) ? (Math.log((x + 1) / x) + Math.log(x / (x - 1))) / 2 : 0
31 }
32 return new type.Complex(x, 0).acoth()
33 },
34
35 'Complex': function (x) {
36 return x.acoth()
37 },
38
39 'BigNumber': function (x) {
40 return new type.BigNumber(1).div(x).atanh()
41 },
42
43 'Array | Matrix': function (x) {
44 return deepMap(x, acoth)
45 }
46 })
47
48 acoth.toTex = { 1: `\\coth^{-1}\\left(\${args[0]}\\right)` }
49
50 return acoth
51}
52
53exports.name = 'acoth'
54exports.factory = factory