patchGNU Octave - Patches: patch #8622, basic matrix functions

 
 

patch #8622: basic matrix functions

Submitter:  None
Submitted:  Mon 16 Mar 2015 11:02:33 AM UTC
   
 
Category:  None Priority:  1 - Later
Status:  Invalid Privacy:  Public
Assigned to:  None Originator Email:  -email is unavailable-
Open/Closed:  Closed
* Mandatory Fields

Add a New Comment Rich Markup
   

Tue 17 Mar 2015 10:33:55 AM UTC, comment #5: 

To catch up the discussion, the mathematical background is doing the following computation:

http://www.mathsisfun.com/algebra/matrix-inverse-minors-cofactors-adjugate.html

Note: I don't want to offend anyone with the chosen link, but the example is very intuitive to get the ideas quickly.

After reading the example and the code provided, I have to agree to Jordi, these functions may be useful for educational purpose. For example create an Octave tutorial page explaining the background like in the link and provide the explained m-code for others students to benefit from.

But the code is not suitable to go into the Octave core.

Kai Torben Ohlhus <siko1056>
Group Member
Mon 16 Mar 2015 04:03:51 PM UTC, comment #4: 

Hahahah (this was actually funny).
yeah man. i see. I am now successfully unconvinced. hahaha.

-Deleted Account- <jbe>
Mon 16 Mar 2015 03:53:56 PM UTC, comment #3: 

In that case, the fastest way to compute adjugate matrices is to do det(A)*inv(A)... but this is so trivial that I hardly think it requires a whole new function, and anyone who really needs adjugate matrices with blithe disregard for numerical stability can simply do det(A)*inv(A).

I am still unconvinced we need this code.

Jordi GutiƩrrez Hermoso <jordigh>
Group Member
Mon 16 Mar 2015 03:15:44 PM UTC, comment #2: 

Thanks for your opinion. However I do disagree with some of the response.

" adjugate and cofactors are numerically useless...". For your purposes, yes, they're useless. To some students starting a course in linear algebra/matrices, it's useful. I'm sure if I had something more complex to do I would use something smarter from Octave or an Octave-Forge package. Yes there are better ways of computing the inverse. It's a matter of choice. What if I need to do it this way? Who cares about being computationally expensive when it almost instantly spits out results for my 4x4 matrix? Someone who is actually concerned about those factors would NOT be looking for these functions.

Perhaps I could include a warning in the function similar to how some other Octave functions warn of being expensive.

-- About copy and paste code and the % comments etc
 Yes, it needs cleaning up. The Matlab style is how I learned, but I can change it. I just wrote the functions so I could have something that worked.

I would like to fix the code. It should be obvious that I am still a noob at math and Octave/Matlab, so could you please clarify what type of numerical errors or conditions would cause the errors?

Thanks

-Deleted Account- <jbe>
Mon 16 Mar 2015 01:53:45 PM UTC, comment #1: 

I am sorry to say this, but I do not think there is much value to these contributions.

The problem is numerical stability. The adjugate and cofactors of a matrix are essentially numerically useless, in part because the determinant itself is numerically useless. Near singular matrices can have large determinants and well-conditioned matrices can have small determinants. See Golub & Van Loan, section 2.7.3, "Determinants and Nearness to Singularity."

Even if we decide to include these functions with the proviso that it is in fact impossible to properly handle numerical error, we certainly cannot accept a cut-and-paste job:

    https://en.wikipedia.org/wiki/Copy_and_paste_programming#/media/File:Forgotten_edits_in_copypaste_programming.gif

If you disagree strongly, a first step to convince me to accept these functions is to modify them to not be nearly identical to each other, a second step would be to follow Octave style (e.g. comments with #, not with %), and a third step would be to come up with some way to handle numerical error.

The adjugate also has one further disadvantage: it's just about the worst possible way to compute an inverse. In addition to the unstability problems described above, it is also the most computationally expensive, with complexity well above O(n^3), depending on the determinant implementation. If done symbolically, like in a CAS, the adjugate is O(n!), just about the worst possible.

Jordi GutiƩrrez Hermoso <jordigh>
Group Member
Mon 16 Mar 2015 11:02:33 AM UTC, original submission:  

These two functions ( adjunct() and cofactors() ) implement some basic matrix operations that were not found in the octave package. The adjunct of a matrix or its cofactors are used for calculating inverse matrices and other operations. An inv() function is already in octave however these two functions are for cases where you want to check the calculations that you do by hand. They should save users time in going through the long process, esp. for long homework assignments where it is required to show the calculation steps.

Anonymous

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

Attached Files
file #33358:  cofactors.m added by None (1KiB - text/x-objcsrc)
file #33359:  adjunct.m added by None (1KiB - text/x-objcsrc)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by siko1056 (Posted a comment)
  • -email is unavailable- added by jbe (Posted a comment)
  • -email is unavailable- added by jordigh (Posted a comment)
  • -email is unavailable- added by None (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.

     

    Follow 5 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2015-03-16 jordigh Priority7 - High 1 - Later
        StatusNone Invalid
        Open/ClosedOpen Closed
    2015-03-16 None Attached File- Added cofactors.m, #33358
        Attached File- Added adjunct.m, #33359

    Back to the top

    Powered by Savane 3.13-caa5.
    Corresponding source code