home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / math / zpp / complex.doc < prev    next >
Encoding:
Text File  |  1992-04-03  |  6.1 KB  |  172 lines

  1.  
  2.  
  3.                               Z++ Version 1.0
  4.  
  5.                       Copyright 1992 by Carl Moreland
  6.                                  04/03/92
  7.  
  8.     Z++ is a public domain complex number class written in C++. The distri-
  9. buted files are:
  10.  
  11.         complex.h    header file for Z++
  12.         complex.cpp    source code for Z++
  13.         complex.doc     this file
  14.         z_test.cpp    demonstration of complex numbers
  15.         fft.cpp        fft using Z++
  16.         signal.dat    data file for testing the fft
  17.  
  18. To use the complex number class, simply #include "complex.h" in your source
  19. and add complex.cpp to the project or make file. You may use and distribute
  20. this code freely, but all distributed copies must be unmodified,  and there
  21. may be no distribution charges.  Comments, suggestions for improvement, and
  22. bug reports may be sent to me via CompuServe (72137,2657), or mail them to:
  23.  
  24.         Carl Moreland
  25.         4314 Filmore Rd
  26.         Greensboro, NC 27409
  27.  
  28. ---------------------------------------------------------------------------
  29. ---------------------------------------------------------------------------
  30.  
  31. Introduction:
  32.  
  33. ---------------------------------------------------------------------------
  34.     Complex numbers may be declared or initialized in the following ways:
  35.  
  36.         complex z;          // z is initialized to (0,0)
  37.     complex z(3);          // z = (3,0)
  38.         complex z = 3;          // z = (3,0)
  39.         complex z(3,4);          // z = (3,4)
  40.         complex z = complex(3,4)  // z = (3,4)
  41.         complex z = x;          // set equal to a double/float/int
  42.         complex z1 = z2;      // set equal to another complex
  43.  
  44. Uninitialized  complex variables are set to (0,0) by the default  construc-
  45. tor, and variables that are set equal to a single number have their  imagi-
  46. nary part set to zero.
  47.  
  48. The following operators are available:
  49.  
  50.         =    see above
  51.         +  +=    addition
  52.         -  -=    subtraction
  53.         *  *=    multiplication
  54.         /  /=    division
  55.         ^    power (z1^z2)
  56.         == !=    comparison
  57.  
  58. The following functions are available:
  59.  
  60.         re    real part
  61.         im    imaginary part
  62.         real    real part
  63.         imag    imaginary part
  64.     mag    magnitude (sqrt(x**2 + y**2))
  65.         arg    argument  (atan(y/x))
  66.         ang    angle (same as argument)
  67.         ph    phase (same as argument)
  68.         conj    complex conjugate (x, -y)
  69.         norm    norm (x**2 + y**2)
  70.     abs    absolute value (same as magnitude)
  71.         sqrt    square root
  72.         pow    power
  73.         exp    exponential
  74.         log    natural log
  75.         ln    natural log
  76.         log10    log (base 10)
  77.         cos    cosine
  78.         sin    sine
  79.         tan    tangent
  80.         acos    arccosine
  81.         asin    arcsine
  82.         atan    arctangent
  83.         cosh    hyperbolic cosine
  84.         sinh    hyperbolic sine
  85.         tanh    hyperbolic tangent
  86.     rtop    rectangular-to-polar conversion
  87.     ptor    polar-to-rectangular conversion
  88.         topolar    converts z to polar form
  89.         torect    converts z to rectangular form
  90.  
  91.         SetArgMode    ┐
  92.         SetPrintMode  ├ See text below
  93.         SetLetter     ┘
  94.  
  95. ---------------------------------------------------------------------------
  96.  
  97.     Most features of Z++ are standard. However, there are a few things that
  98. are unique and should be explained.
  99.  
  100.  
  101.     The  conversion functions rtop() and ptor() accept a complex number  as
  102. the  argument and return a new complex number as the converted result.  The
  103. member methods topolar() and torect() will convert the instance  internally
  104. and return a reference to it.  Remember though that all math functions  ex-
  105. pect arguments in rectangular notation,  not polar. If you convert a number
  106. to  polar and try to take the cosine,  for instance,  you will not get  the
  107. correct results.
  108.  
  109.  
  110.     There  are two modes that can be set in Z++.  The argument mode  deter-
  111. mines whether complex arguments (from the functions arg(),  ang(),  & ph())
  112. are returned in radians (the default) or degrees.  This mode can be set  by
  113. calling  the  function SetArgMode() with either Z_RADIANS or  Z_DEGREES  as
  114. the mode parameter:
  115.  
  116.     z1.SetArgMode(Z_DEGREES);
  117.  
  118. Because  this  mode is represented as a static class variable,  setting  it
  119. will affect all complex numbers. The command above appears to set this mode
  120. only for instance z1, which is not true. To eliminate this confusion, there
  121. is  a static instance named Complex declared in complex.h which  should  be
  122. used to set this mode:
  123.  
  124.     Complex.SetArgMode(Z_DEGREES);
  125.  
  126. Either way will work, but the second has the appearance of being global.
  127.  
  128.  
  129.     The other mode is the print mode which affects the format of cout. This
  130. mode can be set by calling the function SetPrintMode() with either  Z_COMMA
  131. or Z_LETTER as the mode parameter:
  132.  
  133.     Complex.SetPrintMode(Z_COMMA)
  134.     Complex.SetPrintMode(Z_LETTER)
  135.  
  136. The first mode causes complex numbers to printed with the format (x, y)  by
  137. cout. The second mode causes them to be formatted as x ± iy. Like the argu-
  138. ment mode, this mode is global for all complex numbers and therefore should
  139. be set using the Complex instance.
  140.  
  141.  
  142.     Electrical engineers prefer to use the letter j as the complex operator
  143. (the letter i denotes AC current).  There is a function called  SetLetter()
  144. which accepts a character argument:
  145.  
  146.     Complex.SetLetter('j');
  147.  
  148. If the print mode is set to Z_LETTER then cout will print a complex  number
  149. with the format x ± jy.
  150.  
  151.  
  152.     Finally,  besides the instance Complex used above there are four  other
  153. static instances declared:
  154.  
  155.     Z0   = complex(0,0)
  156.     Z1   = complex(1,0)
  157.     Zi   = complex(0,1)
  158.     Zinf = complex(HUGE_VAL, HUGE_VAL)
  159.  
  160. These are common useful numbers that can be used for assignments,  compari-
  161. sons, and equations.
  162.  
  163. ---------------------------------------------------------------------------
  164.  
  165. FFT note:
  166.  
  167.     The FFT program that is included was originally written in C and ran on
  168. DOS, VMS, and Unix.  It's purpose was to transform sinusoidal data from  an
  169. analog-to-digital converter and display the harmonics and relative bits  of
  170. accuracy.  I have only converted the fft() routine to use the  Z++  complex
  171. numbers; the rest of the program remains pure C. The data file included for
  172. testing the FFT is the actual results from a 12-bit ADC.