• No se han encontrado resultados

Tipos de competencia y estrategia en la didáctica de la lengua

I. B. CULTURA

3) Lo urbano

3.1. Tipos de competencia y estrategia en la didáctica de la lengua

In the reduced system generated during Gauss elimination, the coefficient of xi is 1 in the ith equation and 0 in all subsequent equations. These values do not need to be stored explicitly, however, because the program never actually refers to them.

A variant known as Crout factorization employs these matrix positions, on and below the main diagonal of A (taking into account row interchanges), to record the multipliers that are applied when each row is subtracted from the rows below it. The computation can be rearranged so that all operations on a given element are performed in sequence. A modern optimizing Fortran compiler can preserve the common element in a register—even in an extended precision register—for higher speed and accuracy.

The effect of this Crout reduction algorithm is to replace A by a pair of triangular matrices, L and U, such that A = L × U, where U is an upper triangular matrix and L is lower triangular. Elements of U are the same as the coefficients in the equations after Gauss elimination has been applied, and elements of L are the multipliers that are applied to perfom the elimination. The computations required for Crout factorization are the same as for Gauss elimination except that they are performed in a different se-quence and the multipliers are saved.

After L and U have been computed from A, the system L c = b (where b is the given right side) is easily solved for c, because L is a lower triangular matrix. This solution process, called forward substitu-tion, is described later. The solution vector c from this linear system is identical to the reduced right side obtained by “ordinary” Gauss elimination. (To see this, note that U = L–1 A and c = L–1 b. The transforma-tion by which Gauss eliminatransforma-tion converts A to U is represented by the matrix L–1; the elimination pro-cess applies this same transformation L–1 to the right side b.)

The matrices L and U share the storage space of A, replacing the elements of A as factorization progresses. U is stored above the main diagonal and L is stored below (and on) the diagonal. There is no storage for the diagonal elements of U; each of these represents a leading coefficient that is set to 1 at the beginning of a stage of the elimination. The program takes these values into account implicitly, and does not need to store them.

25 Incorporating row interchanges, the actual factorization can be represented as P A = L U. The per-mutation matrix P is defined by interchanging the rows of an identity matrix in the designated manner.

(In the actual program, however, row interchanges are recorded in compact form, as a vector rather than as a matrix.) The given system A x = b becomes P A x = P b or (after the factorization) L U x = P b. Here P b is simply the permuted version of the given right side vector, which we may call b~. Once L, U, and P have been found by the factorization process, forward substitution is applied to solve the lower trian-gular system L c = b~. As before, back substitution is applied to solve U x = c.

With this method, processing the right side may be postponed until after the factorization is com-pleted, rather than being accomplished concurrently. The factors L and U are stored and row inter-changes are recorded. After the factorization is complete, permutation is applied to the right side. For-ward substitution with L followed by backFor-ward substitution with U now gives the solution x.

This postponement of right side processing can be important. Some applications involve several systems of equations with the same coefficients but with different right sides. The factorization step involves only the coefficient matrix, and needs to be performed only once. Later, forward and backward substitution can be applied separately to each of the right sides. The number of computation steps re-quired for Crout factorization (done only once) is roughly proportional to n3, while the number of steps for forward and back substitution (repeated for each different right side) is proportional to n2. The fol-lowing are two such applications:

For some very common data fitting calculations, A depends upon the characteristics of a measuring instrument while b is obtained from measured data values. Thus, the factorization can be performed once and applied to many sets of data over the lifetime of the instrument.

• The process of iterative refinement, which is a simple way to improve the accuracy of the solution of many linear algebraic systems and to estimate the validity of the result, is described below. This process requires solving a related system with the same matrix A and with a new right side that is not available at the time of the original reduction process, being computed as a high precision re-s i d u a l .

Factorization alternates between reducing a column of L (below the diagonal) and a row of U (to the right of the diagonal). A preliminary Crout factorization program that ignores row interchanges and

“unrolls” all array section operations into explicit loops appears as follows:

doI=1,N

!ReducecolumnI doJ=I,N

doK=1,I-1

A(J,I)=A(J,I)-A(J,K)*A(K,I) enddo

enddo

!ReducerowI doJ=I+1,N

doK=1,I-1

A(I,J)=A(I,J)-A(I,K)*A(K,J) enddo

A(I,J)=A(I,J)/A(I,I) enddo

enddo

1.2 ARRAY TECHNIQUES

Column reduction. Each element in column i of L is reduced by subtracting products of elements, ob-tained by multiplying an element in the row to the right of that element with a corresponding element in the column of U above the diagonal. (Note that there is nothing to subtract when i is 1).

doJ=I,N doK=1,I-1

A(J,I)=A(J,I)-A(J,K)*A(K,I) enddo

enddo

The computation in the inner loop is equivalent to subtracting a scalar product of two vectors; the range of values of the index variable k becomes the row subscript range for one of the vectors and the column subscript range for the other vector:

doJ=I,N

A(J,I)=A(J,I)-dot_product(A(J,:I-1)*A(:I-1,I)) enddo

This loop is eliminated by further use of array section notation. The row vectors are combined into a matrix that is multiplied by the same column vector as before:

A(I:,I)=A(I:,I)-matmul(A(I:,:I-1)*A(:I-1,I))

A special Fortran rule permits one (but not both) of the arguments of matmul to have rank 1.

To reflect row interchanges, the permutation vector p must be applied to all row subscripts of A:

A(P(I:),I)=A(P(I:),I)&

-matmul(A(P(I:),:I-1)*A(P(:I-1),I))

Row reduction. Each element in the row of L is similarly reduced. Note that when i = 1 the inner loop collapses and the only effect is to divide the row by its diagonal element; also, the outer loop collapses when i = n.

doJ=I+1,N doK=1,I-1

A(I,J)=A(I,J)-A(I,K)*A(K,J) enddo

A(I,J)=A(I,J)/A(I,I) enddo

As before, the loops can be converted to array section and matrix multiplication operations. Row inter-changes are applied, and division by the diagonal element is incorporated into the assignment opera-tion:

A(P(I),I+1:)=(A(P(I),I+1:)&

-matmul(A(P(I),:I-1),A(P(:I-1),I+1:)))/A(P(I),I)

The column reduction loop and the row reduction loop have each been reduced to a single array assign-ment stateassign-ment. Only the outer loop remains.

27

Say It with Fortran

In the following Fortran implementation, the subroutine Factor computes the factors L and U (stored in A) and the permutation vector p.

! Crout Factorization with scaled partial pivoting.

subroutine Factor( Flag )

A, P, and N are inherited from a containing program unit. A is an N by N matrix; P is an integer vector of length N; At entry to the subroutine, the coefficient matrix is stored in A. Upon completion, the factors of A have replaced A and the permutation is recorded in P. The local array S has automatic shape. K is an array constructor implied do variable.

logical, intent( out ) :: Flag

real, dimension(size( A, dim = 1 )) :: S integer :: K, I, Loc, Temp

! start subroutine Factor Flag = .false.

The following steps initialize the permutation vector P to a sequence of consecutive integers, and store a copy of the largest element (in absolute value) in each row in the corresponding element of S.

P = (/ (K, K = 1, N) /)

S = maxval( abs( A ), dim = 2 ) if (any( S <=0 )) then

print *, " One of the row norms is zero. "

return end if

Column reduction and row reduction are performed alternately.

doI=1,N