FORTRAN was developed to solve scientific and technical problems. A repository with a large number of columns is more natural from a scientific point of view, since the general rule of linear algebra uses column vectors and often treats matrices as concatenations of column vectors. In matrix vector multiplications, column vectors are located on the right side (after multiplication), with subsequent matrices being added further on the left side, for example. B*(A*x) . Languages โโsuch as COBOL, PL / 1, and C treat matrices as collections of row entries, so row ordering is more natural for them.
In linear algebra, a vector is represented by its coordinates: x = x[1]*e1 + x[2]*e2 + ... + x[n]*en where x[i] are vector coordinates, and ei is the i th basic vector. In the matrix representation, the basis vectors are column vectors. Then the linear operator A acting on x gives:
y = A*x = A*{x[1]*e1 + x[2]*e2 + ... x[n]*en} = x[1]*(A*e1) + x[2]*(A*e2) + ... x[n]*(A*en)
In the matrix representation, the linear operator A consists of columns n , column i is the result of A acting on the ith basis vector, and A*x then just a linear combination of columns A with coefficients for x coordinates. In FORTRAN, this will be:
! Zero out the result vector DO k = 1,n y(k) = 0.0 END DO ! Iterate over the columns of A DO i = 1,n ! Add the i-th column to the linear combination with a weight of x(i) w = x(i) DO k = 1,n y(k) = y(k) + w*A(k,i) END DO END DO
This automatically takes advantage of column storage A This may seem uncomfortable, but back in the 50s, when FORTRAN was born, the FMAC hardware and register optimization were not at all as popular as they are now.
source share