1 |
|
2 |
|
3 | # Function complex
|
4 |
|
5 | Create a complex value or convert a value to a complex value.
|
6 |
|
7 |
|
8 | ## Syntax
|
9 |
|
10 | ```js
|
11 | math.complex() // creates a complex value with zero
|
12 | // as real and imaginary part.
|
13 | math.complex(re : number, im : string) // creates a complex value with provided
|
14 | // values for real and imaginary part.
|
15 | math.complex(re : number) // creates a complex value with provided
|
16 | // real value and zero imaginary part.
|
17 | math.complex(complex : Complex) // clones the provided complex value.
|
18 | math.complex(arg : string) // parses a string into a complex value.
|
19 | math.complex(array : Array) // converts the elements of the array
|
20 | // or matrix element wise into a
|
21 | // complex value.
|
22 | math.complex({re: number, im: number}) // creates a complex value with provided
|
23 | // values for real an imaginary part.
|
24 | math.complex({r: number, phi: number}) // creates a complex value with provided
|
25 | // polar coordinates
|
26 | ```
|
27 |
|
28 | ### Parameters
|
29 |
|
30 | Parameter | Type | Description
|
31 | --------- | ---- | -----------
|
32 | `args` | * | Array | Matrix | Arguments specifying the real and imaginary part of the complex number
|
33 |
|
34 | ### Returns
|
35 |
|
36 | Type | Description
|
37 | ---- | -----------
|
38 | Complex | Array | Matrix | Returns a complex value
|
39 |
|
40 |
|
41 | ## Examples
|
42 |
|
43 | ```js
|
44 | const a = math.complex(3, -4) // a = Complex 3 - 4i
|
45 | a.re = 5 // a = Complex 5 - 4i
|
46 | const i = a.im // Number -4
|
47 | const b = math.complex('2 + 6i') // Complex 2 + 6i
|
48 | const c = math.complex() // Complex 0 + 0i
|
49 | const d = math.add(a, b) // Complex 5 + 2i
|
50 | ```
|
51 |
|
52 |
|
53 | ## See also
|
54 |
|
55 | [bignumber](bignumber.md),
|
56 | [boolean](boolean.md),
|
57 | [index](index.md),
|
58 | [matrix](matrix.md),
|
59 | [number](number.md),
|
60 | [string](string.md),
|
61 | [unit](unit.md)
|