) p>
) p>
) p>
// --------------------------------------------- --------------------- p>
void preob (int S) p>
( p>
int i, j; p>
long double temp; p>
for (j = S; j <= num +1; j + +) A [S] [j] = A [S] [j]/max; p>
for (i = S + 1; i <= num; i ++) p>
( p>
temp = A [i] [S]; p>
for (j = S; j <= num +1; j + +) A [i] [j] = A [i] [j] - A [S] [j] * temp; p>
) p>
) p>
// --------------------------------------------- --------------------- p>
void perestanovka (int sr, int st) p>
( p>
if (J! = (num +1- sr)) p>
( p>
for (i = 1; i <= num; i + +) ( p>
A [i] [J] = A [i] [J] + A [i] [num +1- sr]; p>
A [i] [num +1- sr] = A [i] [J] - A [i] [num +1- sr]; p>
A [i] [J] = A [i] [J] - A [i] [num +1- sr]; p>
) p>
c [J] = c [J] + c [num +1- sr]; p>
c [num +1- sr] = c [J] - c [num +1- sr]; p>
c [J] = c [J] - c [num +1- sr]; p>
) p>
if (I! = (num +2- st)) p>
( p>
for (j = 1; j <= num +1; j + +) ( p>
A [I] [j] = A [I] [j] + A [num +2- st] [j]; p>
A [num +2- st] [j] = A [I] [j] - A [num +2- st] [j]; p>
A [I] [j] = A [I] [j] - A [num +2- st] [j];) p>
) p>
) p>
// --------------------------------------------- --------------------- p>
void otvet () p>
( p>
float temp; p>
for (i = num; i> = 1; i -) p>
( p>
temp = A [i] [num +1]; p>
for (j = num; j> i; j -) temp = temp - A [i] [j] * x [j]; p>
x [i] = temp/A [ i] [i]; p>
) p>
) p>
// --------------------------------------------- --------------------- p>
void interface () p>
( p>
clrscr (); p>
print (num, num +1); p>
cout << "n Масив перестановок стовпців"; p>
for (i = 1; i <= num; i + +) cout << "" <
) p>
// --------------------------------------------- --------------------- p>
void load_file () p>
( p>
char ch; p>
ifstream in ( "c: gaussmat.dat "); p>
cout << "n"; p>
for (i = 1; i <= num; i ++) p>
( p>
c [i] = i; p>
while (ch! = '|') in>> ch; p>
ch = 'q'; p>
for (j = 1; j <= num +1; j + +) in>> A [i] [j]; p>
) p>
) p>
// --------------------------------------------- --------------------- p>
void main () p>
( p>
clrscr (); p>
load_file (); p>
int g; p>
for (g = num +1; g> = 3; g -) p>
( p>
interface (); max_el (g-1, g); getch (); p>
perestanovka (g-1, g); interface (); getch (); p>
preob (num +2- g); interface (); getch (); p>
) p>
clrscr (); p>
print (num, num +1); p>
otvet (); p>
print (num, num +1); p>
cout << "nn"; p>
long double X [num]; p>
for (i = 1; i <= num; i + +) X [c [i]] = x [i]; p>
for (i = 1; i <= num; i + +) cout << "X" <
getch (); p>
) p>
Тестові завдання.
Завдання № 1 (знайти невідомі):
4.24x1 + 2.73x2 - 1.55x3 = 1.87 p>
2.34x1 + 1.27x2 + 3.15x3 = 2.16 p>
3.05x1 - 1.05x2 - 0.63x3 = -1.25 p>
1.1 Результат виконання програми:
x1 = - 0.025461 x2 = 0.915112 x3 = 0.335678 p>
1.2 Розрахунок похибки обчислення:
4.24 * (- 0.025461) + 2.73 * 0.915112 - 1.55 * 0.335678 = 1,87000022 похибка: 2,2 * 10-7 p>
2.34 * (- 0.025461) + 1.27 * 0.915112 + 3.15 * 0.335678 = 2,1599992 похибка: 8,0 * 10-7 p>
3.05 * (- 0.025461) - 1.05 * 0.915112 - 0.63 * 0.335678 = -1,25000079 похибка: 7,9 * 10-7 p>
середня похибка обчислення: 6,0 * 10-7 p>
Завдання № 2 (знайти невідомі):
3.81x1 + 0.25x2 + 1.28x3 + (0.75 + a) x4 = 4.21 p>
2.25x1 + 1.32x2 + (4.5 + a) x3 + 0.49x4 = 6.47 + b p>
5.31x1 + (0.28 + a) x2 + 0.98x3 + 1.04x4 = 2.38 p>
(9.39 + a) x1 + 2.45x2 + 3.35x3 + 2.28x4 = 10.48 + b p>
a = (0,1,2,3,4) b = (0,1,2 , 3,4,5) p>
2.1 Таблиця значень.
a
b
Відповіді:
0
0
X1 = -12.660899
X2 = -16.107649
X3 = 5.273899
X4 = 66.299137
1
X1 = -12.132586
X2 = -14.858407
X3 = 5.186943
X4 = 63.347289
2
X1 = -11.604272
X2 = -13.609166
X3 = 5.099988
X4 = 60.39544
3
X1 = -11.075957
X2 = -12.359925
X3 = 5.013031
X4 = 57.443595
4
X1 = -10.547642
X2 = -11.110685
X3 = 4.926076
X4 = 54.491746
5
X1 = -10.019327
X2 = -9.861445
X3 = 4.839121
X4 = 51.539901
1
0
X1 = 13.959632
X2 = -39.106359
X3 = 7.324007
X4 = -27.756765
1
X1 = 16.668562
X2 = -46.672114
X3 = 8.73446
X4 = -33.605312
2
X1 = 19.377489
X2 = -54.237864
X3 = 10.144913
X4 = -39.453861
3
X1 = 22.086416
X2 = -61.803618
X3 = 11.555367
X4 = -45.30241
4
X1 = 24.795347
X2 = -69.369373
X3 = 12.96582
X4 = -51.150959
5
X1 = 27.504276
X2 = -76.935127
X3 = 14.376274
X4 = -56.999508
2
0
X1 = 1.033843
X2 = -1.696273
X3 = 0.997951
X4 = -0.211727
1
X1 = 1.191176
X2 = -2.016845
X3 = 1.183171
X4 = -0.486773
2
X1 = 1.348508
X2 = -2.337417
X3 = 1.36839
X4 = -0.761819
3
X1 = 1.505841
X2 = -2.657989
X3 = 1.55361
X4 = -1.036865
4
X1 = 1.663174
X2 = -2.978561
X3 = 1.73883
X4 = -1.311911
5
X1 = 1.820507
X2 = -3.299134
X3 = 1.92405
X4 = -1.586957
3
0
X1 = 0.772977
X2 = -0.794749
X3 = 0.762146
X4 = 0.13016
1
X1 = 0.872765
X2 = -0.954303
X3 = 0.902687
X4 = -0.008559
2
X1 = 0.972553
X2 = -1.113856
X3 = 1.043229
X4 = -0.147278
3
X1 = 1.072341
X2 = -1.27341
X3 = 1.18377
X4 = -0.285998
4
X1 = 1.172129
X2 = -1.432964
X3 = 1.324311
X4 = -0.424717
5
X1 = 1.271917
X2 = -1.592518
X3 = 1.464853
X4 = -0.563436
4
0
X1 = 0.675128
X2 = -0.476895
X3 = 0.645225
X4 = 0.196021
1
X1 = 0.754634
X2 = -0.580642
X3 = 0.763131
X4 = 0.105936
2
X1 = 0.83414
X2 = -0.68439
X3 = 0.881037
X4 = 0.015852
3
X1 = 0.913647
X2 = -0.788137
X3 = 0.998942
X4 = -0.074233
4
X1 = 0.993153
X2 = -0.891884
X3 = 1.116848
X4 = -0.164317
5
X1 = 1.072659
X2 = -0.995631
X3 = 1.234754
X4 = -0.254402