# Thread: solution to a linear system of equations

1. ## solution to a linear system of equations

http://www.scs.carleton.ca/~wli/2404...Assign1W09.doc

In the first part the procedure that I followed is as follows. Is it in accordance with the requirements.

Code:
```class Main
{
public:
Main(void);
~Main(void);
void main(){
double a[100][100], b[100][100], d[100][100], c[100], e[100], maxele, temp;

cout<<" Please enter the number of unknowns: ";
for(int i=0; i<n; i++){
for(int j=0; j<n; j++)
cin>>a[i][j];
}
for(int i=0; i<n; i++){
cin>>c[i];
}
for(int i=0; i<n; i++){
for(int j=0; j<n; j++){
if(a[i][j]<0){
b[i][j]=-1*a[i][j];
}
else{
b[i][j]=a[i][j];
}
}
}

int k=0;
for(int i=0; i<n; i++){
k<--i;
while(j<n){
if(a[i][j]>a[i][k]){
temp<--a[i][k];
a[i][k]<--a[i][j];
a[i][j]<--temp;
maxele<--a[i][k];
j++;
k++;
}
}
}

for(int i=0; i<n; i++){
for(int j=0; j<n; j++){
d[i][j]<--a[i][j]/a[i][1];
}
}

for(int i=0; i<n; i++){
if(a[i][1]<a[++i][1]){
for(int j=0; j<n; j++){
a[i][j]<--a[++i][j];
}
}
}

for(int i=0; i<n; i++){
if(a[i][i]<1 && a[i][i]>1E-9){
cout<<"the system does not have a unique solution";
break;
}
else{
for(int j=0; j<n; j++){
a[i][j]<--a[i][j]-d[i][j];
}
}
}
break;
}

static const int i=50;
static const int j=50;

while(i>0) do{
while(j>0) do{
if(a[i][j]<1 && a[i][j]>1E-9){
break;
}
else{
e[i]=(b[i]-a[i][--j])/a[i][j];
}
}
}

/*for(int i=sizeof a; i>0; i--){
for(int j=sizeof a; j>0; j--){
if(a[i][j]<1 && a[i][j]>1E-9){
break;
}
else{
e[i]=(b[i]-a[i][--j])/a[i][j];
}
}
}*/
}

private:

};```

2. I didn't read the requirements, but I doubt that your requirements are to write ... whatever that is. If it's supposed to be C++, it needs a heck of a lot of work. Your main program is never inside of a class. There's no reason to have a class if you don't need one, and you don't seem to need one. Are you using "<--" for assignment? In C++, that's "=". I'm sure there's more.

3. Like, what the hell happened to the poor whitespace? Don't you have any pity on that poor whitespace?

4. i believe you've done the partial pivoting wrong.

5. This chunk of code is mysterious
Code:
```double a[100][100], b[100][100], d[100][100], c[100], e[100], maxele, temp;

cout<<" Please enter the number of unknowns: ";
for(int i=0; i<n; i++){
for(int j=0; j<n; j++)
cin>>a[i][j];
}```
n is not defined. Did you want to ask the user for n, and then ask him/her to enter n squared values? It seems n should be fixed at 100.
Also, please indent your code: the logic is simple enough to follow, but the branches would be clearer with indentation.