Difference between revisions of "Example Complex Math"
Jump to navigation
Jump to search
Line 3: | Line 3: | ||
External Resources: | External Resources: | ||
− | * [https://github.com/lessthanoptimal/ejml/blob/v0. | + | * [https://github.com/lessthanoptimal/ejml/blob/v0.31/examples/src/org/ejml/example/ExampleComplexMath.java ExampleComplexMath.java source code] |
* <disqus>Discuss this example</disqus> | * <disqus>Discuss this example</disqus> | ||
Line 17: | Line 17: | ||
public static void main( String []args ) { | 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("a = "+a); | ||
Line 26: | Line 26: | ||
System.out.println("------------------"); | System.out.println("------------------"); | ||
− | + | ComplexMath_F64.plus(a, b, c); | |
System.out.println("a + b = "+c); | System.out.println("a + b = "+c); | ||
− | + | ComplexMath_F64.minus(a, b, c); | |
System.out.println("a - b = "+c); | System.out.println("a - b = "+c); | ||
− | + | ComplexMath_F64.multiply(a, b, c); | |
System.out.println("a * b = "+c); | System.out.println("a * b = "+c); | ||
− | + | ComplexMath_F64.divide(a, b, c); | |
System.out.println("a / b = "+c); | System.out.println("a / b = "+c); | ||
System.out.println("------------------"); | System.out.println("------------------"); | ||
− | + | ComplexPolar_F64 polarA = new ComplexPolar_F64(); | |
− | + | ComplexMath_F64.convert(a, polarA); | |
System.out.println("polar notation of a = "+polarA); | System.out.println("polar notation of a = "+polarA); | ||
− | + | ComplexMath_F64.pow(polarA, 3, polarC); | |
System.out.println("a ** 3 = "+polarC); | System.out.println("a ** 3 = "+polarC); | ||
− | + | ComplexMath_F64.convert(polarC, c); | |
System.out.println("a ** 3 = "+c); | System.out.println("a ** 3 = "+c); | ||
} | } | ||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> |
Latest revision as of 17:16, 18 May 2017
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);
}
}