1 |
|
2 |
|
3 | const deepMap = require('../../utils/collection/deepMap')
|
4 |
|
5 | function factory (type, config, load, typed) {
|
6 | /**
|
7 | * Compute the argument of a complex value.
|
8 | * For a complex number `a + bi`, the argument is computed as `atan2(b, a)`.
|
9 | *
|
10 | * For matrices, the function is evaluated element wise.
|
11 | *
|
12 | * Syntax:
|
13 | *
|
14 | * math.arg(x)
|
15 | *
|
16 | * Examples:
|
17 | *
|
18 | * const a = math.complex(2, 2)
|
19 | * math.arg(a) / math.pi // returns number 0.25
|
20 | *
|
21 | * const b = math.complex('2 + 3i')
|
22 | * math.arg(b) // returns number 0.982793723247329
|
23 | * math.atan2(3, 2) // returns number 0.982793723247329
|
24 | *
|
25 | * See also:
|
26 | *
|
27 | * re, im, conj, abs
|
28 | *
|
29 | * @param {number | BigNumber | Complex | Array | Matrix} x
|
30 | * A complex number or array with complex numbers
|
31 | * @return {number | BigNumber | Array | Matrix} The argument of x
|
32 | */
|
33 | const arg = typed('arg', {
|
34 | 'number': function (x) {
|
35 | return Math.atan2(0, x)
|
36 | },
|
37 |
|
38 | 'BigNumber': function (x) {
|
39 | return type.BigNumber.atan2(0, x)
|
40 | },
|
41 |
|
42 | 'Complex': function (x) {
|
43 | return x.arg()
|
44 | },
|
45 |
|
46 | // TODO: implement BigNumber support for function arg
|
47 |
|
48 | 'Array | Matrix': function (x) {
|
49 | return deepMap(x, arg)
|
50 | }
|
51 | })
|
52 |
|
53 | arg.toTex = { 1: `\\arg\\left(\${args[0]}\\right)` }
|
54 |
|
55 | return arg
|
56 | }
|
57 |
|
58 | exports.name = 'arg'
|
59 | exports.factory = factory
|