# Difference between revisions of "Example Complex Math"

From Efficient Java Matrix Library

(Created page with " The Complex64F data type stores a single complex number. Inside the ComplexMath64F class are functions for performing standard math operations on Complex64F, such as additio...") |
|||

Line 3: | Line 3: | ||

Code on GitHub: | Code on GitHub: | ||

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

− | == Example | + | == Example == |

<syntaxhighlight lang="java"> | <syntaxhighlight lang="java"> |

## Revision as of 18:53, 31 March 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.

Code on GitHub: ExampleComplexMath

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