ID EN
Vector & List

complex

R Base 3.6.2 🇮🇩 Bahasa Indonesia

Fungsi dasar yang mendukung aritmatika kompleks di R, selain operator aritmatika +, -, *, /, dan ^.

Syntax

R
complex(length.out = 0, real = numeric(), imaginary = numeric(),
        modulus = 1, argument = 0)
as.complex(x, …)
is.complex(x)<p></p><p>Re(z)
Im(z)
Mod(z)
Arg(z)
Conj(z)</p>

Arguments

Parameter Deskripsi
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.
z an object of mode complex, or one of a class for which a methods has been defined.
&#8230; further arguments passed to or from other methods.

Details

Vektor kompleks dapat dibuat dengan kompleks. Vektor dapat ditentukan dengan memberikan panjangnya, bagian real dan imajinernya, atau modulus dan argumen. (Memberikan panjangnya saja akan menghasilkan vektor nol yang kompleks.) as.complex berupaya untuk memaksa argumennya menjadi tipe yang kompleks: seperti as.vector, as.complex menghapus atribut termasuk nama. Hingga R versi 3.2.x, semua bentuk NA dan NaN dipaksa menjadi NA kompleks, yaitu konstanta NA_complex_, yang bagian nyata dan imajinernya adalah NA. Sejak R 3.3.0, biasanya hanya objek dengan bagian NA yang dipaksa menjadi NA kompleks, tetapi objek lain dengan bagian NaN tidak. Akibatnya, aritmatika kompleks yang hanya melibatkan NaN (tetapi tidak ada NA) biasanya tidak akan menghasilkan NA kompleks melainkan bilangan kompleks dengan bagian nyata atau imajiner dari NaN. Bukan

Contoh

Example
R
# NOT RUN {
require(graphics)

0i ^ (-3:3)

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

## create a complex normal vector
z <- complex(real = stats::rnorm(100), imaginary = stats::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")

showC <- function(z) noquote(sprintf("(R = %g, I = %g)", Re(z), Im(z)))

## The exact result of this *depends* on the platform, compiler, math-library:
(NpNA <- NaN + NA_complex_) ; str(NpNA) # *behaves* as 'cplx NA' ..
stopifnot(is.na(NpNA), is.na(NA_complex_), is.na(Re(NA_complex_)), is.na(Im(NA_complex_)))
showC(NpNA)# but not always is {shows  '(R = NaN, I = NA)' on some platforms}
## and this is not TRUE everywhere:
identical(NpNA, NA_complex_)
showC(NA_complex_) # always == (R = NA, I = NA)
# }

See Also

Arithmetic; polyroot finds all \(n\) complex roots of a polynomial of degree \(n\).