Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bool Gauss( double A [10][10], double B[10], int N, double X[10])
- {
- int i, j;
- for ( i = 1; i <= N-1; i++)
- {
- int k=i;
- R=abs(A[i][i]);
- for ( j= i+1; j <= N; j++)
- {
- if (abs(A[j][i]>R))
- {
- k = j;
- R = (abs(A[j][i]));
- }
- }
- if (R< 1e-7)
- {
- MessageBox::Show(" розв`язку немає ");
- return false;
- }
- if (k != i)
- {
- R= B[k];
- B[k]= B[i];
- B[i]= R;
- for (j=1; j<= N; j++)
- {
- R= A[k][j];
- A[k][j]= A[i][j];
- A[i][j]= R;
- }
- }
- R= A[i][i];
- B[i]= B[i]/R;
- for (j=1; j<= N; j++)
- A[i][j]= A[i][j]/R;
- for (k=i+1; k<= N+1; k++)
- {
- R=A[k][i];
- B[k]= B[k] - R*B[i];
- A[k][i] = 0;
- for (j= i+1; j<= N; j++)
- A[k][j]= A[k][j] - R*A[i][j];
- }
- }
- if (abs(A[N][N]) <= 1e-7)
- {
- MessageBox::Show(" Рівняння не сумісне ");
- return false;
- }
- for (int i = 0; i < N; i++)
- for (int j = 0; j < N; j++)
- {
- C_Matr->Rows[i]->Cells[j] -> Value = Convert::ToString(A[i + 1][j + 1]);
- }
- MessageBox::Show("Завершили прямий хід");
- // Зворотній хід
- X[N]= B[N]/A[N][N];
- for (int i = N - 1; i >= 1; i--)
- {
- R = B[i];
- for (int j = i + 1; j <= N; j++) R -= A[i][j] * X[j];
- X[i] = R;
- }
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement