#include <fstream.h>
#include <math.h>
#include <conio.h>
#include <stdlib.h>
const num = 4;
int i,j,I,J;
int c[num+1];
long double x[num+1];
long double max;
long double A[num][num+1];
// -----------------------------------------------------------
void max_el(int sr, int st)
{ max = A[num+1-sr][num+2-st];
I = num+1-sr;
J = num+2-st;
for (i = num+1-sr ; i<=num ; i++)
{
for (j = num+2-st ; j<=num ; j++)
if (fabs(A[i][j]) > fabs(max))
max = A[i][j];
I = i;
J = j;
}
cout << "nn Max = " << max << " I=" << I<< " J=" << J;
void print(int sr,int st)
cout << "n";
int i,j;
for (j = num+2-st ; j<=num+1 ; j++)
if (A[i][j] < 0 ) gotoxy(12*j + j - 1,i+1);
else gotoxy(12*j + j,i+1);
cout << A[i][j];
// ------------------------------------------------------------------
void preob(int S)
long double temp;
for (j = S; j<=num+1; j++) A[S][j] = A[S][j]/max;
for (i = S + 1; i <= num; i++)
temp = A[i][S];
for (j = S; j<= num+1 ; j++) A[i][j] = A[i][j] - A[S][j]*temp;
void perestanovka(int sr,int st)
if (J != (num+1-sr))
for (i = 1; i<=num; i++) {
A[i][J] = A[i][J] + A[i][num+1-sr];
A[i][num+1-sr] = A[i][J] - A[i][num+1-sr];
A[i][J] = A[i][J] - A[i][num+1-sr];
c[J] = c[J] + c[num+1-sr];
c[num+1-sr] = c[J] - c[num+1-sr];
c[J] = c[J] - c[num+1-sr];
if (I != (num+2-st))
for (j = 1; j<=num+1; j++) {
A[I][j] = A[I][j] + A[num+2-st][j];
A[num+2-st][j] = A[I][j] - A[num+2-st][j];
A[I][j] = A[I][j] - A[num+2-st][j]; }
void otvet()
float temp;
for (i=num; i>=1; i--)
temp = A[i][num+1];
for(j = num; j > i; j--) temp = temp - A[i][j]*x[j];
x[i] = temp/A[i][i];
void interface()
clrscr();
print(num,num+1);
cout << "n Массив перестановок столбцов ";
for (i = 1; i <= num ;i++) cout << " " << c[i];
void load_file()
char ch;
ifstream in("c:gaussmat.dat");
for (i = 1 ; i<=num ; i++)
while (ch != '
void main()
load_file();
int g;
for(g = num+1; g >= 3; g--)
interface(); max_el(g-1,g); getch();
perestanovka(g-1,g); interface(); getch();
preob(num+2-g); interface(); getch();
otvet();
cout << "nn ";
long double X[num];
for (i=1; i<=num; i++) X[c[i]] = x[i];
for (i=1; i<=num; i++) cout << " X" << i << " = " << X[i];
getch();
4.24x1 + 2.73x2 - 1.55x3 = 1.87
2.34x1 + 1.27x2 + 3.15x3 = 2.16
3.05x1 - 1.05x2 - 0.63x3 = -1.25
x1 = - 0.025461 x2 = 0.915112 x3 = 0.335678
4.24*(- 0.025461) + 2.73*0.915112 - 1.55*0.335678 = 1,87000022 погрешность: 2,2*10-7
2.34*(- 0.025461) + 1.27*0.915112 + 3.15*0.335678 = 2,1599992 погрешность: 8,0*10-7
3.05*(- 0.025461) - 1.05*0.915112 - 0.63*0.335678 = -1,25000079 погрешность: 7,9*10-7
средняя погрешность вычисления: 6,0*10-7
3.81x1 + 0.25x2 + 1.28x3 + (0.75+a)x4 = 4.21
2.25x1 + 1.32x2 + (4.5+a)x3 + 0.49x4 = 6.47+b
5.31x1 + (0.28+a) x2 + 0.98x3 + 1.04x4 = 2.38
(9.39+a)x1 + 2.45x2 + 3.35x3 + 2.28x4 = 10.48+b
a = (0,1,2,3,4) b = (0,1,2,3,4,5)
a