Skip to content

Instantly share code, notes, and snippets.

@Relecto
Last active June 3, 2020 11:00
Show Gist options
  • Select an option

  • Save Relecto/a2cc209520a9271cd68519050e048a6a to your computer and use it in GitHub Desktop.

Select an option

Save Relecto/a2cc209520a9271cd68519050e048a6a to your computer and use it in GitHub Desktop.
minor and cofactor of 3x3 matrix
console.clear()
matrix = [
[1, -1, 3],
[-2, 5, 7],
[1, 1, 2]
]
for (let i = 0; i < 3; i++) {
for (let j = 0; j < 3; j++) {
let minor = JSON.parse(JSON.stringify(matrix))
minor.splice(i, 1)
minor.forEach(c => c.splice(j, 1))
let M = minor[0][0] * minor[1][1] - minor[0][1] * minor[1][0]
let A = Math.pow(-1, (i + 1) + (j + 1)) * M
console.log(`M(${i + 1},${j + 1}) = ${minor[0][0]} * ${minor[1][1]} - ${minor[0][1]} * ${minor[1][0]} = ${M}`)
// console.log(`M(${i + 1},${j + 1}) = ${M}`)
console.log(`A(${i + 1},${j + 1}) = ${A}`)
minor.forEach(row => console.log(row))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment