Question
For example: the system of linear equations:
3x+5y+2z=1
3x+2y+7z=1
3x+6y+8z=1
In the input file:
3 <------ is the dimension of the matrix
1 3 5 2
1 3 2 7
1 3 6 8
You should get the matrices from the input file. Then solve the answer with Gauss-Jordan method.
The equations and the answers need to be put in the output file "gauss.txt".
Solution Preview
This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.
#include <iostream>#include <cmath>
#include <cstdlib>
#include <sstream>
#include <fstream>
#include <string>
using namespace std;
void freeArray(int N, double **M){
// De-Allocate memory to prevent memory leak
for (int i = 0; i < N; i++)
delete [] M[i];
delete [] M;
}
double **AllocateArray(int N){
double **M;
M = new double*[N];
for (int i = 0; i < N; i++)
M[i] = new double[N+1];
return M;
}
// read of set of equations
int readOneSetOfEquations(int *Num, double ***M,istream &inFile, int toScreen){
char line[256];
int value;
string s;
stringstream ss;
// read dimension
*Num=0;
if(!inFile.eof()){
if ( toScreen ==1){
// from kdb
do{
cout << "Enter Number of rows ( from 2 to 9):";
cin>> value;
cin.clear();
cin.ignore(INT_MAX,'\n');
if(value <2 || value >9)
cout << "Error! Value must be in [2,9]"<< endl;
else
break;...