Example Complex Math
Jump to navigation
Jump to search
The Complex64F data type stores a single complex number. Inside the ComplexMath64F class are functions for performing standard math operations on Complex64F, such as addition and division. The example below demonstrates how to perform these operations.
External Resources:
- ExampleComplexMath.java source code
- <disqus>Discuss this example</disqus>
Example
/**
* Demonstration of different operations that can be performed on complex numbers.
*
* @author Peter Abeles
*/
public class ExampleComplexMath {
public static void main( String []args ) {
Complex_F64 a = new Complex_F64(1,2);
Complex_F64 b = new Complex_F64(-1,-0.6);
Complex_F64 c = new Complex_F64();
ComplexPolar_F64 polarC = new ComplexPolar_F64();
System.out.println("a = "+a);
System.out.println("b = "+b);
System.out.println("------------------");
ComplexMath_F64.plus(a, b, c);
System.out.println("a + b = "+c);
ComplexMath_F64.minus(a, b, c);
System.out.println("a - b = "+c);
ComplexMath_F64.multiply(a, b, c);
System.out.println("a * b = "+c);
ComplexMath_F64.divide(a, b, c);
System.out.println("a / b = "+c);
System.out.println("------------------");
ComplexPolar_F64 polarA = new ComplexPolar_F64();
ComplexMath_F64.convert(a, polarA);
System.out.println("polar notation of a = "+polarA);
ComplexMath_F64.pow(polarA, 3, polarC);
System.out.println("a ** 3 = "+polarC);
ComplexMath_F64.convert(polarC, c);
System.out.println("a ** 3 = "+c);
}
}