When using floating point matrices in Ada 2005+ the function is defined as "Unit_Matrix" in Ada.Numerics.Generic_Real_Arrays. As a generic package it can work with user defined floating point types, or the predefined Short_Real_Arrays, Real_Arrays, and Long_Real_Arrays initializations. As seen below, the first indices of both dimensions can also be set since Ada array indices do not arbitrarily begin with a particular number.

BEGIN PRINT(CHR$(12);) ! CLS INPUT("Matrix size",N%) !$DIM A[N%,N%] FOR I%=1 TO N% DO A[I%,I%]=1 END FOR! print matrix FOR I%=1 TO N% DO FOR J%=1 TO N% DO WRITE("###";A[I%,J%];) END FOR PRINT END FOREND PROGRAM

Fōrmulæ programs are not textual, visualization/edition of programs is done showing/manipulating structures but not text. Moreover, there can be multiple visual representations of the same program. Even though it is possible to have textual representation —i.e. XML, JSON— they are intended for transportation effects more than visualization and edition.

The option to show Fōrmulæ programs and their results is showing images. Unfortunately images cannot be uploaded in Rosetta Code.

allocate(I(ms,ms)) I =0! Initialize the array. forall(j =1:ms) I(j,j)=1! Set the diagonal.

! I is the identity matrix, let's show it:

write (fmt, '(A,I2,A)')'(', ms, 'F6.2)'! if you consider to have used the (row, col) convention, ! the following will print the transposed matrix (col, row)! but I' = I, so it's not important here write (*, fmt) I(:,:)

The objective is to do the assignment in one fell swoop, rather than separately setting the 0 values and the 1 values. It works because, with integer arithmetic, the only way that both i/j and j/i are one is when they are equal - thus one on the diagonal elements, and zero elsewhere because either i < j so that i/j = 0, or i > j so that j/i = 0. While this means two divides and a multiply per element instead of simply transferring a constant, the constraint on speed is likely to be the limited bandwidth from cpu to memory. The expression's code would surely fit in the cpu's internal memory, and registers would be used for the variables.

Program IdentityInteger NParameter(N =666)Real A(N,N)Integer i,j

ForAll(i =1:N, j =1:N) A(i,j)=(i/j)*(j/i)

END

The ForAll statement is a feature of F90, and carries the implication that the assignments may be done in any order, even "simultaneously" (as with multiple cpus), plus that all RHS values are calculated before any LHS part receives a value - not relevant here since the RHS makes no reference to items altered in the LHS. Earlier Fortran compilers lack this statement and so one must use explicit DO-loops:

DO1 I =1,NDO1 J =1,N1 A(I,J)=(I/J)*(J/I)

Array assignment statements are also a feature of F90 and later.

An alternative might be a simpler logical expression testing i = j except that the numerical values for true and false on a particular system may well not be 1 and 0 but (for instance, via Compaq F90/95 on Windows XP) 0 and -1 instead. On an IBM 390 mainframe, pl/i and Fortran used different values. The Burroughs 6700 inspected the low-order bit only, with the intriguing result that odd integers would be deemed true and even false. Integer arithmetic can't be relied upon across languages either, because in pl/i, integer division doesn't truncate.

Flat: Representation as a single flat slice. You just have to know to handle it as a square matrix. In many cases that's not a problem and the code is simpler this way. If you want to add a little bit of type checking, you can define a matrix type as shown here.

The REXX language doesn't have matrices as such, so the problem is largely how to display the "matrix".

The code to display the matrices was kept as a stand-alone general-purpose (square) matrix display
subroutine, which, in part, determines if the square matrix is indeed a square matrix based on the
number of elements given.

It also finds the maximum widths of the integer and decimal fraction parts (if any) and uses those widths
to align (right-justify according to the [possibly implied] decimal point) the columns of the square matrix.

It also tries to display a centered (and easier to read) matrix, along with a title.