Advertisement
Guest User

Untitled

a guest
Apr 6th, 2020
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.61 KB | None | 0 0
  1. // x <- A * d * A' * b.  x is allowed to be the same as b.
  2. template <class T, int N>
  3. static inline void eigmult(const T (&A)[N][N],
  4.                            const T d[N],
  5.                            const T b[N],
  6.                            T x[N])
  7. {
  8.     T e[N];
  9.     for (int i = 0; i < N; i++) {
  10.         T sum = 0;
  11.         for (int j = 0; j < N; j++)
  12.             sum += A[j][i] * b[j];
  13.         e[i] = sum * d[i];
  14.     }
  15.     for (int i = 0; i < N; i++) {
  16.         T sum = 0;
  17.         for (int j = 0; j < N; j++)
  18.             sum += A[i][j] * e[j];
  19.         x[i] = sum;
  20.     }
  21. }
  22.  
  23.  
  24. he calls the code in his program like this:
  25.  
  26. // Solve system
  27. eigmult<double,6>(A, einv, b);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement