UNPKG

1.53 kBJavaScriptView Raw
1'use strict';
2
3var deepMap = require('../../utils/collection/deepMap');
4
5function factory(type, config, load, typed) {
6 /**
7 * Calculate the hyperbolic cotangent of a value,
8 * defined as `coth(x) = 1 / tanh(x)`.
9 *
10 * For matrices, the function is evaluated element wise.
11 *
12 * Syntax:
13 *
14 * math.coth(x)
15 *
16 * Examples:
17 *
18 * // coth(x) = 1 / tanh(x)
19 * math.coth(2) // returns 1.0373147207275482
20 * 1 / math.tanh(2) // returns 1.0373147207275482
21 *
22 * See also:
23 *
24 * sinh, tanh, cosh
25 *
26 * @param {number | Complex | Unit | Array | Matrix} x Function input
27 * @return {number | Complex | Array | Matrix} Hyperbolic cotangent of x
28 */
29 var coth = typed('coth', {
30 'number': _coth,
31
32 'Complex': function Complex(x) {
33 return x.coth();
34 },
35
36 'BigNumber': function BigNumber(x) {
37 return new type.BigNumber(1).div(x.tanh());
38 },
39
40 'Unit': function Unit(x) {
41 if (!x.hasBase(type.Unit.BASE_UNITS.ANGLE)) {
42 throw new TypeError('Unit in function coth is no angle');
43 }
44 return coth(x.value);
45 },
46
47 'Array | Matrix': function ArrayMatrix(x) {
48 return deepMap(x, coth);
49 }
50 });
51
52 coth.toTex = { 1: '\\coth\\left(${args[0]}\\right)' };
53
54 return coth;
55}
56
57/**
58 * Calculate the hyperbolic cosine of a number
59 * @param {number} x
60 * @returns {number}
61 * @private
62 */
63function _coth(x) {
64 var e = Math.exp(2 * x);
65 return (e + 1) / (e - 1);
66}
67
68exports.name = 'coth';
69exports.factory = factory;
\No newline at end of file