== Magic Technologic Inc.==
Volume 0x0c, Algoritms 0x10, Phile #0x0a of 0x0f
|=-----------------------------------------------------------------=| |=----------------=[ Решение СЛАУ методом Гаусса ]=----------------=| |=-----------------------------------------------------------------=| |=----------------=[ Copyright (c) Flame Of Soul ]=----------------=| |=---------------=[ [E-mail]: _allbasse@yandex.ru ]=---------------=| |=-----------------------------------------------------------------=| #include "stdio.h" #include "iostream.h" bool getLUDecomposition( double **matrixU, double **matrixL, int currRowAndColumn, int numberOfEquation ) { bool result; int i, k; double tempItem; result = ( matrixU[currRowAndColumn][currRowAndColumn] != 0 ); if ( result && currRowAndColumn < numberOfEquation - 1 ) { for ( i = currRowAndColumn + 1; i < numberOfEquation; i++ ) { matrixL[i][currRowAndColumn] = matrixU[i][currRowAndColumn] / matrixU[currRowAndColumn][currRowAndColumn]; tempItem = - matrixL[i][currRowAndColumn]; for ( k = currRowAndColumn; k < numberOfEquation; k++ ) { matrixU[i][k] = matrixU[i][k] + matrixU[currRowAndColumn][k]*tempItem;}} result = getLUDecomposition( matrixU, matrixL, currRowAndColumn + 1, numberOfEquation );} return result;}
void main() { int i, j; int size; double **matrixU, **matrixL; cout << "Gauss'es method of LU.\nEnter system dimension: "; cin >> size; matrixU = new double*[size]; matrixL = new double*[size]; for ( i = 0; i < size; i++ ) { matrixU[i] = new double[size]; matrixL[i] = new double[size]; for ( j = 0; j < size; j ++ ){ matrixL[i][j] = ( i == j ? 1 : 0 );}} for ( i = 0; i < size; i ++ ){ cout << "Enter " << i + 1 << " row: "; for ( j = 0; j < size; j ++ ){ cin >> matrixU[i][j];}} if ( !getLUDecomposition( matrixU, matrixL, 0, size ) ) { cout << "LU-decomposition for this matrix not found";} else { cout << "L-matrix is:\n"; for ( i = 0; i < size; i ++ ){ for ( j = 0; j < size; j ++ ){ cout << matrixL[i][j] << " ";} cout << "\n";} cout << "\nU-matrix is:\n"; for ( i = 0; i < size; i ++ ){ for ( j = 0; j < size; j ++ ){ cout << matrixU[i][j] << " ";} cout << "\n";}} cout << "\nPress \"Enter\" to continue..." << endl; getchar();} |=-----------------------------=[ CPP ]=---------------------------=| |=-----------------------------------------------------------------=|
|