Join GitHub today
Add cofactor and first_minor methods for the Matrix class #568
The cofactor is very useful and important operation.
We can do some calculations more smart.
# a is object of Matrix class # Determinant a[0,0] * a.cofactor(0,0) + a[0,1] * a.cofactor(0,1) .. #Matrix of cofactors c = Matrix.new([a.cofactor(0,0), a.cofactor(0,1)..], [a.cofactor(1,0).. # Inverse of a matrix c.transpose/a.determinant # cross product v1, v2, .. , v(n-1): n-vector e = Vector[1,1...,1] a = Matrix[e, v1, v2, .. , v(n-1)] Vector[a.cofactor(0,0), a.cofactor(0,1), .. ,a.cofactor(0,n-1)]
It help us to think general definition(it means m * n matrix) of determinant, inverse, and other.
Great work @gogotanaka
I've made some small comments, otherwise this looks good.
It would be great if you could also modify the NEWS file, and make sure you end up with 2 commits (on for