#include
#include
int maximal(int n, double R0[]){
int i,f;
f=0.0;
for(i=0;i
if(R0[i+1]>R0[i]) f=i+1;
}
return f;
}
void main(){
int i,j,n,f,k,iter;
double S,det;
cout<<"Vvedite razmer kvadratnoy matrici= ";<br>cin>>n;
double *x=new double [n];
double **b=new double *[n];
for(i=0;i
b[i]=new double[n+1];
double **a=new double *[n];
for(i=0;i
a[i]=new double[n+1];
cout<<"Vvedite kolichestvo iteraciy:";<br>
cin>>iter;
cout<<"Vvedite matritcu";<br>
for(i=0;i
for(j=0;j<=n;j++)<br>
cin>>b[i][j];
}
cout<<"podgotovka k relaksatcii...\n";<br>
for(i=0;i
for(j=0;j
a[i][j]=-b[i][j]/b[i][i];
a[i][n]=b[i][n]/b[i][i];
}
for(i=0;i
for(j=0;j
cout<<" "<<a[i][j]<<" || ";<br>
cout<<"\n";<br>
}
double *x0=new double [n];
for(i=0;i
x[i]=0.0;
double *R0=new double [n];
cout<<"Vvedite znachenie nachal`nih priblizheniy:\n";<br>
for(i=0;i
cin>>x0[i];
S=0.0;
for(i=0;i
for(j=0;j
S=S+a[i][j]*x0[i];
}
for(i=0;i
R0[i]=a[i][n]-x0[i]+S;
cout<<"R("<<i<<")="<<R0[i]<<" | ";<br>
}
f=maximal(n,R0);
det=R0[f];
for(k=0;k
cout<<"det{"<<k<<"}="<<det<<"\n";<br>
for(i=0;i
if(i!=f) R0[i]=R0[i]+a[i][f]*det;
else R0[i]=R0[i]-det;
}
for(i=0;i
cout<<"R["<<i+1<<"]="<<R0[i]<<" ";<br>
x[f]=x[f]+det;
f=maximal(n,R0);
det=R0[f];
}
cout<<"\n";<br>
for(i=0;i
cout<<"X{"<<i+1<<"}="<<x[i]<<"\n";<br>
delete []x;
delete []R0;
delete []x0;
delete []a;
cin.get();
cin.get();
}