Build an array of complex numbers from their parts
c = complex(u) c = complex(a, b)
a
and b
are not
scalars, they must have the same sizes.
u
or of
a
and b
.
If u
is sparse, or if a
and
b
have the same sizes and both are sparse,
then c
is also sparse.
Otherwise c
is dense-encoded.
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.
In the following example, we create a complex number from its real and imaginary parts.
If a
only is specified, then the imaginary
part is set to zero.
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
.
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
Version | Description |
6.1.1 | Extension to sparse arrays. |