Difference between revisions of "Example Complex Math"

From Efficient Java Matrix Library
Jump to: navigation, search
 
Line 3: Line 3:
  
 
External Resources:
 
External Resources:
* [https://github.com/lessthanoptimal/ejml/blob/v0.27/examples/src/org/ejml/example/ExampleComplexMath.java ExampleComplexMath.java source code]
+
* [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 ) {
         Complex64F a = new Complex64F(1,2);
+
         Complex_F64 a = new Complex_F64(1,2);
         Complex64F b = new Complex64F(-1,-0.6);
+
         Complex_F64 b = new Complex_F64(-1,-0.6);
         Complex64F c = new Complex64F();
+
         Complex_F64 c = new Complex_F64();
         ComplexPolar64F polarC = new ComplexPolar64F();
+
         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("------------------");
  
         ComplexMath64F.plus(a, b, c);
+
         ComplexMath_F64.plus(a, b, c);
 
         System.out.println("a + b = "+c);
 
         System.out.println("a + b = "+c);
         ComplexMath64F.minus(a, b, c);
+
         ComplexMath_F64.minus(a, b, c);
 
         System.out.println("a - b = "+c);
 
         System.out.println("a - b = "+c);
         ComplexMath64F.multiply(a, b, c);
+
         ComplexMath_F64.multiply(a, b, c);
 
         System.out.println("a * b = "+c);
 
         System.out.println("a * b = "+c);
         ComplexMath64F.divide(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("------------------");
         ComplexPolar64F polarA = new ComplexPolar64F();
+
         ComplexPolar_F64 polarA = new ComplexPolar_F64();
         ComplexMath64F.convert(a, polarA);
+
         ComplexMath_F64.convert(a, polarA);
 
         System.out.println("polar notation of a = "+polarA);
 
         System.out.println("polar notation of a = "+polarA);
         ComplexMath64F.pow(polarA, 3, polarC);
+
         ComplexMath_F64.pow(polarA, 3, polarC);
 
         System.out.println("a ** 3 = "+polarC);
 
         System.out.println("a ** 3 = "+polarC);
         ComplexMath64F.convert(polarC, c);
+
         ComplexMath_F64.convert(polarC, c);
 
         System.out.println("a ** 3 = "+c);
 
         System.out.println("a ** 3 = "+c);
 
     }
 
     }
 
}
 
}
 
</syntaxhighlight>
 
</syntaxhighlight>

Latest revision as of 18: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:

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);
    }
}