Matrix multiplication: Difference between revisions

Added Easylang
(add ooRexx)
(Added Easylang)
(5 intermediate revisions by 4 users not shown)
Line 2,016:
[75,00, 75,00, 75,00]
[117,00, 117,00, 117,00]]</pre>
=={{header|EasyLang}}==
}</syntaxhighlight>
proc matmul . m1[][] m2[][] r[][] .
r[][] = [ ]
for i to len m1[][]
(-2r[][] 5&= 0[ 2)))]
for j = 1 to len m2[1][]
r[i][] &= 0
for k to len m2[][]
r[i][j] += m1[i][k] * m2[k][j]
(0 1 1))) .
.
.
.
mat1[][] = [ [ 1 2 3 ] [ 4 5 6 ] ]
mat2[][] = [ [ 1 2 ] [ 3 4 ] [ 5 6 ] ]
matmul mat1[][] mat2[][] erg[][]
print erg[][]
</syntaxhighlight>
 
{{out}}
<pre>
[
[ 22 28 ]
[ 49 64 ]
]
</pre>
 
=={{header|EGL}}==
<syntaxhighlight lang="egl">
Line 2,083 ⟶ 2,111:
=={{header|Emacs Lisp}}==
<syntaxhighlight lang="lisp">
(defvar M1 '((2 1 4)
-1 6 (0 1 6 1)))
 
(m2defvar M2 '(( 6 3 -1 0)
(let ()
( 1 1 0 4)
(defun matrices-multiply (m1 m2)
(let (fn-row-mult2 5 0 2)))
(setq fn-row-mult
(lambda (row col-idx)
(let ((col (cl-loop for m2-row in m2
collect (nth col-idx m2-row))))
(apply '+ (cl-loop for v1 in row for v2 in col
collect (* v1 v2))) ) ) )
(cl-loop for m1-row in m1 collect
(seq-map-indexed (lambda (v col-idx)
(funcall fn-row-mult m1-row col-idx) )
(nth 0 m2) ) ) ) )
 
(letseq-map ((m1lambda '((2 1 4a1)
(seq-map (lambda (itema2) (formatapply "%5s#'+ "(seq-mapn item))#'* line)a1 a2) ) ) ) )
(0 1 1)))
(apply #'seq-mapn #'list M2)))
(m2 '((6 3 -1 0)
(1 1 0 4M1)
(-2 5 0 2)))
result-matrix)
 
(switch-to-buffer-other-window "**matrix-result**")
(erase-buffer)
(setq result-matrix (matrices-multiply m1 m2))
(cl-loop for line in result-matrix do
(insert (format "%s\n"
(apply 'concat
(seq-map (lambda (item) (format "%5s " item)) line) ) ) ) ) )
)
</syntaxhighlight>
 
{{out}}
<pre>
((5 27 -2 12) (-1 6 120 6))
-1 6 0 6
</pre>
 
Line 5,607 ⟶ 5,612:
{{works with|Rakudo|2022.07-3}}
 
Here is an evena more concisefunctional version, expressing the product of two matrices as the cross dot product of the first matrix with the transpose of the second :
 
<syntaxhighlight lang="raku" line>sub infix:<×·>( { [+] @A,^a Z* @B)^b {}
sub crossinfix:<×>(@A, ([Z] @B), with{ =>(@A { [+Z] @^a Z* B).rotor(@^bB) })
</syntaxhighlight>
.rotor(@B);
}</syntaxhighlight>
 
=={{header|Rascal}}==
Line 5,639 ⟶ 5,643:
=={{header|REXX}}==
<syntaxhighlight lang="rexx">/*REXX program calculates the Kronecker product of two arbitrary size matrices. */
Signal On syntax
x.=0
amat=4X2 1 2 3 4 5 6 7 8 /* define A matrix size and elements */
Line 5,711 ⟶ 5,716:
exit:
Say arg(1)
Exit
 
Syntax:
Say 'Syntax raised in line' sigl
Say sourceline(sigl)
Say 'rc='rc '('errortext(rc)')'
Say '***** There was a problem!'
Exit</syntaxhighlight>
{{out|output|text=&nbsp; when using the internal default input:}}
Line 6,653 ⟶ 6,665:
{{libheader|Wren-matrix}}
{{libheader|Wren-fmt}}
<syntaxhighlight lang="ecmascriptwren">import "./matrix" for Matrix
import "./fmt" for Fmt
 
var a = Matrix.new([
1,969

edits