home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / magazine / pas_nl / shcmplx / testcmpx.pas < prev   
Pascal/Delphi Source File  |  1991-03-06  |  4KB  |  137 lines

  1. {$N+,E+}
  2. program TestCmpx;
  3. {
  4.                         To test the ShCmplx unit
  5.  
  6.                   Copyright 1991 Madison & Associates
  7.                           All Rights Reserved
  8.  
  9.         This unit and the associated .DOC and TEST*.* files may
  10.         be freely copied and distributed, provided only that no
  11.         fee is charged for the package beyond a nominal copying
  12.         charge, and provided that the package is distributed IN
  13.         UNALTERED FORM. The sole exception to  this  latter re-
  14.         striction is that bona-fide clubs and  user  groups may
  15.         append text material to the documentation file, provid-
  16.         ed that any material appended is clearly  identified as
  17.         to its source, its beginning, and its end.
  18. }
  19.  
  20. uses
  21.   TpString,
  22.   TpCrt,
  23.   ShCmplx;
  24.  
  25. var
  26.   A,
  27.   B,
  28.   C,
  29.   D   : Complex;
  30.   T1  : integer;
  31.   Arad: ComplexElement;
  32.  
  33. begin
  34.   New(A); New(B); New(C); New(D);
  35.   A^.Re := 5.0; A^.Im := 12.0;
  36.   WriteLn;
  37.   WriteLn(Center('BASIC FUNCTION TEST',75));
  38.   WriteLn;
  39.   WriteLn
  40.     ('The complex conjugate of ' + Cmp2Str(A,0,2) + ' is ' +
  41.       Cmp2Str(CConjF(A),0,2));
  42.   WriteLn
  43.     ('The absolute value of ' + Cmp2Str(A,0,2) + ' is ' +
  44.       Real2Str(CAbsF(A),0,4));
  45.   B^.Re := 7.5; B^.Im := 6.25;
  46.   WriteLn
  47.     (Cmp2Str(A,0,2) + ' + ' + Cmp2Str(B,0,2) + ' = ' +
  48.       Cmp2Str(CAddF(A, B),0,4));
  49.   WriteLn
  50.     (Cmp2Str(A,0,2) + ' - ' + Cmp2Str(B,0,2) + ' = ' +
  51.       Cmp2Str(CSubF(A, B),0,4));
  52.   WriteLn
  53.     (Cmp2Str(A,0,2) + ' * ' + Cmp2Str(B,0,2) + ' = ' +
  54.       Cmp2Str(CMulF(A, B),0,4));
  55.   WriteLn
  56.     (Cmp2Str(A,0,2) + ' / ' + Cmp2Str(B,0,2) + ' = ' +
  57.       Cmp2Str(CDivF(A, B),0,4));
  58.   C^.Re := 5.0; C^.Im :=  2.0;
  59.   D^.Re := 3.0; D^.Im := -4.0;
  60.   WriteLn
  61.     (Cmp2Str(C,0,2) + ' / ' + Cmp2Str(D,0,2) + ' = ' +
  62.       Cmp2Str(CDivF(C, D),0,4));
  63. Write('Any key to continue...'); if ReadKey = '' then; WriteLn;
  64.   WriteLn;
  65.  
  66.   WriteLn(Center('NESTED CALLS AND INVERSE FUNCTIONS TEST',75));
  67.   WriteLn;
  68.   WriteLn
  69.     (Cmp2Str(A,0,2) + ' + ' + Cmp2Str(B,0,2) + ' + ' +
  70.      Cmp2Str(C,0,2) + ' + ' + Cmp2Str(D,0,2) + ' = ');
  71.   WriteLn
  72.     ('':10, Cmp2Str(CAddF(A, CAddF(B, CAddF(C, D))),0,2));
  73.   WriteLn
  74.     (Cmp2Str(A,0,2) + ' / ' + Cmp2Str(B,0,2) + ' * ' + Cmp2Str(B,0,2) +
  75.      ' = ' + Cmp2Str(CMulF(CDivF(A, B), B), 0, 2));
  76.   WriteLn
  77.     (Cmp2Str(A,0,2) + ' + ' + Cmp2Str(B,0,2) + ' - ' + Cmp2Str(B,0,2) +
  78.      ' = ' + Cmp2Str(CAddF(CSubF(A, B), B), 0, 2));
  79. Write('Any key to continue...'); if ReadKey = '' then; WriteLn;
  80.   WriteLn;
  81.  
  82.   WriteLn(Center('COORDINATE SYSTEM TRANSFORMATION TEST',75));
  83.   WriteLn;
  84.   A^.Re := sqrt(3.0)*0.5; A^.Im := 0.5; {FIRST QUADRANT}
  85.   C2P(A, B);
  86.   WriteLn(Cmp2Str(A,0,2),' is ',CmpP2StrD(B,0,2));
  87.   A^.Re := -sqrt(3.0)*0.5; A^.Im := 0.5; {SECOND QUADRANT}
  88.   C2P(A, B);
  89.   WriteLn(Cmp2Str(A,0,2),' is ',CmpP2StrD(B,0,2));
  90.   A^.Re := -sqrt(3.0)*0.5; A^.Im := -0.5; {THIRD QUADRANT}
  91.   C2P(A, B);
  92.   WriteLn(Cmp2Str(A,0,2),' is ',CmpP2StrD(B,0,2));
  93.   A^.Re := sqrt(3.0)*0.5; A^.Im := -0.5; {FOURTH QUADRANT}
  94.   C2P(A, B);
  95.   WriteLn(Cmp2Str(A,0,2),' is ',CmpP2StrD(B,0,2));
  96.   WriteLn;
  97.  
  98.   A^.Re := 1.0;
  99.   for T1 := 0 to 36 do begin
  100.     A^.Im := 10.0 * T1 * Pi / 180.0;
  101.     C := C2PF(P2CF(A));
  102.     Write(CmpP2StrD(C,0,2));
  103.     if (T1 mod 4) = 0 then
  104.       WriteLn
  105.     else
  106.       GoToXY(20*(T1 mod 4), WhereY);
  107.     end;
  108. Write('Any key to continue...'); if ReadKey = '' then; WriteLn;
  109.   WriteLn;
  110.  
  111.   WriteLn(Center('POWER TEST',75));
  112.   WriteLn;
  113.   A^.Re := 8.0; A^.Im := 0.0; Arad := 1.0/3.0;
  114.   WriteLn(CmpP2StrD(A,0,4),' ^ ',Arad);
  115.   WriteLn(CmpP2Str(A,0,4),' ^ ',Arad);
  116.   for T1 := 0 to 3 do begin
  117.     B^ := CpPwrRF(A, Arad)^;
  118.     while B^.Im >= 2.0*Pi do B^.Im := B^.Im - 2.0*Pi;
  119.     Write(CmpP2StrD(B,0,4));
  120.     GoToXY(25, WhereY); Write(' is ', Cmp2Str(P2CF(B),0,4));
  121.     GoToXY(50, WhereY); WriteLn('is ',CmpP2Str(B,0,4));
  122.     A^.Im := A^.Im + 2.0*Pi;
  123.     end;
  124.   WriteLn;
  125.   A^.Re := 125.0; A^.Im := 15.0*Pi/180.0;
  126.   WriteLn(CmpP2StrD(A,0,4),' ^ ',Arad);
  127.   WriteLn(CmpP2Str(A,0,4),' ^ ',Arad);
  128.   for T1 := 0 to 3 do begin
  129.     B^ := CpPwrRF(A, Arad)^;
  130.     while B^.Im >= 2.0*Pi do B^.Im := B^.Im - 2.0*Pi;
  131.     Write(CmpP2StrD(B,0,4));
  132.     GoToXY(25, WhereY); Write('is ', Cmp2Str(P2CF(B),0,4));
  133.     GoToXY(50, WhereY); WriteLn('is ',CmpP2Str(B,0,4));
  134.     A^.Im := A^.Im + 2.0*Pi;
  135.     end;
  136.   end.
  137.