public class Complex
extends java.lang.Object
Constructor and Description |
---|
Complex()
Create a default complex number
|
Complex(double real)
Create a complex number from a real one
|
Complex(double real,
double imaginary)
Create a complex number from the real and imaginary parts
|
Modifier and Type | Method and Description |
---|---|
void |
addComplex(Complex a,
Complex b)
Method to add two complex numbers.
|
void |
divideComplex(Complex a,
Complex b)
Method to divide two complex numbers.
|
double |
getImaginary()
Returns the imaginary part of this Complex number.
|
double |
getReal()
Returns the real part of this Complex number.
|
void |
multiplyComplex(Complex a,
Complex b)
Method to multiply two complex numbers.
|
void |
reset()
Sets both the real and imaginary parts of this complex number to zero.
|
void |
scaleComplex(Complex a,
double b)
Method to scale a complex number by a real one.
|
void |
set(double real,
double imaginary)
Sets the real and imaginary parts of this complex number.
|
double |
squaredMagnitudeComplex()
Method to compute the squared magnitude of a complex number.
|
void |
subtractComplex(Complex a,
Complex b)
Method to subtract two complex numbers.
|
java.lang.String |
toString()
Returns this complex number as a string in the format (real, imaginary).
|
public Complex()
public Complex(double real)
real
- source valuepublic Complex(double real, double imaginary)
real
- real partimaginary
- imaginary partpublic double getReal()
public double getImaginary()
public void reset()
public void set(double real, double imaginary)
real
- the value of the real partimaginary
- the value of the imaginary partpublic void addComplex(Complex a, Complex b)
a
- the first element to be addedb
- the second element to be addedpublic void subtractComplex(Complex a, Complex b)
a
- the element we subtract fromb
- the element to be subtractedpublic void multiplyComplex(Complex a, Complex b)
a
- the first element to multiplyb
- the second element to multiplypublic void divideComplex(Complex a, Complex b)
a
- the numeratorb
- the denominatorpublic void scaleComplex(Complex a, double b)
a
- the complex numberb
- the real scaling factorpublic double squaredMagnitudeComplex()
public java.lang.String toString()
toString
in class java.lang.Object