1 package org.djutils.complex.demo;
2
3 import org.djutils.complex.Complex;
4 import org.djutils.complex.ComplexMath;
5
6
7
8
9
10
11
12
13
14
15
16 public final class ComplexDemo
17 {
18
19
20
21 private ComplexDemo()
22 {
23
24 }
25
26
27
28
29
30 public static void main(final String[] args)
31 {
32 constructors();
33 System.out.println();
34 fieldsGettersNormAndPhi();
35 System.out.println();
36 constants();
37 System.out.println();
38 binaryOps();
39 System.out.println();
40 mathFunctions();
41 }
42
43
44
45
46 public static void constructors()
47 {
48 Complex z1 = new Complex(123.456, -345.678);
49 System.out.println(z1);
50 Complex z2 = new Complex(543.210);
51 System.out.println(z2);
52 }
53
54
55
56
57 public static void fieldsGettersNormAndPhi()
58 {
59 Complex z = new Complex(123.456, -345.678);
60 System.out.println("re=" + z.re + ", im=" + z.im + ", getRe:" + z.getRe() + ", getIm:" + z.getIm() + ", norm:"
61 + z.norm() + ", phi:" + z.phi());
62 }
63
64
65
66
67 public static void constants()
68 {
69 System.out.println("ZERO=" + Complex.ZERO);
70 System.out.println("ONE=" + Complex.ONE);
71 System.out.println("MINUS_ONE=" + Complex.MINUS_ONE);
72 System.out.println("I=" + Complex.I);
73 System.out.println("MINUS_I=" + Complex.MINUS_I);
74 }
75
76
77
78
79 public static void binaryOps()
80 {
81 Complex z1 = new Complex(3, 4);
82 Complex z2 = new Complex(-2, 5);
83 System.out.println("z1=" + z1);
84 System.out.println("z2=" + z2);
85 System.out.println("z1 + z2=" + z1.plus(z2));
86 System.out.println("z1 - z2=" + z1.minus(z2));
87 System.out.println("z1 * z2=" + z1.times(z2));
88 System.out.println("z1 / z2=" + z1.divideBy(z2));
89 System.out.println("z1 * I=" + z1.times(Complex.I));
90 System.out.println("I * I=" + Complex.I.times(Complex.I));
91 }
92
93
94
95
96 public static void mathFunctions()
97 {
98 Complex z = new Complex(3, -5);
99 System.out.println(z);
100 System.out.println(ComplexMath.sqrt(z));
101 System.out.println(ComplexMath.sqrt(z).rotate(Math.PI));
102 System.out.println(ComplexMath.sqrt(z).times(-1));
103 System.out.println(ComplexMath.cbrt(z));
104 System.out.println(ComplexMath.cbrt(z).rotate(2 * Math.PI / 3));
105 System.out.println(ComplexMath.cbrt(z).rotate(4 * Math.PI / 3));
106 System.out.println(ComplexMath.exp(z));
107 System.out.println(ComplexMath.ln(z));
108 System.out.println(ComplexMath.sin(z));
109 System.out.println(ComplexMath.cos(z));
110 System.out.println(ComplexMath.tan(z));
111 System.out.println(ComplexMath.asin(z));
112 System.out.println(ComplexMath.acos(z));
113 System.out.println(ComplexMath.atan(z));
114 System.out.println(ComplexMath.sinh(z));
115 System.out.println(ComplexMath.cosh(z));
116 System.out.println(ComplexMath.tanh(z));
117 System.out.println(ComplexMath.asinh(z));
118 System.out.println(ComplexMath.acosh(z));
119 System.out.println(ComplexMath.atanh(z));
120 }
121
122 }