1 .\" Copyright 2002 Walter Harms (walter.harms@informatik.uni-oldenburg.de)
3 .\" %%%LICENSE_START(GPL_NOVERSION_ONELINE)
4 .\" Distributed under GPL
7 .TH COMPLEX 7 2011-09-16 "" "Linux Programmer's Manual"
9 complex \- basics of complex mathematics
11 .B #include <complex.h>
13 Complex numbers are numbers of the form z = a+b*i, where a and b are
14 real numbers and i = sqrt(\-1), so that i*i = \-1.
16 There are other ways to represent that number.
17 The pair (a,b) of real
18 numbers may be viewed as a point in the plane, given by X- and
20 This same point may also be described by giving
21 the pair of real numbers (r,phi), where r is the distance to the origin O,
22 and phi the angle between the X-axis and the line Oz.
24 z = r*exp(i*phi) = r*(cos(phi)+i*sin(phi)).
26 The basic operations are defined on z = a+b*i and w = c+d*i as:
28 .B addition: z+w = (a+c) + (b+d)*i
30 .B multiplication: z*w = (a*c \- b*d) + (a*d + b*c)*i
32 .B division: z/w = ((a*c + b*d)/(c*c + d*d)) + ((b*c \- a*d)/(c*c + d*d))*i
34 Nearly all math function have a complex counterpart but there are
35 some complex-only functions.
37 Your C-compiler can work with complex numbers if it supports the C99 standard.
39 The imaginary unit is represented by I.
42 /* check that exp(i * pi) == \-1 */
43 #include <math.h> /* for atan */
50 double pi = 4 * atan(1.0);
51 double complex z = cexp(I * pi);
52 printf("%f + %f * i\\n", creal(z), cimag(z));