Matrix multiplication: Difference between revisions

m
→‎{{header|REXX}}: added comments, added whitespace, split some lines, used better subroutine name.
m (Added Sidef language.)
m (→‎{{header|REXX}}: added comments, added whitespace, split some lines, used better subroutine name.)
Line 2,719:
 
=={{header|REXX}}==
<lang rexx>/*REXX program multiplies two2 matrixes together, shows matrixes &and result*/
yx.2 = 4 5 6 /*can eliminate /*the quotes. beginnings of the A matrix.*/
x.=
x.1 = 1 2 /*╔═════════════════════════════╗*/
x.1 = '1 2'
x.2 = 3 4 /*║As none of the values haven't║*/
x.2 = '3 4'
x.3 = " 5 6" /*either║a kindsign, ofquotes quotearen't worksneeded. */
x.4 = 7 8 /*╚═════════════════════════════╝*/
x.4 = '7 8'
do r=1 while x.r\=='' /*build the "A" matric from X. #s*/
do c=1 while x.r\==''; parse var x.r a.r.c x.r; end
end /*r*/
Arows=r-1 /*adjust number of rows (DO loop)*/
Arows=r-1; Acols=c-1
Acols=c-1 /* " " " cols " " */
y.=
y.1 = 1 2 3 /*if all values are/*the positive,beginnings of the B matrix.*/
xy.1 = ' 1 2' 3
y.2 = 4 5 6 /*can eliminate the quotes. */
xy.2 = '3 4' 5 6
do r=1 while y.r\=='' /*build the "B" matric from Y. #s*/
do do cr=1 while y.r\==''; /*build the parse"B" varmatric y.rfrom bY.r.c y.r; end#s*/
do c=1 while y.r\==''; parse var y.r b.r.c y.r; end
end
Brows=r-1; Bcols=c-1
c.Brows=0; L=0r-1 /*L is maxadjust widthnumber of anrows element.(DO loop)*/
Bcols=c-1 do i =1 for Arows /*multiply matrix A" " " cols & B" ──� " C */
c.=0; L=0 do j =1 for Bcols /*L is max width of an element.*/
do i do k=1 for AcolsArows /*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=max(L,length(c.i.j))
end /*k*/
end /*j*/
end end /*i*/
 
call showMatshowMatrix 'A', Arows, Acols /*display matrix A ───► terminal.*/
call showMatshowMatrix 'B', Brows, Bcols /* " " B ───► " */
call showMatshowMatrix 'C', Arows, Bcols /* " " C ───► " */
exit /*stick a fork in it, we're done.*/
/*──────────────────────────────────SHOWMATRIX subroutine───────────────*/
/*──────────────────────────────────SHOWMAT subroutine──────────────────*/
showMatshowMatrix: parse arg mat,rows,cols; say
say center(mat 'matrix',cols*(L+1)+4,"─")
do r =1 for rows; _=
do c=1 for cols; _=_ right(value(mat'.'r'.'c),L); end; say _
end /*r*/
return</lang>
{{out}}