0% found this document useful (0 votes)
43 views1 page

Matriks Vermenigvuldiging: Naiwe Algoritme: Const

This document describes a basic algorithm for multiplying two matrices. It defines two sample matrices A and B of sizes 3x2 and 2x3, respectively. It then uses a nested for loop to iterate through the matrices, multiplying and summing the values at each overlapping index to calculate the result matrices C.

Uploaded by

karelvdwalt9366
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views1 page

Matriks Vermenigvuldiging: Naiwe Algoritme: Const

This document describes a basic algorithm for multiplying two matrices. It defines two sample matrices A and B of sizes 3x2 and 2x3, respectively. It then uses a nested for loop to iterate through the matrices, multiplying and summing the values at each overlapping index to calculate the result matrices C.

Uploaded by

karelvdwalt9366
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Matriks Vermenigvuldiging : Naiwe Algoritme

const A = [ // mXn i.e.3X2


[0, 1]
,[2, 3]
,[4, 5]
];

var m = A.length;
var n = A[0].length;

//console.table( A );
//console.log( n );

const B = [ // nXp i.e.2X3


[0, 1, 2]
,[3, 4, 5]
];

//var n = B.length;
var p = B[0].length;

if (A[0].length !== B.length) {


// mXn & nXp => mXp
throw new Error('number of columns in the first matrix should be
the same as the number of rows in the second');
}

var C = [];

for (var i = 0; i < m; i++) {


C[i] = [];
for (var j = 0; j < p; j++) {
var sum = 0; https://en.wikipedia.org/wiki/Matrix_multiplication_algorithm
for (var k = 0; k < n; k++) {
sum = sum + A[i][k] * B[k][j];
}
C[i][j] = sum;
}
}

console.table( C );

You might also like