New Matrix Java Program

So this quar­ter at UCSC I’m tak­ing a cou­ple math classes but, unfor­tu­nately, I’m not tak­ing any com­puter classes. That’s a bit of a bum­mer because I’ve recently real­ized I’m in LOVE with pro­gram­ming. I love the fact I’m cre­at­ing some­thing from scratch that is work­ing, inter­ac­tive, and returns work­able out­put. For me that’s a big deal, I love cre­ative tan­gi­ble things like art, crafts, and cook­ing (espe­cially bak­ing bagels!) I’d call myself new to pro­gram­ming still, but I’m get­ting the hang of it quickly and lov­ing where it’s tak­ing me.

My TA in one of my math classes encour­aged com­puter peo­ple to imple­ment the process of bring­ing a rec­tan­gu­lar matrix to reduced row ech­e­lon form. If you’re famil­iar with this pro­ce­dure, you know it’s a pain in the butt man­u­ally. So I took on the chal­lenge since I’m not doing any other pro­gram­ming at the moment. I used the shell code of a pre­vi­ous project that solves sudoku puz­zles. If you can imag­ine, a sudoku is just a matrix with strict 9x9 dimen­sions. So my new pro­gram accepts a matrix of any size and out­puts the reduced row ech­e­lon form.

Just as an exam­ple, there is a matrix in a file test2:

$ java matrix test2

Initial Matrix is 5 x 8

0  0  0  0  0  1  2  3

0  2  0  3  0  4  0  6

0  1  2  3  4  5  6 -9

1  3 -9 -2 -3 -4  1  2

1  2  4  5  1 10 22 33

Reduced row echelon form:

1      0      0      0   53/5      0   94/5    -47

0      1      0      0 -132/5      0  -86/5    144

0      0      1      0  -56/5      0  -33/5     63

0      0      0      1   88/5      0   44/5    -98

0      0      0      0      0      1      2      3 uses a cus­tom frac­tion class to han­dle frac­tions instead of using dec­i­mals. Also I found a nifty port of getopt for java that I used to han­dle com­mand line argu­ments. Check out the code and use it / mod­ify it for your­self over at my GitHub page. Also look around my pro­file for the sudoku solver and other code. In future ver­sions I hope to add some func­tion­al­ity such as check­ing the con­sis­tency of the input matrix as well as solv­ing for the vari­ables. Check the git repo for future changes if you’d like!


2 thoughts on “New Matrix Java Program

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>