Addition and subtraction
Addition of two complex numbers can be done geometrically by constructing a parallelogram.
Complex numbers are
added by adding the real and imaginary parts of the summands. That is to say:
Similarly,
subtraction is defined by
Using the visualization of complex numbers in the complex plane, the
addition has the following geometric interpretation: the sum of two
complex numbers
A and
B, interpreted as points of the complex plane, is the point
X obtained by building a
parallelogram three of whose vertices are
O,
A and
B. Equivalently,
X is the point such that the
triangles with vertices
O,
A,
B, and
X,
B,
A, are
congruent.
Multiplication and division
The multiplication of two complex numbers is defined by the following formula:
In particular, the
square of the imaginary unit is −1:
The preceding definition of multiplication of general complex numbers
follows naturally from this fundamental property of the imaginary unit.
Indeed, if
i is treated as a number so that
di means
d times
i, the above multiplication rule is identical to the usual rule for multiplying two sums of two terms.
 (distributive law)

 (commutative law of addition—the order of the summands can be changed)
 (commutative and distributive laws)
 (fundamental property of the imaginary unit).
The division of two complex numbers is defined in terms of complex
multiplication, which is described above, and real division. When at
least one of
c and
d is nonzero, we have
Division can be defined in this way because of the following observation:
As shown earlier,
c − di is the complex conjugate of the denominator
c + di. At least one of the real part
c and the imaginary part
d of the
denominator must be nonzero for division to be defined. This is called "
rationalization" of the denominator (although the denominator in the final expression might be an irrational real number).
public class Complex {
private double real;
private double imaginary;
public double getReal() {
return this.real;
}
public void setReal(double real) {
this.real = real;
}
public double getImaginary() {
return this.imaginary;
}
public void setImaginary(double imaginary) {
this.imaginary = imaginary;
}
public Complex() {
this.setReal(0);
this.setImaginary(0);
}
public Complex(double real, double imaginary){
this.setReal(real);
this.setImaginary(imaginary);
}
public void setRealAndImaginary(double real, double imaginary){
this.setReal(real);
this.setImaginary(imaginary);
}
@Override
public String toString() {
return "Values : [ (" + real + " ) + (" + imaginary + " i ) ]";
}
public Complex addition(Complex temp){
Complex result = new Complex();
result.real = this.getReal() + temp.getReal();
result.imaginary = this.getImaginary() + temp.getImaginary();
return result;
}
public Complex subtraction(Complex temp){
Complex result = new Complex();
result.real = this.getReal()  temp.getReal();
result.imaginary = this.getImaginary()  temp.getImaginary();
return result;
}
public Complex multiplication(Complex temp){
Complex result = new Complex();
result.real = ( this.getReal() * temp.getReal() )  ( this.getImaginary() * temp.getImaginary());
result.imaginary = ( this.getReal() * temp.getImaginary() ) + ( this.getImaginary() * temp.getReal());
return result;
}
public Complex division(Complex temp){
Complex result = new Complex();
result.real = ((( this.getReal() * temp.getReal() ) + ( this.getImaginary() * temp.getImaginary())) / (Math.pow(temp.getReal(), 2) + Math.pow(temp.getImaginary(), 2)));
result.imaginary =((( this.getReal() * temp.getImaginary() )  ( this.getImaginary() * temp.getReal() )) / (Math.pow(temp.getReal(), 2) + Math.pow(temp.getImaginary(), 2)));
return result;
}
public static void main(String[] args) {
Complex complex = new Complex();
Complex complex1 = new Complex(2,1);
Complex complex2 = new Complex(3,4);
System.out.println("complex " + complex);
System.out.println("complex1 " + complex1);
System.out.println("complex2 " + complex2);
System.out.println("\n\n\nAddition " + complex1.addition(complex2));
System.out.println("Subtraction " + complex1.subtraction(complex2));
System.out.println("Multiplication " + complex1.multiplication(complex2));
System.out.println("Division " + complex1.division(complex2));
}
}
Comments
Post a Comment