complex
Build an array of complex numbers from their parts
Syntax
c = complex(u) c = complex(a, b)
Arguments
- u, a, b
- scalars, vectors, matrices or hypermatrices of real numbers.
If both
a
andb
are not scalars, they must have the same sizes. - c
- array of complex numbers, of the size of
u
or ofa
andb
. Ifu
is sparse, or ifa
andb
have the same sizes and both are sparse, thenc
is also sparse. Otherwisec
is dense-encoded.
Description
c = complex(u) creates an array
of complex numbers from their real parts u
,
and zero as imaginary parts.
c = complex(a,b) creates an array
of complex numbers from their respective real parts a
and their imaginary parts b
.
This function is equivalent to a + imult(b)
, which
handles properly special Inf and NaN real and imaginary parts.
Examples
In the following example, we create a complex number from its real and imaginary parts.
complex(1,2) complex([1 2],[3 4])
If a
only is specified, then the imaginary
part is set to zero.
complex([1 2 3])
If a
is a scalar and b
is a matrix, then the result c
has the same
size as b
.
Similarly, if b
is a scalar and a
is a matrix, then the result c
has the same
size as a
.
c = complex([1 2 3], 4) c = complex(1, [2 3 4])
If a
and b
are two
matrices with different sizes, an error is generated, as in the
following session.
-->complex(ones(2,3),ones(4,5)) !--error 10000 complex: Incompatible input arguments #1 and #2: Same sizes expected. at line 33 of function complex called by : complex(ones(2,3),ones(4,5))
With special real or/and imaginary parts:
r = [0 0 0 %inf %inf %inf %nan %nan %nan].'; i = [0 %inf %nan 0 %inf %nan 0 %inf %nan].'; [r, i] // Then let's compare complex(r, i) with r + i*%i : [complex(r,i), r+i*%i]
--> [r, i] ans = 0. 0. 0. Inf 0. Nan Inf 0. Inf Inf Inf Nan Nan 0. Nan Inf Nan Nan // Then let's compare complex(r, i) with r + i*%i : --> [complex(r,i), r+i*%i] ans = 0. + 0.i 0. + 0.i 0. + Infi Nan + Infi 0. + Nani Nan + Nani Inf + 0.i Inf + 0.i Inf + Infi Nan + Infi Inf + Nani Nan + Nani Nan + 0.i Nan + 0.i Nan + Infi Nan + Infi Nan + Nani Nan + Nani
History
Version | Description |
6.1.1 | Extension to sparse arrays. |
Report an issue | ||
<< Complex numbers | Complex numbers | conj >> |