Page 88 - Compact Numerical Methods For Computers
P. 88

Linear equations—a direct approach               77
                       Algorithm 6. Gauss elimination back-substitution
                       This algorithm is designed to follow Gauss elimination (algorithm 5), but can be applied also
                       to systems of equations which are already triangular or which have been brought to triangular
                      form by other methods, for instance, the Givens’ reduction of §4.2 (algorithm 3).
                        procedure gebacksub(n, p:integer; {size of problem n=nRow, p=nRHS}
                                            var A : rmatrix); {work array containing
                                               Gauss elimination reduced coefficient
                                               matrix and transformed right hand sides}

                        {alg06.pas == Gauss elimination back-substitution.
                        Places solutions to linear equation systems in columns n+1,..,n+p
                        of matrix A. Alg05.pas (Gauss elimination) must be executed first with
                        right hand sides in the columns n+1,..,n+p of matrix A in order
                        to triangularize the system of equations.
                                      Copyright 1988 J. C. Nash
                        }
                        var
                           s : real; {accumulator}
                           i, j, k: integer;
                        begin
                           writeln(‘alg06.pas -- Gauss elimination back-substitution’);
                           for i:=(n+1) to (n+p) do {STEP 1}
                           begin
                              A[n,i]:=A[n,i]/A[n,n]; {STEP 2}
                              for j:=(n-1) down to 1 do {STEP 3}
                              begin
                                 s:=A[j,i]; {STEP 4}
                                 for k:=(j+1) to n do {STEP 5}
                                 begin
                                   s:=s-A[j,k]*A[k,i]; {to subtract contributions from solution
                                                  elements which have already been determined}
                                 end; {loop on k}
                                 A[j,i]:=s/A[j,j]; {STEP 6 -- to fix solution element j}
                              end; {loop on j -- STEP 7}
                           end; {loop on i -- STEP 8}
                        end; {alg06.pas}


                       The solutions to the triangular system(s) of equations and hence to the original equations
                      (2.2) are contained in columns n + 1, n + 2, . . . , n+p, of the working array.
                       Example 6.1. The use of linear equations and linear least-squares problems
                       Organisations which publish statistics frequently use indices to summarise the
                       change in some set of measurable quantities. Already in example 3.2 we have
                       used indices of the use of various chemicals in agriculture and an index for farm
                       income. The consumer price index, and the Dow Jones and Financial Times
                       indices provide other examples. Such indices are computed by dividing the
                      average value of the quantity for period t by the average for some base period
                       t = 0 which is usually given the index value 100. Thus, if the quantity is called P,
                      then
                                                                                         (6.28)
   83   84   85   86   87   88   89   90   91   92   93