complex                 package:base                 R Documentation

_C_o_m_p_l_e_x _V_e_c_t_o_r_s

_D_e_s_c_r_i_p_t_i_o_n:

     Basic functions which support complex arithmetic in R.

_U_s_a_g_e:

     complex(length.out = 0, real = numeric(), imaginary = numeric(),
             modulus = 1, argument = 0)
     as.complex(x, ...)
     is.complex(x)

     Re(x)
     Im(x)
     Mod(x)
     Arg(x)
     Conj(x)

_A_r_g_u_m_e_n_t_s:

length.out: numeric.  Desired length of the output vector, inputs being
          recycled as needed.

    real: numeric vector.

imaginary: numeric vector.

 modulus: numeric vector.

argument: numeric vector.

       x: an object, probably of mode 'complex'.

     ...: further arguments passed to or from other methods.

_D_e_t_a_i_l_s:

     Complex vectors can be created with 'complex'.  The vector can be
     specified either by giving its length, its real and imaginary
     parts, or modulus and argument. (Giving just the length generates
     a vector of complex zeroes.)

     'as.complex' attempts to coerce its argument to be of complex
     type: like 'as.vector' it strips attributes including names.

     Note that 'is.complex' and 'is.numeric' are never both 'TRUE'.

     The functions 'Re', 'Im', 'Mod', 'Arg' and 'Conj' have their usual
     interpretation as returning the real part, imaginary part,
     modulus, argument and complex conjugate for complex values.
     Modulus and argument are also called the _polar coordinates_. If z
     = x + i y with real x and y, 'Mod'(z) = sqrt{x^2 + y^2}, and for
     phi= Arg(z), x = cos(phi) and y = sin(phi). They are all generic
     functions: methods can be defined for them individually or via the
     'Complex' group generic.

     In addition, the elementary trigonometric, logarithmic and
     exponential functions are available for complex values.

     'is.complex' is generic: you can write methods to handle specific
     classes of objects, see InternalMethods.

_R_e_f_e_r_e_n_c_e_s:

     Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988) _The New S
     Language_. Wadsworth & Brooks/Cole.

_E_x_a_m_p_l_e_s:

     0i ^ (-3:3)

     matrix(1i^ (-6:5), nr=4)#- all columns are the same
     0 ^ 1i # a complex NaN

     ## create a complex normal vector
     z <- complex(real = rnorm(100), imag = rnorm(100))
     ## or also (less efficiently):
     z2 <- 1:2 + 1i*(8:9)

     ## The Arg(.) is an angle:
     zz <- (rep(1:4,len=9) + 1i*(9:1))/10
     zz.shift <- complex(modulus = Mod(zz), argument= Arg(zz) + pi)
     plot(zz, xlim=c(-1,1), ylim=c(-1,1), col="red", asp = 1,
          main = expression(paste("Rotation by "," ", pi == 180^o)))
     abline(h=0,v=0, col="blue", lty=3)
     points(zz.shift, col="orange")

