Math DSL Part Deux - Elementary Row Operations (EROs)

Posted by Warner Onstine Mon, 26 Nov 2007 18:59:24 GMT

After sending out my query to the groovy user list I got back some ideas (no offense to Yann, just something I need to tackle on my own, so I didn’t look at your solution). What I ended up doing was two-fold:

  • Create a new MetaClass using ExpandoMetaClass
  • Define a new class that understood what row and matrix it was going to operate on (so it can have its own operator overloading)

Yes it was a little bit of extra work, but worth it. I also implemented my or operator overloading so that I can specify augmented matrices in three formats:

  • A|I for the identity matrix (only works on square matrices)
  • A|0 for the zero column, used for solving the set of linear equations
  • A|b for a vector column, also used for solving the set of linear equations

As always it helps to learn from others’ mistakes (and oddities) so I’ll share mine along the road:

  • When dealing with EMC (ExpandoMetaClass) watch out for the use of the this keyword
  • Closure delegates don’t always act the way you would hope when extending GroovyObjectSupport (at least I couldn’t get it to work right which is one reason why I switched to EMC)
  • Overriding the or operator works fine until you get to an object that has overridden the equals operator. In this case Groovy kept trying to find out if my Matrix was equal to my MatrixColumn. Once I figured this out I just returned false if the MatrixColumn was being compared against a Matrix then it worked as expected.

The next part I want to add is the ability to track the EROs through Elementary Matrices. These are matrices that start out as 1s along the diagonal and they get the same EROs applied to them (this will be useful further down the line for other operations).

Trackbacks

Use the following link to trackback from your own site:
http://www.warneronstine.com/blog/articles/trackback/306

Comments

Leave a response

Comments