Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / February 2006

Tip: Looking for answers? Try searching our database.

Matrix inversion algorithm examples

Thread view: 
Robert M. Gary - 10 Feb 2006 16:52 GMT
Does anyone have any code examples of doing a Matrix inversion that I
could look at? I'm trying to get a sense of strategies to go about it.
I understand inversions from a pure mathematical/algebra point of view
but it seems like there could be different ways of going about
implmenting it in code. I"m working on a website to do financial
portfolio modeling and a lot of the algorithms are matrix based. I
understand the graphics guys use matrices a lot too.

-Robert
Chris Smith - 10 Feb 2006 17:53 GMT
> Does anyone have any code examples of doing a Matrix inversion that I
> could look at? I'm trying to get a sense of strategies to go about it.
[quoted text clipped - 3 lines]
> portfolio modeling and a lot of the algorithms are matrix based. I
> understand the graphics guys use matrices a lot too.

First of all, there are several ways to represent matrices.  If your
matrices are "dense" (that is, most cells contain non-zero values), then
you just store all the values.  If your matrices are "sparse" (that is,
most cells are zero... or some other known value), then you get far
better performance from a sparse matrix structure that just stores the
non-zero values.  This makes huge differences in the code to perform
operations.

Beyond that, I'll let someone else respond who has the time to write a
better answer.

Signature

www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation

Robert M. Gary - 10 Feb 2006 22:03 GMT
> your matrices are "dense" (that is, most cells contain non-zero values), then you just store all the values.

Sorry, mine are dense. Mostly they are matrices of asset price
variance.

-Robert
Chris Lamb - 10 Feb 2006 19:31 GMT
> Does anyone have any code examples of doing a Matrix inversion that I
> could look at? I'm trying to get a sense of strategies to go about it.
[quoted text clipped - 5 lines]
>
> -Robert

An example using Gaussian Elimination:

Jama - http://math.nist.gov/javanumerics/jama/

Most times, if you are inverting a matrix, you should be inverting
something small so sparse/dense representation shouldn't matter. If
you are inverting a matrix so large that sparse representation
improves algorthm performance, you are doing the wrong thing. Almost
always if you are inverting say a 1,000x1,000 matrix you havn't
understood the problem. Also, forming the direct inverse of a large
matrix will buld up errors such that your answer is near meaningless.

HTH

Chris
Patricia Shanahan - 10 Feb 2006 20:50 GMT
>>Does anyone have any code examples of doing a Matrix inversion that I
>>could look at? I'm trying to get a sense of strategies to go about it.
[quoted text clipped - 21 lines]
>
> Chris

Are you saying that you should never solve large systems of linear
equations, or just that it is a mistake to do it by directly inverting
the matrix rather than e.g. by LU factorization?

Patricia
Chris Lamb - 10 Feb 2006 20:59 GMT
>>>Does anyone have any code examples of doing a Matrix inversion that I
>>>could look at? I'm trying to get a sense of strategies to go about it.
[quoted text clipped - 25 lines]
> equations, or just that it is a mistake to do it by directly inverting
> the matrix rather than e.g. by LU factorization?

I hope we do need to solve large systems of equations. After all, my PhD
was entirely based on that! Your second statement is right, but I prefer
(well, they perform best in my field) Conjugate Gradients and related
methods.
Yes, it is almost invariably a mistake to do it by direct inversion.

Chris
Chris Uppal - 10 Feb 2006 20:12 GMT
> Does anyone have any code examples of doing a Matrix inversion that I
> could look at? I'm trying to get a sense of strategies to go about it.

You could take a look at JAMA or Jampack from NIST:

   http://math.nist.gov/javanumerics/jama/
   ftp://math.nist.gov/pub/Jampack/Jampack/AboutJampack.html

They might be more "advanced" than you want, though.

   -- chris
Roedy Green - 10 Feb 2006 21:22 GMT
>Matrix inversion

nearly always you just grab a matrix inversion routine from a package.
Anything you write will almost inevitably be slower or blow up more
often. It takes quite a bit of cleverness to avoid error propagation.
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

Robert M. Gary - 10 Feb 2006 22:01 GMT
I may end up just using a package, however I would like to also see an
algorithm just to understand how its working.

-Robert
Jos A. Horsmeier - 10 Feb 2006 22:54 GMT
> Does anyone have any code examples of doing a Matrix inversion that I
> could look at? I'm trying to get a sense of strategies to go about it.
[quoted text clipped - 3 lines]
> portfolio modeling and a lot of the algorithms are matrix based. I
> understand the graphics guys use matrices a lot too.

Never explicitly inverse a matrix; both for performance and numerical
stability reasons. You only need the inverse of a matrix conceptually,
i.e. Ax = b --> x = A^-1 b. For such purposes google for 'LUP decomposition'
of a matrix. It's faster and introduces far less numerical instability.

kind regards,

Jos
Jacob - 11 Feb 2006 18:36 GMT
> Does anyone have any code examples of doing a Matrix inversion that I
> could look at?

This class inverts (check the invert() method) a 4x4 matrix
by the use of cofactors:

http://geosoft.no/software/matrix4x4/Matrix4x4.java.html

This is probably the fastest way to invert this type of
matrix, but might not be generalized to higher dimensions.

> I understand the graphics guys use matrices a lot too.

Yes, but we normally stop at 4x4...


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.