mathajax

Complex number

A complex number consists of two parts; one is the real part and other imaginary part. The real part is marked on x-axis and the imaginary part on the y-axis on the complex plane.

   
     A complex number   z=  a + bi
                        a    -  Real part  
                        b    -  imaginary part  

complex number on complex plane

Complex Conjugate

A complex numbers can be converted into complex conjugate by simply multiplying (-1) with imaginary parts. It causes the complex point on first quadrant moves to forth quadrant and vice versa. Similarly,the complex point on second quadrant moves to third quadrant and vice versa.
   Complex   z=  a +bi
   conjugate  =  a + (-1)bi = a - bi

Complex - Absolute

An absolute value of a complex number is found by the distance between origin and complex number on the complex plane.
    
           A complex number   =  a + bi

           Absolute value =    sqrt ( a^2 + b^2 )
   

The Java programming code - Complex number

The following code explains how to represent complex number in Java programming and also finds their absolute value and complex conjugate


public class Complex {
 public double real,imag; 

 public Complex() {
     real =0; 
     imag=0;
 }
 
 public Complex(double real,double imag) {
     this.real =real; 
     this.imag=imag;
 }
 
 public double abs() {
     
     double absval = Math.pow(real,2.0) + Math.pow(imag,2.0);
     return ( Math.sqrt(absval)  ); 
 }

 public Complex conjucate() {
     return new Complex(this.real,(-1)*this.imag); 
 }
   
 public String toString() 
   {   
    String str1= this.real+"+"+this.imag+"i";
    String str2= this.real+"-"+Math.abs(this.imag)+"i";    
    return (imag>0) ?  str1  : str2;  
 }
 
  public static void main(String[] args) 
   {
  
 System.out.println("Complex Number System in Java");
    
 Complex C1 = new Complex(2,-3);
 Complex C2 = new Complex(-4,2);  
 System.out.println("Complex  C1:" +C1);    
 System.out.println("Complex  C2:" +C2);
      
 System.out.println("nComplex Conjugate");  
 Complex C3 = C1.conjucate();
 Complex C4 = C1.conjucate();
 System.out.println("Conjugate of  C1:" +C3);    
 System.out.println("Conjucate of  C2:" +C4);     
    }

}


Output


Complex Number System in Java
Complex  C1: 2.0-3.0i
Complex  C2: -4.0+2.0i

Complex Conjugate
Conjugate of  C1 :2.0+3.0i
Conjucate of  C2 :-4.0-2.0i

Complex Absolute
abs  C1 :  3.605
abs  C2 :  4.472


Comments

Popular posts from this blog

Solving System of Linear Equations by Gauss Jordan Elimination

Matrix Forward and Back Substitution

Solve System of Linear Equations by LU Decompose

Chebyshev distance between two points

Distance Metric - Euclidean Distance