Advertisement
Neveles

Untitled

Apr 4th, 2021
647
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.75 KB | None | 0 0
  1. double** invertMatrix(double** A, int size)
  2. {  
  3.   double** result = new double* [size];
  4.   for (int i = 0; i < size; i++)
  5.   {
  6.     result[i] = new double[size];
  7.   }
  8.  
  9.   double* newA = new double [size*size];
  10.   newA = matrixToArray(A, size);
  11.  
  12.   double cond = 0;;
  13.   int* pivot = new int[size];
  14.   int flag = 0;
  15.  
  16.   decomp(size, size, newA, &cond, pivot, &flag);
  17.  
  18.   std::cout << "Decomp arguments: cond = " << cond << "; flag = " << flag << "\n";
  19.  
  20.   double* B = new double[size];
  21.   for (int i = 0; i < size; i++)
  22.   {
  23.     for (int k = 0; k < size; k++)
  24.     {
  25.       B[k] = 0;
  26.     }
  27.  
  28.     B[i] = 1;
  29.  
  30.     solve(size, size, newA, B, pivot);
  31.  
  32.     for (int j = 0; j < size; j++)
  33.     {
  34.       result[j][i] = B[j];
  35.     }
  36.   }
  37.  
  38.   return result;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement