The question is more theoretical. How can the forward and reverse Gauss processes be solved when solving a SLAE in one procedure, that is, it means, in one cycle, in one “pass”?

Once again, I don’t need the entire algorithm. I need only an idea in words with a very brief explanation to it.

Perhaps, try to organize any cycle from n-1 to 0 (well, if the SLAE is nxn), where the coefficients of the matrix will vanish in a magical way, and the solution vector will be considered?

If suddenly someone might need a piece of code that implements these two moves, then here it is:

/// Прямой ход bool gausss( tdouble ** mtx, tdouble * vect ) { tdouble c; for ( int j = 0; j < n; j++ ) { tdouble temp = abs( mtx[j][j] ); int mem = j; максимум for ( int i = j + 1; i < n; i++ ) { // от j+1 if ( temp < abs( mtx[i][j] ) ) { temp = abs( mtx[i][j] ); mem = i; } } if ( temp < eps ) return false; changing( mtx, vect, mem, j ); for ( int i = j + 1; i < n; i++ ) { c = mtx[i][j] / mtx[j][j]; for ( int k = j; k < n; k++ ) { mtx[i][k] -= c * mtx[j][k]; } vect[i] -= c * vect[j]; } } return true; } /// Обратный ход void gausss_reverse( tdouble ** mtx, tdouble * vect, tdouble * sol ) { for ( int i = n - 1; i >= 0; i-- ) { tdouble temp = 0; for ( int j = i + 1; j < n; j++ ) { temp += mtx[i][j] * sol[j]; } sol[i] = (vect[i] - temp) / mtx[i][i]; } } 
  • Separately, it is usually done this way: a cycle is written "for a forward stroke", and then for a "reverse stroke". In the "forward stroke", the main element is selected, then the coefficients are zeroed in accordance with this, and the matrix is ​​reduced to upper triangular form. In the "reverse course" a cycle is organized from n-1 to 0 and the X are recalculated according to the well-known formula @ AntonSazonov - MGMKLML
  • @ AntonSazonov I know, yes. In my program it is implemented. - MGMKLML
  • What I mean is that if you show the solution separately in the form of a code, then the chances of getting an answer will be greater. I myself, alas, in SLAU do not have a tooth in my foot ... - Anton Sazonov
  • one
    @ AntonSazonov Understood, corrected). - MGMKLML

1 answer 1

Well, look.

What is usually the Gauss method? You in the direct course get zeros under the diagonal. And on the reverse - over the diagonal. This can be easily combined.

In the combined algorithm, you first execute the step of the direct method — this produces zeros under the diagonal. Now you can “kill” nonzero coefficients over it with the current line. Thus, your matrix will look like this (example for the third step):

 a11 0 0 a14 0 a22 0 a24 0 0 a33 a34 0 0 0 a44 0 0 0 a54 .............. 

At each step, you add one column to the diagonal view of the matrix.

In principle, at each step you can also divide by the diagonal element to get a unit there. Then at the end you have a column of free members will become a decision column.

  • Yes, thank you very much))). I needed it to today's lab, but there we sort of could somehow figure it out). But anyway, thanks for the reply) - MGMKLML
  • @MGMKLML: Please! - VladD