Matrix multiplication: Difference between revisions
Content added Content deleted
Walterpachl (talk | contribs) (→{{header|REXX}}: add Signal on Syntax) |
No edit summary |
||
Line 2,083: | Line 2,083: | ||
=={{header|Emacs Lisp}}== |
=={{header|Emacs Lisp}}== |
||
<syntaxhighlight lang="lisp"> |
<syntaxhighlight lang="lisp"> |
||
(defvar M1 '((2 1 4) |
|||
⚫ | |||
⚫ | |||
(let () |
|||
⚫ | |||
(defun matrices-multiply (m1 m2) |
|||
(-2 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) ) ) ) ) |
|||
(seq-map (lambda (a1) |
|||
⚫ | |||
⚫ | |||
(apply #'seq-mapn #'list M2))) |
|||
⚫ | |||
M1) |
|||
(-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 |
|||
⚫ | |||
) |
|||
</syntaxhighlight> |
</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
((5 27 -2 12) (-1 6 0 6)) |
|||
⚫ | |||
</pre> |
</pre> |
||