Esempio n. 1
0
    void SolveGEIP(const Matrix& A, Vector &x, const Vector& b)
    { 
      // Verify that the system is well-formed
      const int size = A.Rows();
      if ((A.Cols() != size) || (b.Size() != size)) {
        throw NonconformableShapesError();
      }

      // Prepare the augmented matrix
      Matrix aug(size, size+1, NaN());
      for (int i = 0; i < size; ++i) {
        aug.Col(i) = A.Col(i);
      }
      aug.Col(size) = b;
      
      // Go to town...
      eliminate(aug, size, fabs(1e-14));
      back_substitute(aug, size);

      x = aug.Col(size);
    }
Esempio n. 2
0
void lin_alg::Gauss_Solve(double **A, double *b, double *x, int size, bool pivoting, bool printing)
{
	// This is a function that performs a row reduction on an augmented matrix followed by 
	// backsubstitution to find the solution of A.x=b
	// R. Sheehan 28 - 2 - 2013

	// the argument pivoting has been defaulted to be set to true
	// so that pivoting is always applied unless otherwise specified

	// Create an array to aid with the simulated row-interchanges
	// new is equivalent to malloc
	int *nrow = new (int [size+1]); 
	
	double **Aug = matrix(size, size+1); // create an array to hold the augmented matrix

	// perform the row reduction
	row_reduce( A, b, Aug, nrow, size, pivoting); 

	if(printing){

		cout<<"Row reduced system\n";
		print_matrix(Aug, size, size+1); 

	}

	// compute x by back-substitution on the row-reduced augmented matrix
	back_substitute(x,Aug,nrow,size); 

	if(printing){

		cout<<"Computed solution\n";
		print_vector(x, size); 

	}

	// Delete memory that is no longer required
	delete[] nrow; 
	delete[] Aug; 
}