This program solves linear system of equations by using Gauss-Siedel iterative process, where the initial approximation is:
(x0, y0, z0) = (0, 0, 0)
But when I am running it the window shuts immediately after I enter the matrix input and can't complete the whole program.
Here is the code:
#include<iostream>
#include<iomanip>
#include<cmath>
using namespace std;
int main(){
float x1, x2, x3, x1new, x2new, x3new, sum;
float a[3][3], b[3], error[3];
x1 = x2 = x3 = 0;
x1new = x2new = x3new = 0;
cout <<"enter the coefficients of equation or matrix a \n";
for(int i = 0; i < 3; i++){
for(int j = 0; j < 3; j++)
cin >> a[i][j];
}
cout <<" \n enter the right side values of equation or matrix b ";
for(int i = 0; i < 3; i++)
cin >> b[i];
for(int i = 0; i < 3; i++){
error[i] = 1;
}
while((error[0]| | error[1]| | error[2]) > =0.00001){
x1 = (b[0] - (a[0][1] * x2 + a[0][2] * x3)) / a[0][0];
x2 = (b[1] - (a[1][0] * x1 + a[1][2] * x3)) / a[1][1];
x3 = (b[2] - (a[2][0] * x1 + a[2][1] * x2)) / a[2][2];
error[0] = abs(x1) - abs(x1new);
error[1] = abs(x2) - abs(x2new);
error[2] = abs(x3) - abs(x3new);
x1new = x1;
x2new = x2;
x3new = x3;
}
cout <<"\n the values of variables x1,x2 and x3 are:";
cout << x1 << x2 << x3;
}
Question:
What am I doing wrong?