UNPKG

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