UNPKG

1.28 kBJavaScriptView Raw
1'use strict'
2
3const deepMap = require('../../utils/collection/deepMap')
4
5function factory (type, config, load, typed) {
6 /**
7 * Calculate the cotangent of a value. Defined as `cot(x) = 1 / tan(x)`.
8 *
9 * For matrices, the function is evaluated element wise.
10 *
11 * Syntax:
12 *
13 * math.cot(x)
14 *
15 * Examples:
16 *
17 * math.cot(2) // returns number -0.45765755436028577
18 * 1 / math.tan(2) // returns number -0.45765755436028577
19 *
20 * See also:
21 *
22 * tan, sec, csc
23 *
24 * @param {number | Complex | Unit | Array | Matrix} x Function input
25 * @return {number | Complex | Array | Matrix} Cotangent of x
26 */
27 const cot = typed('cot', {
28 'number': function (x) {
29 return 1 / Math.tan(x)
30 },
31
32 'Complex': function (x) {
33 return x.cot()
34 },
35
36 'BigNumber': function (x) {
37 return new type.BigNumber(1).div(x.tan())
38 },
39
40 'Unit': function (x) {
41 if (!x.hasBase(type.Unit.BASE_UNITS.ANGLE)) {
42 throw new TypeError('Unit in function cot is no angle')
43 }
44 return cot(x.value)
45 },
46
47 'Array | Matrix': function (x) {
48 return deepMap(x, cot)
49 }
50 })
51
52 cot.toTex = { 1: `\\cot\\left(\${args[0]}\\right)` }
53
54 return cot
55}
56
57exports.name = 'cot'
58exports.factory = factory