1 | import { factory } from '../../utils/factory'
|
2 | import { deepMap } from '../../utils/collection'
|
3 |
|
4 | const name = 'conj'
|
5 | const dependencies = ['typed']
|
6 |
|
7 | export const createConj = /* #__PURE__ */ factory(name, dependencies, ({ typed }) => {
|
8 | /**
|
9 | * Compute the complex conjugate of a complex value.
|
10 | * If `x = a+bi`, the complex conjugate of `x` is `a - bi`.
|
11 | *
|
12 | * For matrices, the function is evaluated element wise.
|
13 | *
|
14 | * Syntax:
|
15 | *
|
16 | * math.conj(x)
|
17 | *
|
18 | * Examples:
|
19 | *
|
20 | * math.conj(math.complex('2 + 3i')) // returns Complex 2 - 3i
|
21 | * math.conj(math.complex('2 - 3i')) // returns Complex 2 + 3i
|
22 | * math.conj(math.complex('-5.2i')) // returns Complex 5.2i
|
23 | *
|
24 | * See also:
|
25 | *
|
26 | * re, im, arg, abs
|
27 | *
|
28 | * @param {number | BigNumber | Complex | Array | Matrix} x
|
29 | * A complex number or array with complex numbers
|
30 | * @return {number | BigNumber | Complex | Array | Matrix}
|
31 | * The complex conjugate of x
|
32 | */
|
33 | const conj = typed(name, {
|
34 | number: function (x) {
|
35 | return x
|
36 | },
|
37 |
|
38 | BigNumber: function (x) {
|
39 | return x
|
40 | },
|
41 |
|
42 | Complex: function (x) {
|
43 | return x.conjugate()
|
44 | },
|
45 |
|
46 | 'Array | Matrix': function (x) {
|
47 | return deepMap(x, conj)
|
48 | }
|
49 | })
|
50 |
|
51 | return conj
|
52 | })
|