1Complex(3)            User Contributed Perl Documentation           Complex(3)
2
3
4

NAME

6       PDL::Complex - handle complex numbers
7

SYNOPSIS

9         use PDL;
10         use PDL::Complex;
11

DESCRIPTION

13       This module features a growing number of functions manipulating complex
14       numbers. These are usually represented as a pair "[ real imag ]" or "[
15       angle phase ]". If not explicitly mentioned, the functions can work
16       inplace (not yet implemented!!!) and require rectangular form.
17
18       While there is a procedural interface available ("$a/$b*$c <=> Cmul
19       (Cdiv $a, $b), $c)"), you can also opt to cast your pdl's into the
20       "PDL::Complex" datatype, which works just like your normal piddles, but
21       with all the normal perl operators overloaded.
22
23       The latter means that "sin($a) + $b/$c" will be evaluated using the
24       normal rules of complex numbers, while other pdl functions (like "max")
25       just treat the piddle as a real-valued piddle with a lowest dimension
26       of size 2, so "max" will return the maximum of all real and imaginary
27       parts, not the "highest" (for some definition)
28

TIPS, TRICKS & CAVEATS

30       ·   "i" is a constant exported by this module, which represents
31           "-1**0.5", i.e. the imaginary unit. it can be used to quickly and
32           conveniently write complex constants like this: "4+3*i".
33
34       ·   Use "r2C(real-values)" to convert from real to complex, as in "$r =
35           Cpow $cplx, r2C 2". The overloaded operators automatically do that
36           for you, all the other functions, do not. So "Croots 1, 5" will
37           return all the fifths roots of 1+1*i (due to threading).
38
39       ·   use "cplx(real-valued-piddle)" to cast from normal piddles into the
40           complex datatype. Use "real(complex-valued-piddle)" to cast back.
41           This requires a copy, though.
42
43       ·   This module has received some testing by Vanuxem Grégory (g.vanuxem
44           at wanadoo dot fr). Please report any other errors you come across!
45

EXAMPLE WALK-THROUGH

47       The complex constant five is equal to "pdl(1,0)":
48
49          pdl> p $x = r2C 5
50          5 +0i
51
52       Now calculate the three cubic roots of of five:
53
54          pdl> p $r = Croots $x, 3
55          [1.70998 +0i  -0.854988 +1.48088i  -0.854988 -1.48088i]
56
57       Check that these really are the roots:
58
59          pdl> p $r ** 3
60          [5 +0i  5 -1.22465e-15i  5 -7.65714e-15i]
61
62       Duh! Could be better. Now try by multiplying $r three times with
63       itself:
64
65          pdl> p $r*$r*$r
66          [5 +0i  5 -4.72647e-15i  5 -7.53694e-15i]
67
68       Well... maybe "Cpow" (which is used by the "**" operator) isn't as bad
69       as I thought. Now multiply by "i" and negate, which is just a very
70       expensive way of swapping real and imaginary parts.
71
72          pdl> p -($r*i)
73          [0 -1.70998i  1.48088 +0.854988i  -1.48088 +0.854988i]
74
75       Now plot the magnitude of (part of) the complex sine. First generate
76       the coefficients:
77
78          pdl> $sin = i * zeroes(50)->xlinvals(2,4) + zeroes(50)->xlinvals(0,7)
79
80       Now plot the imaginary part, the real part and the magnitude of the
81       sine into the same diagram:
82
83          pdl> use PDL::Graphics::Gnuplot
84          pdl> gplot( with => 'lines',
85                     PDL::cat(im ( sin $sin ),
86                              re ( sin $sin ),
87                              abs( sin $sin ) ))
88
89       An ASCII version of this plot looks like this:
90
91         30 ++-----+------+------+------+------+------+------+------+------+-----++
92            +      +      +      +      +      +      +      +      +      +      +
93            |                                                                   $$|
94            |                                                                  $  |
95         25 ++                                                               $$  ++
96            |                                                              ***    |
97            |                                                            **   *** |
98            |                                                         $$*        *|
99         20 ++                                                       $**         ++
100            |                                                     $$$*           #|
101            |                                                  $$$   *          # |
102            |                                                $$     *           # |
103         15 ++                                            $$$       *          # ++
104            |                                          $$$        **           #  |
105            |                                      $$$$          *            #   |
106            |                                  $$$$              *            #   |
107         10 ++                            $$$$$                 *            #   ++
108            |                        $$$$$                     *             #    |
109            |                 $$$$$$$                         *             #     |
110          5 ++       $$$############                          *             #    ++
111            |*****$$$###            ###                      *             #      |
112            *    #*****                #                     *             #      |
113            | ###      ***              ###                **              #      |
114          0 ##            ***              #              *               #      ++
115            |                *              #             *              #        |
116            |                 ***            #          **               #        |
117            |                    *            #        *                #         |
118         -5 ++                    **           #      *                 #        ++
119            |                       ***         ##  **                 #          |
120            |                          *          #*                  #           |
121            |                           ****    ***##                #            |
122        -10 ++                              ****     #              #            ++
123            |                                         #             #             |
124            |                                          ##         ##              |
125            +      +      +      +      +      +      +  ### + ###  +      +      +
126        -15 ++-----+------+------+------+------+------+-----###-----+------+-----++
127            0      5      10     15     20     25     30     35     40     45     50
128

FUNCTIONS

130   cplx real-valued-pdl
131       Cast a real-valued piddle to the complex datatype. The first dimension
132       of the piddle must be of size 2. After this the usual (complex)
133       arithmetic operators are applied to this pdl, rather than the normal
134       elementwise pdl operators.  Dataflow to the complex parent works. Use
135       "sever" on the result if you don't want this.
136
137   complex real-valued-pdl
138       Cast a real-valued piddle to the complex datatype without dataflow and
139       inplace. Achieved by merely reblessing a piddle. The first dimension of
140       the piddle must be of size 2.
141
142   real cplx-valued-pdl
143       Cast a complex valued pdl back to the "normal" pdl datatype. Afterwards
144       the normal elementwise pdl operators are used in operations. Dataflow
145       to the real parent works. Use "sever" on the result if you don't want
146       this.
147
148   r2C
149         Signature: (r(); [o]c(m=2))
150
151       convert real to complex, assuming an imaginary part of zero
152
153       r2C does not process bad values.  It will set the bad-value flag of all
154       output piddles if the flag is set for any of the input piddles.
155
156   i2C
157         Signature: (r(); [o]c(m=2))
158
159       convert imaginary to complex, assuming a real part of zero
160
161       i2C does not process bad values.  It will set the bad-value flag of all
162       output piddles if the flag is set for any of the input piddles.
163
164   Cr2p
165         Signature: (r(m=2); float+ [o]p(m=2))
166
167       convert complex numbers in rectangular form to polar (mod,arg) form.
168       Works inplace
169
170       Cr2p does not process bad values.  It will set the bad-value flag of
171       all output piddles if the flag is set for any of the input piddles.
172
173   Cp2r
174         Signature: (r(m=2); [o]p(m=2))
175
176       convert complex numbers in polar (mod,arg) form to rectangular form.
177       Works inplace
178
179       Cp2r does not process bad values.  It will set the bad-value flag of
180       all output piddles if the flag is set for any of the input piddles.
181
182   Cmul
183         Signature: (a(m=2); b(m=2); [o]c(m=2))
184
185       complex multiplication
186
187       Cmul does not process bad values.  It will set the bad-value flag of
188       all output piddles if the flag is set for any of the input piddles.
189
190   Cprodover
191         Signature: (a(m=2,n); [o]c(m=2))
192
193       Project via product to N-1 dimension
194
195       Cprodover does not process bad values.  It will set the bad-value flag
196       of all output piddles if the flag is set for any of the input piddles.
197
198   Cscale
199         Signature: (a(m=2); b(); [o]c(m=2))
200
201       mixed complex/real multiplication
202
203       Cscale does not process bad values.  It will set the bad-value flag of
204       all output piddles if the flag is set for any of the input piddles.
205
206   Cdiv
207         Signature: (a(m=2); b(m=2); [o]c(m=2))
208
209       complex division
210
211       Cdiv does not process bad values.  It will set the bad-value flag of
212       all output piddles if the flag is set for any of the input piddles.
213
214   Ccmp
215         Signature: (a(m=2); b(m=2); [o]c())
216
217       Complex comparison oeprator (spaceship). It orders by real first, then
218       by imaginary. Hm, but it is mathematical nonsense! Complex numbers
219       cannot be ordered.
220
221       Ccmp does not process bad values.  It will set the bad-value flag of
222       all output piddles if the flag is set for any of the input piddles.
223
224   Cconj
225         Signature: (a(m=2); [o]c(m=2))
226
227       complex conjugation. Works inplace
228
229       Cconj does not process bad values.  It will set the bad-value flag of
230       all output piddles if the flag is set for any of the input piddles.
231
232   Cabs
233         Signature: (a(m=2); [o]c())
234
235       complex "abs()" (also known as modulus)
236
237       Cabs does not process bad values.  It will set the bad-value flag of
238       all output piddles if the flag is set for any of the input piddles.
239
240   Cabs2
241         Signature: (a(m=2); [o]c())
242
243       complex squared "abs()" (also known squared modulus)
244
245       Cabs2 does not process bad values.  It will set the bad-value flag of
246       all output piddles if the flag is set for any of the input piddles.
247
248   Carg
249         Signature: (a(m=2); [o]c())
250
251       complex argument function ("angle")
252
253       Carg does not process bad values.  It will set the bad-value flag of
254       all output piddles if the flag is set for any of the input piddles.
255
256   Csin
257         Signature: (a(m=2); [o]c(m=2))
258
259         sin (a) = 1/(2*i) * (exp (a*i) - exp (-a*i)). Works inplace
260
261       Csin does not process bad values.  It will set the bad-value flag of
262       all output piddles if the flag is set for any of the input piddles.
263
264   Ccos
265         Signature: (a(m=2); [o]c(m=2))
266
267         cos (a) = 1/2 * (exp (a*i) + exp (-a*i)). Works inplace
268
269       Ccos does not process bad values.  It will set the bad-value flag of
270       all output piddles if the flag is set for any of the input piddles.
271
272   Ctan a [not inplace]
273         tan (a) = -i * (exp (a*i) - exp (-a*i)) / (exp (a*i) + exp (-a*i))
274
275   Cexp
276         Signature: (a(m=2); [o]c(m=2))
277
278       exp (a) = exp (real (a)) * (cos (imag (a)) + i * sin (imag (a))). Works
279       inplace
280
281       Cexp does not process bad values.  It will set the bad-value flag of
282       all output piddles if the flag is set for any of the input piddles.
283
284   Clog
285         Signature: (a(m=2); [o]c(m=2))
286
287       log (a) = log (cabs (a)) + i * carg (a). Works inplace
288
289       Clog does not process bad values.  It will set the bad-value flag of
290       all output piddles if the flag is set for any of the input piddles.
291
292   Cpow
293         Signature: (a(m=2); b(m=2); [o]c(m=2))
294
295       complex "pow()" ("**"-operator)
296
297       Cpow does not process bad values.  It will set the bad-value flag of
298       all output piddles if the flag is set for any of the input piddles.
299
300   Csqrt
301         Signature: (a(m=2); [o]c(m=2))
302
303       Works inplace
304
305       Csqrt does not process bad values.  It will set the bad-value flag of
306       all output piddles if the flag is set for any of the input piddles.
307
308   Casin
309         Signature: (a(m=2); [o]c(m=2))
310
311       Works inplace
312
313       Casin does not process bad values.  It will set the bad-value flag of
314       all output piddles if the flag is set for any of the input piddles.
315
316   Cacos
317         Signature: (a(m=2); [o]c(m=2))
318
319       Works inplace
320
321       Cacos does not process bad values.  It will set the bad-value flag of
322       all output piddles if the flag is set for any of the input piddles.
323
324   Catan cplx [not inplace]
325       Return the complex "atan()".
326
327   Csinh
328         Signature: (a(m=2); [o]c(m=2))
329
330         sinh (a) = (exp (a) - exp (-a)) / 2. Works inplace
331
332       Csinh does not process bad values.  It will set the bad-value flag of
333       all output piddles if the flag is set for any of the input piddles.
334
335   Ccosh
336         Signature: (a(m=2); [o]c(m=2))
337
338         cosh (a) = (exp (a) + exp (-a)) / 2. Works inplace
339
340       Ccosh does not process bad values.  It will set the bad-value flag of
341       all output piddles if the flag is set for any of the input piddles.
342
343   Ctanh
344         Signature: (a(m=2); [o]c(m=2))
345
346       Works inplace
347
348       Ctanh does not process bad values.  It will set the bad-value flag of
349       all output piddles if the flag is set for any of the input piddles.
350
351   Casinh
352         Signature: (a(m=2); [o]c(m=2))
353
354       Works inplace
355
356       Casinh does not process bad values.  It will set the bad-value flag of
357       all output piddles if the flag is set for any of the input piddles.
358
359   Cacosh
360         Signature: (a(m=2); [o]c(m=2))
361
362       Works inplace
363
364       Cacosh does not process bad values.  It will set the bad-value flag of
365       all output piddles if the flag is set for any of the input piddles.
366
367   Catanh
368         Signature: (a(m=2); [o]c(m=2))
369
370       Works inplace
371
372       Catanh does not process bad values.  It will set the bad-value flag of
373       all output piddles if the flag is set for any of the input piddles.
374
375   Cproj
376         Signature: (a(m=2); [o]c(m=2))
377
378       compute the projection of a complex number to the riemann sphere. Works
379       inplace
380
381       Cproj does not process bad values.  It will set the bad-value flag of
382       all output piddles if the flag is set for any of the input piddles.
383
384   Croots
385         Signature: (a(m=2); [o]c(m=2,n); int n => n)
386
387       Compute the "n" roots of "a". "n" must be a positive integer. The
388       result will always be a complex type!
389
390       Croots does not process bad values.  It will set the bad-value flag of
391       all output piddles if the flag is set for any of the input piddles.
392
393   re cplx, im cplx
394       Return the real or imaginary part of the complex number(s) given. These
395       are slicing operators, so data flow works. The real and imaginary parts
396       are returned as piddles (ref eq PDL).
397
398   rCpolynomial
399         Signature: (coeffs(n); x(c=2,m); [o]out(c=2,m))
400
401       evaluate the polynomial with (real) coefficients "coeffs" at the
402       (complex) position(s) "x". "coeffs[0]" is the constant term.
403
404       rCpolynomial does not process bad values.  It will set the bad-value
405       flag of all output piddles if the flag is set for any of the input
406       piddles.
407

AUTHOR

409       Copyright (C) 2000 Marc Lehmann <pcg@goof.com>.  All rights reserved.
410       There is no warranty. You are allowed to redistribute this software /
411       documentation as described in the file COPYING in the PDL distribution.
412

SEE ALSO

414       perl(1), PDL.
415
416
417
418perl v5.28.1                      2019-02-14                        Complex(3)
Impressum