#include #include // A procedure implementing a Gaussian elimination algorithm (with row pivoting) for // solving the equation Ax=b, where: // A - nonsingular square matrix (changed to upper-triangular in the procedure), // b - a vector containing the RHS on entering and the solution on exiting // n - the dimention of the vector b (and the sqare matrix A) int gaussian_elimination(double** A, double *b, int n) { int i,j,k, tmp; //STEP 0.5 - ouput the matrix A (included for debugging only) for (int i=0; i fabs(A[p[i]][i])) index = j; } // Interchange the i-th and index-th rows tmp = p[i]; p[i] = p[index]; p[index] = tmp; // Clear the entries below the diagonal in the i-th column for(int j=i+1; j=0; i--) { for(k=n-1; k>i; k--) b[p[i]] -= b[p[k]]*A[p[i]][k]; if(A[p[i]][i]==0) return -i; b[p[i]] = b[p[i]]/A[p[i]][i]; } //STEP 3 - Reorder the solution double* temp = new double[n]; for(i=0; i> N; std::cout << std::endl; double** A = new double*[N]; double* b = new double[N]; for (int i=0; i>A[i][k]; } } std::cout << std::endl; std::cout << "Enter the right hand side: " << std::endl; for (int k=0; k>b[k]; } gaussian_elimination(A,b,N); for (int i=0; i