Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
int main()
{
int num_of_equation, num_of_cols, num_of_rows;
double** Array_size;
double* Vector_vars;
cout<<endl;
cout<<"
GAUSSIAN ELIMINATION"<<endl;
cout<<endl;
cout<<"Enter the number of equations: ";
cin>>num_of_equation;
/*---------------------------------------VECTOR VARIABLES---------------------*/
Vector_vars = vectorVars(num_of_equation);
cout<<"Enter right-hand vectors: "<<endl<<endl;
for(num_of_rows = 0; num_of_rows < num_of_equation; num_of_rows++)
cin>>Vector_vars[num_of_rows];
p = 0;
}
/*--------------------------------FUNCTION THAT DELETES THE VALUE OF Vector_vars[] FROM
THE TRIANGULAR MATRIX TO REPLACE IT WITH THE Vector_vars[i] VALUE FROM
THE BACK-SUBSTITION------------------------------*/
void vectorFree(double* p)
{
delete[] p;
p = 0;
}
/*---------------------------------FUNCTION THAT PRINTS THE UPPER TRIANGULAR FORM-------------------------------*/
void vectorPrint(double* p, int n)
{
for ( int i = 0; i < n; i++)
cout <<"\t"<<"X"<<i<<"= "<<p[i];
cout << endl << endl;
}
/* ----------------function that tests if the variables inserted fits in the size of the
rows and
columns of the array which was declared by the inputted variable
num_of_equations ---------------- */
double** matrixArray(int a, int b)
{
double** p;
p = new double* [a];
for ( int i = 0; i < a; i++ )
p[i] = new double[b];
return p;
}
double* vectorVars(int a)
{
double* v;
v = new double[a];
return v;
}
/*-----------------------FUNCTION FOR PRINTING THE AUGMENTED MATRIX--------------------*/
void matrixPrint(double** p, int num_of_equation, double* v)
{
for ( int num_of_rows = 0; num_of_rows < num_of_equation; num_of_rows++)
{
for ( int num_of_cols = 0; num_of_cols < num_of_equation; num_of_cols++)
cout << "\t"<< p[num_of_rows][num_of_cols];
cout<<"\t\t"<<"|"<<"\t"<<v[num_of_rows];
cout << endl;
}
}