Add cofactor and first_minor methods for the Matrix class #568

Closed
wants to merge 9 commits into
from

Conversation

2 participants
Member

gogotanaka commented Mar 15, 2014

 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.
Member

marcandre commented Mar 15, 2014

 Good proposal. There should really be 3 commits in this PR. There's a change to the doc of minor (not sure about why these changes are needed), the addition of `first_minor` ad the addition of `cofactor`. Would you like to split this in three commits?
Member

gogotanaka commented Mar 16, 2014

 Thank for your review!! I’ll do anything you say. Thank you.

gogotanaka added some commits Mar 16, 2014

``` Add first_minor method for Matrix class ```
``` 630472f ```
``` Add cofactor method for Matrix class ```
``` 83a6496 ```
Member

gogotanaka commented Mar 16, 2014

 I did everything Mr. marcandre said. I would appreciate if you could check it again.

gogotanaka added some commits Mar 16, 2014

``` i -> row, j -> column ```
``` f885266 ```
``` change TypeError to RuntimeError ```
``` 90bd636 ```
``` add test with a 1xn rectangular matrix ```
``` 795393e ```
Member

gogotanaka commented Mar 16, 2014

 Thanks for your reviews again. I did what you said. I appreciate that you gave me a lot of comments.

lib/matrix.rb

lib/matrix.rb
Member

marcandre commented Mar 17, 2014

 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 `first_minor`, then one for `cofactor`). Yeah, this will delete my comments, but that's fine 😃

gogotanaka added some commits Mar 17, 2014

``` improve cofactor's comment ```
``` e4529b5 ```
``` improve first_minor's error message ```
``` 8073007 ```
``` * NEWS: add first_minor method for Matrix class ```
``` 3f860bd ```
``` * NEWS: add cofactor method for Matrix class ```
``` e792a5b ```
Member

gogotanaka commented Mar 17, 2014

 I have completed. Thanks for reviewing again and again. Mr. @marcandre
Member

gogotanaka commented Mar 23, 2014

 I have finished all modifications. Could anyone please check it?

marcandre added a commit that referenced this pull request Apr 6, 2014

``` * lib/matrix.rb: Add Matrix#cofactor [fix GH-568] ```
```  Patch by gogotanaka

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45528 b2dd03c8-39d4-4d8f-98ff-823fe69b080e```
``` d11d87c ```
Member

marcandre commented Apr 6, 2014

 Committed, thanks for the PR!

mmasaki pushed a commit to mmasaki/ruby that referenced this pull request Apr 21, 2014

``` * lib/matrix.rb: Add first_minor [fix GH-568] ```
```  Patch by gogotanaka

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45527 b2dd03c8-39d4-4d8f-98ff-823fe69b080e```
``` 85f0eb7 ```

mmasaki pushed a commit to mmasaki/ruby that referenced this pull request Apr 21, 2014

``` * lib/matrix.rb: Add Matrix#cofactor [fix GH-568] ```
```  Patch by gogotanaka

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45528 b2dd03c8-39d4-4d8f-98ff-823fe69b080e```
``` c8e4ba7 ```