Matrix multiplication: Difference between revisions

(Added BBC BASIC)
Line 797:
The following version uses 2D arrays as inputs.
 
<lang lisp>(defun mmul (A B)
(defun mmul (a b)
(let* ((m (car (array-dimensions A)))
(loop
(n (cadr (array-dimensions A)))
with m (l (cadr= (array-dimensionsdimension a B))0)
with n (C= (makearray-arraydimension `(,m ,l) :initial-elementa 0))1)
(loop for i fromwith 0l to= (array-dimension mb 1) do
with c = (make-array (looplist form kl) from:initial-element 0 to (- l 1) do
for i below m (setf (aref C i k)do
(loop for jk from 0 to (-below nl 1)do
sum (*setf (aref Ac i jk)
(arefloop Bfor j k))))))below n
sum (* (aref a i j)
C))</lang>
(aref b j k)))))
finally (return c)))
 
;; Example use:
(mmul #2a((1 2) (3 4)) #2a((-3 -8 3) (-2 1 4)))
;; gives: #2A((-7 -6 11) (-17 -20 25))
C))</lang>
 
=={{header|D}}==
Anonymous user