dev/cpp/gauss_miron/gauss_mir.cpp

55 lines
1.3 KiB
C++

#include <iostream>
using namespace std;
const int n=350;
typedef double massive[2*n+1][2*n+1];
double a_k[2*n+1];
double b[2*n+1];
double c[2*n+1];
double right_part[2*n+1];
double sys[2*n+1][2*n+1];
void sys_solve()
{
int i,j,k;
double sum=0.0;
double f[2*n+1];
massive b,c;
//Прямой ход
for(i=0;i<2*n+1;i++) b[i][i]=1.0;
for(j=0;j<2*n+1;j++)
{
for(i=j;i<2*n+1;i++)
{
sum=0.0;
for(k=0;k<j;k++) sum=sum+c[i][k]*b[k][j];
c[i][j]=sys[i][j]-sum;
}
for(i=j+1;i<2*n+1;i++)
{
sum=0.0;
for(k=0;k<j;k++) sum=sum+c[j][k]*b[k][i];
b[j][i]=(sys[j][i]-sum)/c[j][j];
}
}
for(j=0;j<2*n+1;j++)
{
sum=0.0;
for(k=0;k<j;k++) sum=sum+c[j][k]*f[k];
f[j]=(right_part[j]-sum)/c[j][j];
}
//Обратный ход
for(j=2*n;j>=0;j--)
{
sum=0.0;
for(k=j+1;k<2*n+1;k++) sum=sum+b[j][k]*a_k[k];
a_k[j]=f[j]-sum;
}
}
int main()
{
sys_solve();
cout<<"end"<<endl;char ch;cin>>ch;
return 0;
}