home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 14 / CDACTUAL.iso / cdactual / demobin / share / program / c / ZPP120.ZIP / COMPLEX.DOC < prev    next >
Encoding:
Text File  |  1993-02-16  |  5.6 KB  |  150 lines

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