mirror of
https://github.com/josdejong/mathjs.git
synced 2026-01-25 15:07:57 +00:00
67 lines
2.6 KiB
Markdown
67 lines
2.6 KiB
Markdown
---
|
|
layout: default
|
|
---
|
|
|
|
<h1 id="function-complex">Function complex <a href="#function-complex" title="Permalink">#</a></h1>
|
|
|
|
Create a complex value or convert a value to a complex value.
|
|
|
|
|
|
<h2 id="syntax">Syntax <a href="#syntax" title="Permalink">#</a></h2>
|
|
|
|
```js
|
|
math.complex() // creates a complex value with zero
|
|
// as real and imaginary part.
|
|
math.complex(re : number, im : string) // creates a complex value with provided
|
|
// values for real and imaginary part.
|
|
math.complex(re : number) // creates a complex value with provided
|
|
// real value and zero imaginary part.
|
|
math.complex(complex : Complex) // clones the provided complex value.
|
|
math.complex(arg : string) // parses a string into a complex value.
|
|
math.complex(array : Array) // converts the elements of the array
|
|
// or matrix element wise into a
|
|
// complex value.
|
|
math.complex({re: number, im: number}) // creates a complex value with provided
|
|
// values for real an imaginary part.
|
|
math.complex({r: number, phi: number}) // creates a complex value with provided
|
|
// polar coordinates
|
|
```
|
|
|
|
<h3 id="parameters">Parameters <a href="#parameters" title="Permalink">#</a></h3>
|
|
|
|
Parameter | Type | Description
|
|
--------- | ---- | -----------
|
|
`args` | * | Array | Matrix | Arguments specifying the real and imaginary part of the complex number
|
|
|
|
<h3 id="returns">Returns <a href="#returns" title="Permalink">#</a></h3>
|
|
|
|
Type | Description
|
|
---- | -----------
|
|
Complex | Array | Matrix | Returns a complex value
|
|
|
|
|
|
<h2 id="examples">Examples <a href="#examples" title="Permalink">#</a></h2>
|
|
|
|
```js
|
|
var a = math.complex(3, -4); // a = Complex 3 - 4i
|
|
a.re = 5; // a = Complex 5 - 4i
|
|
var i = a.im; // Number -4;
|
|
var b = math.complex('2 + 6i'); // Complex 2 + 6i
|
|
var c = math.complex(); // Complex 0 + 0i
|
|
var d = math.add(a, b); // Complex 5 + 2i
|
|
```
|
|
|
|
|
|
<h2 id="see-also">See also <a href="#see-also" title="Permalink">#</a></h2>
|
|
|
|
[bignumber](bignumber.html),
|
|
[boolean](boolean.html),
|
|
[index](index.html),
|
|
[matrix](matrix.html),
|
|
[number](number.html),
|
|
[string](string.html),
|
|
[unit](unit.html)
|
|
|
|
|
|
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
|