logo

Using Complex Numbers in R 📂R

Using Complex Numbers in R

Overview

R includes the complex number data type. There’s no need to implement it yourself; you just need to use it. In addition to basic arithmetic, it also includes several functions essential for handling complex numbers.

Code

Let’s say z1:=1iz_{1} : = 1- i and z2:=1+iz_{2} := 1+ i.

z_1 = 1-1i
z_2 = 1+1i

z_1 + z_2
z_1 - z_2
z_1 * z_2
z_1 / z_2
 
Re(z_1)
Im(z_1)
Mod(z_1)
Arg(z_1)
Conj(z_1)

Executing the code above results in the following. Let’s verify it with the formulas.

20190324\_112407.png

z1+z2=2z1z2=i2z1z2=(1i)(1+i)=1i2=2z1z2=(1i)(1+i)=(1i)(1+i)(1+i)2=22i=i z_{1} + z_{2} = 2 \\ z_{1} - z_{2} = i 2 \\ z_{1} z_{2} = (1 - i) (1 + i) = 1 - i^2 = 2 \\ {{z_{1}} \over { z_{2} }} = {{ (1 - i) } \over { (1 + i) }} = {{ (1 - i)(1 + i) } \over { (1 + i)^2 }} = {{ 2 } \over { 2i }} = -i

20190324\_112429.png

Rez1=1Imz1=1z1=12+(1)2=2argz1=π4z1=1+i \operatorname{Re} z_{1} = 1 \\ \operatorname{Im} z_{1} = -1 \\ | z_{1} | = \sqrt{1^2 + (-1)^2 } = \sqrt{2} \\ \arg z_{1} = -{{ \pi } \over {4}} \\ \overline{ z_{1} } = 1 + i