Created
September 16, 2015 18:17
-
-
Save jwerle/13cd6a94724c7534f195 to your computer and use it in GitHub Desktop.
Identity matrix construction from the KroneckerDelta function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
// kronecker delta | |
let kd = (i, j) => i == j ? 1 : 0; | |
// (In)ij identity matrix constructor | |
let I = n => { | |
let a = [], k = 0; | |
for (let i = 0; i < n; ++i) | |
for (let j = 0; j < n; ++j) | |
a[k++] = kd(i, j); | |
return a; | |
}; | |
// constructs | |
let mat2 = _ => I(2); | |
let mat3 = _ => I(3); | |
let mat4 = _ => I(4); | |
// proof | |
console.log(4 == mat2().length); | |
console.log(9 == mat3().length); | |
console.log(16 == mat4().length); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment