You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

elmhes.cc 726B

123456789101112131415161718192021222324252627282930313233343536
  1. #include "ABACUS.h"
  2. using namespace std;
  3. void ABACUS::elmhes(SQMat_DP& a)
  4. {
  5. // Reduction to Hessenberg form by elimination method. NR p.490
  6. int i, j, m;
  7. DP y, x;
  8. int n = a.size();
  9. for (m = 1; m < n-1; m++) {
  10. x = 0.0;
  11. i = m;
  12. for (j = m; j < n; j++) {
  13. if (fabs(a[j][m-1]) > fabs(x)) {
  14. x = a[j][m-1];
  15. i = j;
  16. }
  17. }
  18. if (i != m) {
  19. for (j = m - 1; j < n; j++) SWAP(a[i][j], a[m][j]);
  20. for (j = 0; j < n; j++) SWAP(a[j][i], a[j][m]);
  21. }
  22. if (x != 0.0) {
  23. for (i = m + 1; i < n; i++) {
  24. if ((y = a[i][m-1]) != 0.0) {
  25. y /= x;
  26. a[i][m-1] = y;
  27. for (j = m; j < n; j++) a[i][j] -= y*a[m][j];
  28. for (j = 0; j < n; j++) a[j][m] += y*a[j][i];
  29. }
  30. }
  31. }
  32. }
  33. }