complex
Complex Valued Objects
Description
The complex and as.complex functions create vectors of complex numbers.
Usage
complex(length.out = 0L, real = numeric(), imaginary = numeric(),
modulus = 1, argument = 0)
is.complex(x)
as.complex(x, ...)
Arguments
length |
length of the returned object.
|
real |
vector of real parts for use in the construction of the return value.
|
imaginary |
vector of imaginary parts for use in the construction of the return value.
|
modulus |
vector of moduli for use in the construction of the return value.
|
argument |
vector of arguments for use in the construction of the return value.
|
x |
any object.
|
... |
additional arguments.
|
Details
The "+" within the rectangular representation of a complex number has the
usual precedence.
The as.complex function is generic but
currently there are no methods written for it.
Value
complex returns a simple object (i.e., a vector) of mode "complex".
If real and/or imaginary are specified, the real and
imaginary parts of the result are set from them, using the defaults
if necessary.
If modulus and/or argument are specified, the modulus and
argument of the result are set from them, using the defaults
if necessary. real and imaginary are ignored in this case.
is.complex returns TRUE if x is of mode "complex", and
FALSE otherwise.
Its behavior is unaffected by any attributes of x; for example, x could
be a complex array.
as.complex returns x if x is a simple object of mode "complex", and
otherwise a complex object of the same length as x and with data resulting
from coercing the elements of x to mode "complex".
Attributes are deleted.
See Also
Complex
(describes the functions that do basic manipulations of complex),
numbers.
Examples
complex(real=3, imag=4) == 3+4i
complex(mod=2, arg=1.5*pi) - (-2i) # almost equal
abs(3+4i)
log(complex(arg=seq(0, pi, len=5))) / pi
log(-.1) # NaN, because -.1 is numeric, not complex
log(-.1 + 0i) # complex(re=-log(10), im=pi)
sqrt(as.complex(-4:4))
Re(sqrt(as.complex(-4:4)))
x <- -7:8
fft(sin(x*2.5*pi) + 1/(1+x^2))[1:(length(x)/2)]