Matrix multiplication: Difference between revisions
Content added Content deleted
m (Added output.) |
Drkameleon (talk | contribs) (Added Arturo implementation) |
||
Line 543: | Line 543: | ||
{{Out}} |
{{Out}} |
||
<lang AppleScript>{{51, -8, 26, -18}, {-8, -38, -6, 34}, {33, 42, 38, -14}, {17, 74, 72, 44}}</lang> |
<lang AppleScript>{{51, -8, 26, -18}, {-8, -38, -6, 34}, {33, 42, 38, -14}, {17, 74, 72, 44}}</lang> |
||
=={{header|Arturo}}== |
|||
<lang rebol>printMatrix: function [m][ |
|||
loop m 'row -> print map row 'val [pad to :string .format:".2f" val 6] |
|||
print "--------------------------------" |
|||
] |
|||
multiply: function [a,b][ |
|||
X: size a |
|||
Y: size first b |
|||
result: array.of: @[X Y] 0 |
|||
loop 0..X-1 'i [ |
|||
loop 0..Y-1 'j [ |
|||
loop 0..(size first a)-1 'k -> |
|||
result\[i]\[j]: result\[i]\[j] + a\[i]\[k] * b\[k]\[j] |
|||
] |
|||
] |
|||
return result |
|||
] |
|||
A: [[1.0 1.0 1.0 1.0] |
|||
[2.0 4.0 8.0 16.0] |
|||
[3.0 9.0 27.0 81.0] |
|||
[4.0 16.0 64.0 256.0]] |
|||
B: @[@[ 4.0 0-3.0 4/3.0 0-1/4.0] |
|||
@[0-13/3.0 19/4.0 0-7/3.0 11/24.0] |
|||
@[ 3/2.0 0-2.0 7/6.0 0-1/4.0] |
|||
@[ 0-1/6.0 1/4.0 0-1/6.0 1/24.0]] |
|||
printMatrix A |
|||
printMatrix B |
|||
printMatrix multiply A B |
|||
printMatrix multiply B A</lang> |
|||
{{out}} |
|||
<pre> 1.00 1.00 1.00 1.00 |
|||
2.00 4.00 8.00 16.00 |
|||
3.00 9.00 27.00 81.00 |
|||
4.00 16.00 64.00 256.00 |
|||
-------------------------------- |
|||
4.00 -3.00 1.33 -0.25 |
|||
-4.33 4.75 -2.33 0.46 |
|||
1.50 -2.00 1.17 -0.25 |
|||
-0.17 0.25 -0.17 0.04 |
|||
-------------------------------- |
|||
1.00 0.00 -0.00 -0.00 |
|||
0.00 1.00 -0.00 -0.00 |
|||
0.00 0.00 1.00 0.00 |
|||
0.00 0.00 0.00 1.00 |
|||
-------------------------------- |
|||
1.00 0.00 0.00 0.00 |
|||
0.00 1.00 -0.00 0.00 |
|||
0.00 0.00 1.00 0.00 |
|||
0.00 0.00 -0.00 1.00 |
|||
--------------------------------</pre> |
|||
=={{header|AutoHotkey}}== |
=={{header|AutoHotkey}}== |