home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / n / newmat06.zip / TMTF.CXX < prev    next >
C/C++ Source or Header  |  1992-11-26  |  2KB  |  72 lines

  1.  
  2. //#define WANT_STREAM
  3. #define WANT_MATH
  4.  
  5. #include "include.h"
  6.  
  7. #include "newmatap.h"
  8.  
  9. void Print(const Matrix& X);
  10. void Print(const UpperTriangularMatrix& X);
  11. void Print(const DiagonalMatrix& X);
  12. void Print(const SymmetricMatrix& X);
  13. void Print(const LowerTriangularMatrix& X);
  14.  
  15. void Clean(Matrix&, Real);
  16.  
  17.  
  18.  
  19.  
  20. static void test(int n)
  21. {
  22.    Tracer et("Test FFT");
  23.  
  24.    ColumnVector A(n), B(n), X, Y;
  25.    for (int i=0; i<n; i++)
  26.    {
  27.       Real f = 6.2831853071795864769*i/n;
  28.       A.element(i) = fabs(sin(7.0*f) + 0.5 * cos(19.0 * f));
  29.       B.element(i) = fabs(0.25 * cos(31.0 * f));
  30.    }
  31.    FFT(A, B, X, Y);
  32.    X=X/n; Y=-Y/n;
  33.    FFT(X, Y, X, Y);
  34.    Y = -Y;
  35.    X = X - A; Y = Y - B;
  36.    Clean(X,0.000000001); Clean(Y,0.000000001); Print(X); Print(Y);
  37. }
  38.  
  39. void trymatf()
  40. {
  41.    Tracer et("Fifteenth test of Matrix package");
  42.    Exception::PrintTrace(TRUE);
  43. //   cout << "\nFifteenth test of Matrix package\n";
  44. //   cout << "\n";
  45.  
  46.    ColumnVector A(12), B(12);
  47.    for (int i = 1; i <=12; i++)
  48.    {
  49.       Real i1 = i - 1;
  50.       A(i) = .7
  51.            + .2 * cos(6.2831853071795864769 * 4.0 * i1 / 12)
  52.            + .3 * sin(6.2831853071795864769 * 3.0 * i1 / 12);
  53.       B(i) = .9
  54.            + .5 * sin(6.2831853071795864769 * 2.0 * i1 / 12)
  55.            + .4 * cos(6.2831853071795864769 * 1.0 * i1 / 12);
  56.    }
  57.    FFT(A, B, A, B);
  58.    A(1) -= 8.4; A(3) -= 3.0; A(5) -= 1.2; A(9) -= 1.2; A(11) += 3.0;
  59.    B(1) -= 10.8; B(2) -= 2.4; B(4) += 1.8; B(10) -= 1.8; B(12) -= 2.4;
  60.    Clean(A,0.000000001); Clean(B,0.000000001); Print(A); Print(B);
  61.  
  62.    test(2048);
  63.    test(2000);
  64.    test(27*81);
  65.    test(2310);
  66.    test(49*49);
  67.    test(13*13*13);
  68.    test(43*47);
  69.  
  70. //   cout << "\nEnd of Fifteenth test\n";
  71. }
  72.