Just another update
This commit is contained in:
parent
a25938f123
commit
00a190b0a6
6591 changed files with 94363 additions and 23227 deletions
|
|
@ -1,28 +1,33 @@
|
|||
/*REXX program to create and display an identity matrix. */
|
||||
call identity_matrix 4 /*build and display a 4x4 matrix.*/
|
||||
call identity_matrix 5 /*build and display a 5x5 matrix.*/
|
||||
/*REXX program creates and displays any sized identity matrix. */
|
||||
do k=3 to 6 /* [↓] build & display a matrix.*/
|
||||
call identity_matrix k /*build and display a kxk matrix.*/
|
||||
end /*k*/ /* [↑] use general─purpose disp.*/
|
||||
exit /*stick a fork in it, we're done.*/
|
||||
/*─────────────────────────────────────IDENTITY_MATRIX subroutine───────*/
|
||||
/*──────────────────────────────────IDENTITY_MATRIX subroutine──────────*/
|
||||
identity_matrix: procedure; parse arg n; $=
|
||||
|
||||
do r=1 for n /*build indentity matrix, by row,*/
|
||||
do c=1 for n /* and by cow.*/
|
||||
$=$ (r==c) /*append zero or one (if on diag)*/
|
||||
end /*c*/
|
||||
end /*r*/
|
||||
do r=1 for n /*build identity matrix, by row,*/
|
||||
do c=1 for n /* ··· and by col.*/
|
||||
$=$ (r==c) /*append zero or one (if on diag)*/
|
||||
end /*c*/
|
||||
end /*r*/
|
||||
|
||||
call showMatrix 'identity matrix of size' n,$,n
|
||||
call showMatrix 'identity matrix of size' n, $
|
||||
return
|
||||
/*─────────────────────────────────────TELL subroutine───&find the order*/
|
||||
showMatrix: procedure; parse arg hdr,x,order,sep; if sep=='' then sep='═'
|
||||
width=2 /*width of field to be used to display the elements*/
|
||||
decPlaces=1 /*# decimal places to the right of decimal point. */
|
||||
say; say center(hdr,max(length(hdr)+6,(width+1)*words(x)%order),sep); say
|
||||
#=0
|
||||
do row=1 for order; aLine=
|
||||
do col=1 for order; #=#+1
|
||||
aLine=aLine right(format(word(x,#),,decPlaces)/1, width)
|
||||
end /*col*/ /*dividing by 1 normalizes the #.*/
|
||||
say aLine
|
||||
end /*row*/
|
||||
/*──────────────────────────────────SHOWMATRIX subroutine───────────────*/
|
||||
showMatrix: procedure; parse arg hdr,x; #=words(x) /*#: # of elements*/
|
||||
dp=0 /*DP: dec fraction width.*/
|
||||
w=0 /*W: integer part width.*/
|
||||
do n=1 until n*n>=#; _=word(x,n) /*find matrix order (size).*/
|
||||
parse var _ y '.' f; w=max(w, length(y)); dp=max(dp, length(f))
|
||||
end /*n*/ /* [↑] idiomatically find widths to align output*/
|
||||
w=w+1
|
||||
say; say center(hdr, max(length(hdr)+6, (w+1)*#%n), '─'); say
|
||||
#=0 /*#: element #*/
|
||||
do row=1 for n; _=left('',n+w) /*indentation.*/
|
||||
do col=1 for n; #=#+1 /*bump element*/
|
||||
_=_ right(format(word(x, #), , dp)/1, w)
|
||||
end /*col*/ /* [↑] division by 1 normalizes #*/
|
||||
say _ /*display one line of the matrix. */
|
||||
end /*row*/
|
||||
return
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue