# Difference between revisions of "Example Complex Math"

From Efficient Java Matrix Library

Line 2: | Line 2: | ||

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. | 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: | |

− | [https://github.com/lessthanoptimal/ejml/blob/v0.27/examples/src/org/ejml/example/ExampleComplexMath.java ExampleComplexMath] | + | * [https://github.com/lessthanoptimal/ejml/blob/v0.27/examples/src/org/ejml/example/ExampleComplexMath.java ExampleComplexMath.java source code] |

+ | * <disqus>Discuss this example</disqus> | ||

== Example == | == Example == |

## Revision as of 18:02, 9 August 2015

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 ) {
Complex64F a = new Complex64F(1,2);
Complex64F b = new Complex64F(-1,-0.6);
Complex64F c = new Complex64F();
ComplexPolar64F polarC = new ComplexPolar64F();
System.out.println("a = "+a);
System.out.println("b = "+b);
System.out.println("------------------");
ComplexMath64F.plus(a, b, c);
System.out.println("a + b = "+c);
ComplexMath64F.minus(a, b, c);
System.out.println("a - b = "+c);
ComplexMath64F.multiply(a, b, c);
System.out.println("a * b = "+c);
ComplexMath64F.divide(a, b, c);
System.out.println("a / b = "+c);
System.out.println("------------------");
ComplexPolar64F polarA = new ComplexPolar64F();
ComplexMath64F.convert(a, polarA);
System.out.println("polar notation of a = "+polarA);
ComplexMath64F.pow(polarA, 3, polarC);
System.out.println("a ** 3 = "+polarC);
ComplexMath64F.convert(polarC, c);
System.out.println("a ** 3 = "+c);
}
}
```