Matrix multiplication: Difference between revisions
Content deleted Content added
m →{{header|REXX}}: added comment, changed sep character, changed indentation of DO loops. -- ~~~~ |
|||
Line 2,311: | Line 2,311: | ||
=={{header|REXX}}== |
=={{header|REXX}}== |
||
⚫ | |||
<lang rexx> |
|||
⚫ | |||
⚫ | |||
⚫ | |||
x.1='1 2' |
x.1='1 2' |
||
x.2='3 4' |
x.2='3 4' |
||
x.3='5 6' |
x.3='5 6' |
||
x.4='7 8' |
x.4='7 8' |
||
do r=1 while x.r\=='' |
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 |
do c=1 while x.r\==''; parse var x.r a.r.c x.r; end |
||
end |
end |
||
Arows=r-1; Acols=c-1 |
Arows=r-1; Acols=c-1 |
||
⚫ | |||
⚫ | |||
y.1='1 2 3' |
y.1='1 2 3' |
||
y.2='4 5 6' |
y.2='4 5 6' |
||
do r=1 while y.r\=='' |
do r=1 while y.r\=='' /*build the "B" matric from Y. #s*/ |
||
do c=1 while y.r\==''; parse var y.r b.r.c y.r; end |
do c=1 while y.r\==''; parse var y.r b.r.c y.r; end |
||
end |
end |
||
Brows=r-1; Bcols=c-1 |
Brows=r-1; Bcols=c-1 |
||
c.=0; L=0 /*L is the |
c.=0; L=0 /*L is the ma width element value*/ |
||
do i=1 for Arows |
do i =1 for Arows /*multiply matrix A & B ──► C */ |
||
do j=1 for Bcols |
do j =1 for Bcols |
||
do k=1 for Acols |
do k=1 for Acols |
||
c.i.j=c.i.j+a.i.k*b.k.j; L=max(L,length(c.i.j)) |
c.i.j = c.i.j + a.i.k * b.k.j; L=max(L,length(c.i.j)) |
||
end /*k*/ |
end /*k*/ |
||
end /*j*/ |
end /*j*/ |
||
Line 2,344: | Line 2,341: | ||
call showMat 'B',Brows,Bcols |
call showMat 'B',Brows,Bcols |
||
call showMat 'C',Arows,Bcols |
call showMat 'C',Arows,Bcols |
||
exit /*stick a fork in it, we're done.*/ |
|||
exit |
|||
/*──────────────────────────────────SHOWMAT subroutine──────────────────*/ |
|||
⚫ | |||
⚫ | |||
/*─────────────────────────────────────SHOWMAT subroutine───────────────*/ |
|||
do r =1 for rows; _= |
|||
⚫ | |||
⚫ | |||
⚫ | |||
end |
|||
⚫ | |||
⚫ | |||
'''output''' |
|||
end |
|||
⚫ | |||
return |
|||
─A matrix─ |
|||
⚫ | |||
Output: |
|||
⚫ | |||
-A matrix- |
|||
1 2 |
1 2 |
||
3 4 |
3 4 |
||
Line 2,363: | Line 2,357: | ||
7 8 |
7 8 |
||
──B matrix─── |
|||
--B matrix--- |
|||
1 2 3 |
1 2 3 |
||
4 5 6 |
4 5 6 |
||
──C matrix─── |
|||
--C matrix--- |
|||
9 12 15 |
9 12 15 |
||
19 26 33 |
19 26 33 |