Matrix multiplication: Difference between revisions
Content added Content deleted
No edit summary |
|||
Line 3,185: | Line 3,185: | ||
Original source: [http://seed7.sourceforge.net/algorith/math.htm#mmult] |
Original source: [http://seed7.sourceforge.net/algorith/math.htm#mmult] |
||
=={{header|SequenceL}}== |
|||
:The product of the ''m''×''p'' matrix ''A'' with the ''p''×''n'' matrix ''B'' is the ''m''×''n'' matrix whose (''i'',''j'')'th entry is |
|||
::<math>\sum_{k=1}^p A(i,k)B(k,j)</math> |
|||
The SequenceL definition mirrors that definition more or less exactly: |
|||
<lang sequencel>matmul(A(2), B(2)) [i,j] := |
|||
let k := 1...size(B); |
|||
in sum( A[i,k] * B[k,j] ); |
|||
//Example Use |
|||
a := [[1, 2], |
|||
[3, 4]]; |
|||
b := [[-3, -8, 3], |
|||
[-2, 1, 4]]; |
|||
test := matmul(a, b);</lang> |
|||
It can be written a little more simply using the all keyword: |
|||
<lang sequencel>matmul(A(2), B(2)) [i,j] := sum( A[i,all] * B[all,j] );</lang> |
|||
=={{header|Sidef}}== |
=={{header|Sidef}}== |