2 summary:: complex number
4 related::Classes/Polar, Classes/SimpleNumber, Classes/Float, Classes/Integer
7 A class representing complex numbers.
8 Note that this is a simplified representation of a complex number, which does not implement the full mathematical notion of a complex number.
12 Create a new complex number with the given real and imaginary parts.
18 returns:: a new instance of Complex.
28 subsection:: math support
30 The real part of the number.
33 The imaginary part of the number.
36 the complex conjugate.
39 Complex(2, 9).conjugate
46 Complex(2, 9) + Complex(-6, 2)
53 Complex(2, 9) - Complex(-6, 2)
57 Complex multiplication
60 Complex(2, 9) * Complex(-6, 2)
67 Complex(2, 9) / Complex(-6, 2)
71 Complex exponentiation with base e.
77 exp(Complex(0, pi)) == -1 // Euler's formula: true
81 Complex self multiplication.
84 squared(Complex(2, 1))
88 complex triple self multiplication.
95 Complex exponentiation
97 not implemented for all combinations - some are mathematically ambiguous.
105 Complex(2, 9) ** 1.2 // not defined
110 the comparison of just the real parts.
113 Complex(2, 9) < Complex(5, 1);
117 the comparison assuming that the reals (floats) are fully embedded in the complex numbers
121 Complex(1, 5) == Complex(1, 5);
125 negation of both parts
132 the absoulte value of a complex number is its magnitude.
139 distance to the origin.
141 method:: magnitudeApx
144 the distance to the origin.
146 method:: angle, phase, theta
147 the angle in radians.
150 subsection:: conversion
152 Convert to a link::Classes/Point::.
158 real part as link::Classes/Integer::.
161 real part as link::Classes/Float::.
172 print this on given stream
173 method:: performBinaryOpOnSignal
174 method:: performBinaryOpOnComplex
175 method:: performBinaryOpOnSimpleNumber
176 method:: performBinaryOpOnUGen
186 a * a; // returns Complex(-1, 0);
189 Julia set approximation:
191 f = { |z| z * z + Complex(0.70176, 0.3842) };
194 var n = 80, xs = 400, ys = 400, dx = xs / n, dy = ys / n, zoom = 3, offset = -0.5;
195 var field = { |x| { |y| Complex(x / n + offset * zoom, y / n + offset * zoom) } ! n } ! n;
197 w = Window("Julia set", bounds:Rect(200, 200, xs, ys)).front;
198 w.view.background_(Color.black);
205 Pen.color = Color.gray(z.rho.linlin(-100, 100, 1, 0));
207 Rect(x * dx, y * dy, dx, dy)
214 fork({ 6.do { w.refresh; 2.wait } }, AppClock)