home *** CD-ROM | disk | FTP | other *** search
/ Power Programming / powerprogramming1994.iso / progtool / microcrn / issue_40.arc / DAIMS.ARC / VIMATRIX.CPP < prev    next >
Text File  |  1988-02-10  |  2KB  |  89 lines

  1. #include <math.h>
  2. #include "matrix.hxx"
  3. #include "Cheb_vector.hxx"
  4. #include "vimatrix.hxx"
  5. #undef TEST
  6. /* 
  7. -*++ vi_matrix::vi_matrix(): initializer for vorticity inversion matrix
  8. ** 
  9. ** (*++ history: 
  10. **     11 Dec 87    Bruce Eckel    Creation date
  11. ** ++*)
  12. ** 
  13. ** (*++ detailed: create an n x n matrix and initialize it as the vorticity
  14. ** inversion matrix.
  15. ** ++*)
  16. */
  17.  
  18. vi_matrix::vi_matrix(int n, double lambda) : (n,n,0)
  19. {
  20.     for (int row = 0; row < size()-2; row++){
  21.     for (int col = row+2; col < size(); col++) {
  22.         if ( (row+col)%2 == 0 )
  23.         (*this)[row][col] = (col/C(row))*(col*col - row*row);
  24.     }
  25.     (*this)[row][row] = -lambda;
  26.     }
  27.     double flip = -1.0;
  28.     for( int col = 0; col < size(); col++){
  29.     (*this)[size()-2][col] = flip;
  30.     (*this)[size()-1][col] = 1;
  31.     flip = -flip;
  32.     }
  33.     /* else element = 0, which is the initialized value */
  34. }
  35.  
  36.  
  37.  
  38. /* 
  39. -*++ vi_matrix::operator*(): vi_matrix * chebyshev vector
  40. ** 
  41. ** (*++ history: 
  42. **     16 Jan 88    Bruce &    Creation date
  43. ** ++*)
  44. ** 
  45. ** (*++ detailed: 
  46. ** ++*)
  47. */
  48.  
  49. Cheb_vector & vi_matrix::operator*(Cheb_vector & C)
  50. {
  51.     if (cols() != C.size() || cols() != rows())
  52.     error("matrix must be square and dimension of Cheb_vect for *!");
  53.     Cheb_vector & result = *new Cheb_vector(C.size());
  54.     for(int row = 0; row < rows(); row++) {
  55.     double sum = 0;
  56.     for(int i = 0; i < cols(); i++) {
  57. /*        cout << "row = " << row << " i = " << i << "\n";
  58.         cout.flush();
  59.         cout << "(*this)[row][i] = " << (*this)[row][i] << "\n";
  60.         cout.flush();
  61.         cout << "C[i] = " << C[i] << "\n";
  62.         cout.flush();
  63.         cout << "((*this)[row][i])) * (C[i]) = " 
  64.         << ((*this)[row][i]) * (C[i]) <<"\n";
  65.         cout.flush();
  66. */
  67.         double temp1 = ((*this)[row][i]);
  68.         double temp2 = (C[i]);
  69. /*        sum += ((*this)[row][i]) * (C[i]); */
  70.         sum += temp1 * temp2;
  71. /*        cout << "sum = " << sum << "\n";
  72.         cout.flush();
  73. */
  74.     }
  75.     result[row] = sum;
  76. /*        cout << "result[row] = " << result[row] << "\n\n";
  77.         cout.flush();
  78. */    
  79.     }
  80.     return result;
  81. }
  82.  
  83. #ifdef TEST
  84. main(int argc, char **argv) {
  85.     vi_matrix H(atoi(argv[1]), atof(argv[2]));
  86.     cout << H << NL;
  87. }
  88. #endif
  89.