1 |
|
2 |
|
3 | const deepMap = require('../../utils/collection/deepMap')
|
4 |
|
5 | function factory (type, config, load, typed) {
|
6 | /**
|
7 | * Get the imaginary part of a complex number.
|
8 | * For a complex number `a + bi`, the function returns `b`.
|
9 | *
|
10 | * For matrices, the function is evaluated element wise.
|
11 | *
|
12 | * Syntax:
|
13 | *
|
14 | * math.im(x)
|
15 | *
|
16 | * Examples:
|
17 | *
|
18 | * const a = math.complex(2, 3)
|
19 | * math.re(a) // returns number 2
|
20 | * math.im(a) // returns number 3
|
21 | *
|
22 | * math.re(math.complex('-5.2i')) // returns number -5.2
|
23 | * math.re(math.complex(2.4)) // returns number 0
|
24 | *
|
25 | * See also:
|
26 | *
|
27 | * re, conj, abs, arg
|
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 imaginary part of x
|
32 | */
|
33 | const im = typed('im', {
|
34 | 'number': function (x) {
|
35 | return 0
|
36 | },
|
37 |
|
38 | 'BigNumber': function (x) {
|
39 | return new type.BigNumber(0)
|
40 | },
|
41 |
|
42 | 'Complex': function (x) {
|
43 | return x.im
|
44 | },
|
45 |
|
46 | 'Array | Matrix': function (x) {
|
47 | return deepMap(x, im)
|
48 | }
|
49 | })
|
50 |
|
51 | im.toTex = { 1: `\\Im\\left\\lbrace\${args[0]}\\right\\rbrace` }
|
52 |
|
53 | return im
|
54 | }
|
55 |
|
56 | exports.name = 'im'
|
57 | exports.factory = factory
|