Matrix multiplication: Difference between revisions

m
→‎{{header|REXX}}: added/changed whitespace and comments, changed alignments and indentations.
No edit summary
m (→‎{{header|REXX}}: added/changed whitespace and comments, changed alignments and indentations.)
Line 2,931:
 
=={{header|REXX}}==
<lang rexx>/*REXX program multiplies 2two matrixesmatrices together, showsdisplays matrixesmatrices and result.*/
x.=; x.1=1 2 /*the beginnings of the A matrix.╔═══════════════════════════════════╗*/
x.1 = 1 x.2=3 4 /*╔═════════════════════════════╗║ As none of the matrix values have ║*/
x.2 = 3 4 x.3=5 6 /*║As nonea ofsign, the valuesquotes havenaren't║t needed. ║*/
x.3 = 5 6 x.4=7 8 /*║a sign, quotes aren't needed.║╚═══════════════════════════════════╝*/
do r=1 while x.r\=='' /*build the "A" matrix from X. numbers.*/
x.4 = 7 8 /*╚═════════════════════════════╝*/
do rdo c=1 while x.r\==''; /*build the "A" matricparse fromvar Xx.r a.r.c x.r; #s*/end
end do c=1 while x./*r\==''; parse var x.r a.r.c x.r; end*/
Arows=r-1 end /*radjust the number of rows (DO loop).*/
ArowsAcols=rc-1 /*adjust number of rows" (DO loop) " " " cols " " .*/
y.=; y.1 = 1 2 3
Acols=c-1 /* " " " cols " " */
y.2 = 4 5 6
y. = /*the beginnings of the B matrix.*/
do r=1 while y.r\=='' /*build the "B" matrix from Y. numbers.*/
y.1 = 1 2 3
do c=1 while y.r\==''; parse var y.r b.r.c y.r; end
y.2 = 4 5 6
do end r=1 while y.r\=='' /*build the "B" matric from Y. #sr*/
Brows=r-1 do c=1 while y.r\==''; parse var y.r b.r.c y.r; /*adjust the endnumber of rows (DO loop).*/
AcolsBcols=c-1 /* " " " " cols " " */
end
Browsc.=r-10; w=0 /*adjustW is max numberwidth of rowsan (DOmatrix loop)element.*/
Bcols=c-1 do i=1 for Arows /*multiply matrix " " A " colsand B " ───► " C */
c.=0; L=0 do j=1 for /*L is max width of an element.*/Bcols
do i =1 for Arows /*multiply matrix A & B ──► C */
do j =1 for Bcols
do k=1 for Acols
c.i.j = c.i.j + a.i.k * b.k.j; L w=max(Lw, length(c.i.j))
end /*k*/
end /*j*/
end /*i*/
 
call showMatrix 'A', Arows, Acols /*display matrix A ───► the terminal.*/
call showMatrix 'B', Brows, Bcols /* " " B ───► " " */
call showMatrix 'C', Arows, Bcols /* " " C ───► " " */
exit /*stick a fork in it, we're all done. */
/*────────────────────────────────────────────────────────────────────────────*/
/*──────────────────────────────────SHOWMATRIX subroutine───────────────*/
showMatrix: parse arg mat,rows,cols; say
say center(mat 'matrix', cols*(Lw+1)+4, "─")
do r =1 for rows; _=
do c=1 for cols; _=_ right(value(mat'.'r'.'c),L w); end; say _
end /*r*/
return</lang>
{{out}}