Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bool gauss(double A[6][6], double B[6], int N, double X[6])
- {
- double C[6][6];
- int i, j, k;
- float R;
- {
- j = 0;
- for (i = 1; i <= (N - 1);)
- {
- k = i;
- R = Math::Abs(A[i][i]);
- for (j = i + 1; j <= N;)
- {
- if (Math::Abs(A[j][i]) >= R)
- {
- k = j;
- R = Math::Abs(A[j][i]);
- }
- if (R < 1e-7)
- {
- MessageBox::Show("rivnanja ne symisne");
- }
- if (k != i)
- {
- R = B[k];
- B[k] = B[i];
- B[i] = R;
- for (j = i; j <= N;)
- {
- 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;)
- {
- A[i][j] = A[i][j] / R;
- }
- for (k = i + 1; k <= N;)
- {
- R = A[k][i];
- B[k] = B[k] - R*B[i];
- A[k][i] = 0;
- for (j = i + 1; j = N;)
- {
- A[k][j] = A[k][j] - R*A[i][j];
- }
- }
- if (Math::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_Matrix_dgv->Rows[i]->Cells[j]->Value = Convert::ToString(A[i + 1][j + 1]);
- }
- 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