mathajax

Complex number Multiplication and Division

The arithmetic operation like multiplication and division over two Complex numbers is explained

two complex numbers multiplication and division

Complex number Multiplication

multiply two complex numbers z1 and z2. note i^2 = -1


       z1 =  a + bi
       z2 =  c + di

      z1*z2   =   (a+bi)  * (c+di)
              =   a*c + a*di  + bi*c + bi*di
              =   a*c + a*di  + bi*c + b*d*(i^2)
              =   a*c + a*di  + bi*c  + b*d*(-1)
              =   a*c + a*di  + c*bi - b*d
              =  (a*c - b*d)  + (a*di + c*bi)


Complex number Division

divide two complex numbers z1 and z2. note i^2= -1


       z1 =  a + bi
       z2 =  c + di
   
       z1 / z2   =   (a+bi )  / (c+di)

  multiply numerator and denumerator by conjugate  z2
  
      conjugate z2  =  c  + (-1)* di
                          =  c  - di

      z1 / z2   =   (a+bi) (c-di)  /  (c+di ) (c-di)   

     (a+bi) (c-di)   =  a*c - a*di + c*bi   -bi*di
                     =  a*c - a*di + c*bi   -b*d*(i^2)
                     =  a*c - a*di + c*bi   -b*d*(-1)  
                     =  a*c - a*di + c*bi   +b*d
              =  (a*c + b*d)  - a*di + c*bi  
   
   (c+di) (c-di)  =  c*c  - c*di + c*di - di*di
                  =  c^2  - d^2 i^2
                  = c^2  - d^2 (-1)
                  = c^2  + d^2

  z1 / z2   =      (a*c + b*d)  + (c*di - a*bi)   /  c^2  + d^2


Java code - Complex multiplication and division

The following Java code implements arithmetic operation multiplication and division on two Complex numbers



package math.complex;

public class MulDiv {

 public static Complex multiply(Complex C1,Complex C2) 
     {
  
     Complex tmp = new Complex();     
     tmp.real = C1.real * C2.real;
     tmp.imag = C1.real * C2.imag;     
     
     tmp.imag += C1.imag * C2.real;
     tmp.real += C1.imag * C2.imag*(-1);
     
     return tmp;
    }

  public static Complex divide(Complex C1,Complex C2){
  
    Complex conjc2 = C2.conjucate();  
    Complex numr  = MulDiv.multiply(C1, conjc2);
    Complex demr  = MulDiv.multiply(C2, conjc2);    
      
    double dval =  demr.real + demr.imag;  
    Complex tmp = new Complex ( numr.real/dval,  numr.imag/dval );
    return tmp;
  
 }

 
  public static void main(String[] args) {
  
  
 System.out.println("Complex Number Arithmetic Operation in java n");
  
  System.out.println("Complex Number Multiplication n");        
  Complex C1 = new Complex(-1,2);
  System.out.println("Complex  C1: " +C1);  
  Complex C2 = new Complex(2,-1);
  System.out.println("Complex  C2: " +C2);
  
  Complex C3= MulDiv.multiply(C1, C2);
  System.out.println("C3 = C1 x C2 : " + C3 );
  
  
  System.out.println("Complex Number Division  n");
    
  System.out.println("Complex  C1: " +C1);    
  System.out.println("Complex  C2: " +C2);
  Complex C4= MulDiv.divide(C1, C2);
  System.out.println("C4 = C1 / C2 : " +C4);

 }

}


Output


Complex Number Arithmetic Operation in java 

Complex Number Multiplication 

Complex  C1: -1.0+2.0i
Complex  C2: 2.0-1.0i
C3 = C1 x C2 : 0.0+5.0i

Complex Number Division  

Complex  C1: -1.0+2.0i
Complex  C2: 2.0-1.0i
C4 = C1 / C2 : -0.8+0.6i

Comments

Popular posts from this blog

Matrix Forward and Back Substitution

Chebyshev distance between two points

Solve System of Linear Equations by LU Decompose

Solving System of Linear Equations by Gauss Jordan Elimination