UNPKG

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