New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cofactor and first_minor methods for the Matrix class #568

Closed
wants to merge 9 commits into
base: trunk
from

Conversation

2 participants
@gogotanaka
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.

@marcandre

This comment has been minimized.

Show comment
Hide comment
@marcandre

marcandre Mar 15, 2014

Member

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

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?

@gogotanaka

This comment has been minimized.

Show comment
Hide comment
@gogotanaka

gogotanaka Mar 16, 2014

Member

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

Member

gogotanaka commented Mar 16, 2014

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

@gogotanaka

This comment has been minimized.

Show comment
Hide comment
@gogotanaka

gogotanaka Mar 16, 2014

Member

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

Member

gogotanaka commented Mar 16, 2014

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

@gogotanaka

This comment has been minimized.

Show comment
Hide comment
@gogotanaka

gogotanaka Mar 16, 2014

Member

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

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.

@marcandre

View changes

Show outdated Hide outdated lib/matrix.rb
@marcandre

View changes

Show outdated Hide outdated lib/matrix.rb
@marcandre

This comment has been minimized.

Show comment
Hide comment
@marcandre

marcandre Mar 17, 2014

Member

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 😃

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

This comment has been minimized.

Show comment
Hide comment
@gogotanaka

gogotanaka Mar 17, 2014

Member

I have completed.

Thanks for reviewing again and again. Mr. @marcandre

Member

gogotanaka commented Mar 17, 2014

I have completed.

Thanks for reviewing again and again. Mr. @marcandre

@gogotanaka

This comment has been minimized.

Show comment
Hide comment
@gogotanaka

gogotanaka Mar 23, 2014

Member

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

Member

gogotanaka commented Mar 23, 2014

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

@marcandre marcandre self-assigned this Apr 6, 2014

@marcandre marcandre closed this in b8ba202 Apr 6, 2014

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
@marcandre

This comment has been minimized.

Show comment
Hide comment
@marcandre

marcandre Apr 6, 2014

Member

Committed, thanks for the PR!

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

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment