# Introduction to complex numbers and their Algebra

Complex Numbers are the final stage of evolution of Number System. In this article, I am going to discuss how complex numbers are introduced and basics of complex numbers. I also wrote a C program which can be used to perform the common complex number algebra operations in this article.

## Origin of Complex Numbers

The numbers used for counting are called natural numbers i.e. 1, 2, 3, 4, 5 and so on. Then came the need for zero. Hence, zero was introduced and natural numbers including zero are named as whole numbers i.e. 0, 1, 2, 3, 4, 5 and so on. Then came the need for subtraction. For example, there is no answer for "what number when added to 5 results in 3" in whole numbers. Hence came the next stage of number system, the integers i.e. ... -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5 .... Then came the need for division. Considering another example, there is no answer for "what number when multiplied by 5 results in 3" in integers. So, fractions are introduced and whole numbers and fractions are collectively named as rational numbers. Then came the need for powers of a number. Considering one more example, there is no answer for "what number when multiplied by itself results in 3" in rational numbers. So, irrational numbers are introduced and rational numbers and irrational numbers are collectively named as real numbers. Even then, there is another question which is "what number when multiplied by itself results in -1 or negative numbers" and this question has no answer in real numbers. Therefore, 'i' or imaginary number was introduced which is equal to square root of -1. Then, a general form of complex numbers is introduced which is 'a+ib' where 'a' and 'b' are real numbers. If 'b' is zero, the result is a real number. If 'a' is zero, the result is a pure complex number. If 'a' and 'b' are non zero, the result is a general complex number. Hence, 'a' and 'b' are named real and imaginary parts of a complex number respectively. Some examples of different types of numbers are:
a) (3/5) and (-2/5) are rational numbers.
b) (square root of 2) is an irrational number.
c) (5+3i), (5-2i), (2i), (2) are complex numbers.

## Properties of Complex Numbers

Conjugate : For a complex number 'a+ib', 'a-ib' is called its conjugate.
Modulus or Magnitude : For a complex number 'a+ib', sqrt(sq(a)+sq(b)) is called its modulus or magnitude where sq and sqrt stands for square and square root respectively.
Argument or Amplitude : If a complex number 'a+ib' is plotted on xy plane such that 'a' is the x coordinate and 'b' is the y coordinate, the angle made by the line joining origin and this point with x axis is called its argument or amplitude.

## Algebra of Complex Numbers

Algebra of complex numbers is similar to that of algebra of real numbers. The general operations can be defined as follows.
Addition : Consider two complex numbers (a+ib) and (c+id). The result of their addition is the complex number ((a+c)+i(b+d)) i.e. adding the corresponding real and imaginary parts.
Subtraction : Consider two complex numbers (a+ib) and (c+id). The result of their subtraction is the complex number ((a-c)+i(b-d)) i.e. subtracting the corresponding real and imaginary parts.
Multiplication : Consider two complex numbers (a+ib) and (c+id). The result of their multiplication is the complex number ((ac-bd)+i(ad+bc)) which is obtained as follows.
(a+ib)(c+id)
=a(c+id)+ib(c+id)
As square of 'i' is equal to -1
Division : Consider two complex numbers (a+ib) and (c+id). The result of their division is the complex number ((ac+bd)+i(bc-ad))/(sq(c)-sq(d)) which is obtained as follows.
(a+ib)/(c+id)
Multiplying numerator and denominator with (c-id) and using the multiplication formula

## Representations of complex numbers

General Form : 'a+ib' is a complex number in its general form or cartesian form i.e. (a,b) in cartesian coordinate system.
Euler's form : 'a+ib' in general form is identical to (r)cos(t)+i(r)sin(t) in euler's form or polar form where 'r' and 't' are magnitude and amplitude of 'a+ib' respectively. Simply, it is the representation of a complex number in polar coordinate system. (cos(t))+i(sin(t)) is also called cis(t).
GENERAL FORM : (a) + i(b) = (r)cos(t) + i(r)sin(t) : EULER'S FORM

## C Program to perform complex number operations

This is a C program which can be used to calculate properties of complex numbers or to perform basic algebraic operations on complex numbers or to convert a complex number from one form to another. The program is menu driven and contains a loop so that operations can be performed one after another without multiple compilations and executions. In additon to avoiding error outputs, this program also displays an error message if error inputs are given. In the task of conversion of a complex number from one form to another, you can specify the unit of angle i.e. degrees or radians or grades in the program itself. Also, power of a complex number to any real number can be calculated using this program.

#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<stdlib.h>
#define RD 57.2957795
#define RG 63.6619772
double argument_complex(double a,double b,double c)
{
double d;
d=(b>=0)?(acos(a/sqrt(a*a+b*b))):(-acos(a/sqrt(a*a+b*b)));
if(c!=1&&c!=2&&c!=3)
printf("\n SYNTAX ERROR:TRY AGAIN \n ");
else
d*=(c==1)?(RD):((c==2)?(1):(RG));
return(d);
}
void convert_complex(double a,double b,double c,double d,double *e,double *f)
{
if(c!=1&&c!=2)
printf("\n SYNTAX ERROR:TRY AGAIN \n ");
else
{
if(d!=1&&d!=2&&d!=3)
printf("\n SYNTAX ERROR:TRY AGAIN \n ");
else
{
if(c==1)
{
*e=sqrt(a*a+b*b);
*f=argument_complex(a,b,d);
}
else
{
b/=(d==1)?(RD):((d==2)?(1):(RG));
*e=a*cos(b);
*f=a*sin(b);
}
}
}
}
void main()
{
int choice;
double a,b,c,d,e,f,g;
clrscr();
for(choice=0;choice<=11;choice++)
{
printf("\n 1.Conjugate of (A) ");
printf(" 2.(A)+(B) ");
printf(" 3.(A)-(B) ");
printf(" 4.(A)*(B) ");
printf(" 5.(A)/(B) ");
printf(" 6.(a)+(b)i to \n\n (r,x) ");
printf(" 7.(r)cis(x) to (a,b) ");
printf(" 8.Modulus(A) ");
printf(" 9.Amplitude(A) ");
printf(" 10.[A]^(a) ");
printf(" 11.Off ");
scanf("%d",&choice);
if(choice==1)
{
printf("\n Enter {coordinates} of complex number (A):");
scanf("%lf%lf",&a,&b);
c=+1*a;
d=-1*b;
printf("\n Complex Number (A) is (%lf,%lf) \n",a,b);
printf("\n Conjugate of Complex Number (A) is {%lf,%lf} \n\n ",c,d);
}
else if(choice==2)
{
printf("\n Enter {coordinates} of complex number (A):");
scanf("%lf%lf",&a,&b);
printf("\n Enter {coordinates} of complex number (B):");
scanf("%lf%lf",&c,&d);
e=a+c;
f=b+d;
printf("\n Complex Number (A) is (%lf,%lf) \n",a,b);
printf("\n Complex Number (B) is (%lf,%lf) \n",c,d);
printf("\n Complex Number (A)+(B) is {%lf,%lf} \n\n ",e,f);
}
else if(choice==3)
{
printf("\n Enter {coordinates} of complex number (A):");
scanf("%lf%lf",&a,&b);
printf("\n Enter {coordinates} of complex number (B):");
scanf("%lf%lf",&c,&d);
e=a-c;
f=b-d;
printf("\n Complex Number (A) is (%lf,%lf) \n",a,b);
printf("\n Complex Number (B) is (%lf,%lf) \n",c,d);
printf("\n Complex Number (A)-(B) is {%lf,%lf} \n\n ",e,f);
}
else if(choice==4)
{
printf("\n Enter {coordinates} of complex number (A):");
scanf("%lf%lf",&a,&b);
printf("\n Enter {coordinates} of complex number (B):");
scanf("%lf%lf",&c,&d);
e=a*c-b*d;
f=a*d+b*c;
printf("\n Complex Number (A) is (%lf,%lf) \n",a,b);
printf("\n Complex Number (B) is (%lf,%lf) \n",c,d);
printf("\n Complex Number (A)*(B) is {%lf,%lf} \n\n ",e,f);
}
else if(choice==5)
{
printf("\n Enter {coordinates} of complex number (A):");
scanf("%lf%lf",&a,&b);
printf("\n Enter {coordinates} of complex number (B):");
scanf("%lf%lf",&c,&d);
if(c==0&&d==0)
{
printf("\n Complex Number (A) is (%lf,%lf) \n",a,b);
printf("\n Complex Number (B) is (%lf,%lf) \n",c,d);
printf("\n Complex Number (A)/(B) IS UNDEFINED:TRY AGAIN \n\n ");
}
else
{
e=(b*d+a*c)/(c*c+d*d);
f=(b*c-a*d)/(c*c+d*d);
printf("\n Complex Number (A) is (%lf,%lf) \n",a,b);
printf("\n Complex Number (B) is (%lf,%lf) \n",c,d);
printf("\n Complex Number (A)/(B) is {%lf,%lf} \n\n ",e,f);
}
}
else if(choice==6)
{
printf("\n Enter {a,b} values:");
scanf("%lf,%lf",&a,&b);
convert_complex(a,b,1,1,&c,&d);
printf("\n GENERAL FORM:(%lf,%lf) \n ",a,b);
printf("\n EULER'S FORM:{%lf,%lf} \n\n ",c,d);
}
else if(choice==7)
{
printf("\n Enter {r,x} values:");
scanf("%lf,%lf",&a,&b);
convert_complex(a,b,2,1,&c,&d);
printf("\n EULER'S FORM:(%lf,%lf) \n ",a,b);
printf("\n GENERAL FORM:{%lf,%lf} \n\n ",c,d);
}
else if(choice==8)
{
printf("\n Enter {coordinates} of complex number (A):");
scanf("%lf%lf",&a,&b);
c=sqrt(a*a+b*b);
printf("\n Complex Number (A) is (%lf,%lf) \n",a,b);
printf("\n Modulus of Complex Number (A) is {%lf} \n\n ",c);
}
else if(choice==9)
{
printf("\n Enter {coordinates} of complex number (A):");
scanf("%lf%lf",&a,&b);
c=argument_complex(a,b,1);
printf("\n Complex Number (A) is (%lf,%lf) \n",a,b);
printf("\n Amplitude of Complex number (A) is {%lf} \n\n ",c);
}
else if(choice==10)
{
printf("\n Enter {coordinates} of complex number (A):");
scanf("%lf%lf",&a,&b);
printf("\n Enter {a} value:");
scanf("%lf",&c);
convert_complex(a,b,1,2,&d,&e);
f=pow(d,c)*cos(c*e);
g=pow(d,c)*sin(c*e);
printf("\n Complex Number (A) is (%lf,%lf) \n",a,b);
printf("\n Complex Number [A]^(%lf) is {%lf,%lf} \n\n ",c,f,g);
}
else if(choice==11)
{
printf("\n ");
exit(0);
}
else
{
printf("\n {%d} IS AN INVALID CHOICE:TRY AGAIN \n\n ",choice);
choice=0;
}
}
getch();
}

An example output of the above program is as follows.