How to resolve the algorithm Matrix multiplication step by step in the Raku programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Matrix multiplication step by step in the Raku programming language
Table of Contents
Problem Statement
Multiply two matrices together. They can be of any dimensions, so long as the number of columns of the first matrix is equal to the number of rows of the second matrix.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Matrix multiplication step by step in the Raku programming language
Source code in the raku programming language
sub mmult(@a,@b) {
my @p;
for ^@a X ^@b[0] -> ($r, $c) {
@p[$r][$c] += @a[$r][$_] * @b[$_][$c] for ^@b;
}
@p;
}
my @a = [1, 1, 1, 1],
[2, 4, 8, 16],
[3, 9, 27, 81],
[4, 16, 64, 256];
my @b = [ 4 , -3 , 4/3, -1/4 ],
[-13/3, 19/4, -7/3, 11/24],
[ 3/2, -2 , 7/6, -1/4 ],
[ -1/6, 1/4, -1/6, 1/24];
.say for mmult(@a,@b);
sub mmult(\a,\b) {
[
for ^a -> \r {
[
for ^b[0] -> \c {
[+] a[r;^b] Z* b[^b;c]
}
]
}
]
}
multi infix:<×> (@A, @B) {
@A.map: -> @a { do [+] @a Z× @B[*;$_] for ^@B[0] }
}
sub infix:<×>(@A, @B) {
cross(@A, ([Z] @B), with => { [+] @^a Z* @^b })
.rotor(@B);
}
You may also check:How to resolve the algorithm Increasing gaps between consecutive Niven numbers step by step in the FreeBASIC programming language
You may also check:How to resolve the algorithm A+B step by step in the Amazing Hopper programming language
You may also check:How to resolve the algorithm Rot-13 step by step in the Wren programming language
You may also check:How to resolve the algorithm Play recorded sounds step by step in the Julia programming language
You may also check:How to resolve the algorithm System time step by step in the Yabasic programming language