Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
11З.doc
Скачиваний:
4
Добавлен:
10.09.2019
Размер:
1.31 Mб
Скачать

Inverting of matrixes.

It is hardest operation and we can use algorithm from Joahna mathematics library:

INT i,j,k;

for (INT i = 0;i<n;i++)

for(j = 0;j<n;j++)

Y[i][j] = X[i][j];

/* Locations of pivot elements */

INT pvt_i[7], pvt_j[7];

double pvt_val; /* Value of current pivot element */

double buf; /* Temporary storage */

for (k = 0; k < n; k++)

{

/* Locate k'th pivot element */

pvt_val = Y[k][k]; /* Initialize for search */

pvt_i[k] = k;

pvt_j[k] = k;

for(i = k; i < n; i++)

for(j = k; j < n; j++)

if(fabs(Y[i][j]) > fabs(pvt_val)) {

pvt_i[k] = i;

pvt_j[k] = j;

pvt_val = Y[i][j];

}

if(pvt_val==0) {

/* Matrix is singular (zero determinant). */

printf("Matrix is singular.");

getch();

exit(ERROR_CODE);

}

/* "Interchange" rows (with sign change stuff) */

i = pvt_i[k];

if (i != k) /* If rows are different */

for (j = 0; j < n; j++)

{

buf = -Y[k][j];

Y[k][j] = Y[i][j];

Y[i][j] = buf;

}

/* "Interchange" columns */

j = pvt_j[k];

if (j != k) /* If columns are different */

for (i = 0; i < n; i++)

{

buf = -Y[i][k];

Y[i][k] = Y[i][j];

Y[i][j] = buf;

}

/* Divide column by minus pivot value */

for (i = 0; i < n; i++)

if (i != k) /* Don't touch the pivot entry */

Y[i][k] /= ( -pvt_val) ; /* (Tricky C syntax for division) */

/* Reduce the matrix */

for (i = 0; i < n; i++)

{

buf = Y[i][k];

for (j = 0; j < n; j++)

if ( i != k && j != k ) /* Don't touch pivot. */

Y[i][j] += buf * Y[k][j];

}

/* Divide row by pivot */

for (j = 0; j < n; j++)

if (j != k) /* Don't touch the pivot! */

Y[k][j] /= pvt_val;

/* Replace pivot by reciprocal (at last we can touch it). */

Y[k][k] = 1.0/pvt_val;

}

/* That was most of the work, one final pass of row/column interchange */

/* to finish */

for (k = n-2; k >= 0; k--) /* Don't need to work with 1 by 1 corner */

{

i = pvt_j[k]; /* Rows to swap correspond to pivot COLUMN */

if (i != k) /* If rows are different */

for(j = 0; j < n; j++)

{

buf = Y[k][j];

Y[k][j] = -Y[i][j];

Y[i][j] = buf;

}

j = pvt_i[k]; /* Columns to swap correspond to pivot ROW */

if (j != k) /* If columns are different */

for (i = 0; i < n; i++)

{

buf = Y[i][k];

Y[i][k] = -Y[i][j];

Y[i][j] = buf;

}

}

return ;

According to this part, there are was developed program, that calculating input data for Eller method. Code of this program is represented in Appendix A.

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]