views:

1615

answers:

3

I'm trying to inverse a matrix with version Boost boost_1_37_0 and MTL mtl4-alpha-1-r6418. I can't seem to locate the matrix inversion code. I've googled for examples and they seem to reference lu.h that seems to be missing in the above release(s). Any hints?

@Matt suggested copying lu.h, but that seems to be from MTL2 rather than MTL4. I'm having trouble compiling with MTL2 with VS05 or higher.

So, any idea how to do a matrix inversion in MTL4?

Update: I think I understand Matt better and I'm heading down this ITL path.

+3  A: 

Looks like you use lu_factor, and then lu_inverse. I don't remember what you have to do with the pivots, though. From the documentation.

And yeah, like you said, it looks like their documentations says you need lu.h, somehow:

How do I invert a matrix?

The first question you should ask yourself is whether you want to really compute the inverse of a matrix or if you really want to solve a linear system. For solving a linear system of equations, it is not necessary to explicitly compute the matrix inverse. Rather, it is more efficient to compute triangular factors of the matrix and then perform forward and backward triangular solves with the factors. More about solving linear systems is given below. If you really want to invert a matrix, there is a function lu_inverse() in mtl/lu.h.

If nothing else, you can look at lu.h on their site.

Matt Cruikshank
Thanks. Yeah, I'm in the middle of that trying to make/port lu.h I found, but it seems to be a different version and my linear al is quite rusty.
kenny
A: 

I've never used boost or MTL for matrix math but I have used JAMA/TNT.

This page http://wiki.cs.princeton.edu/index.php/TNT shows how to take a matrix inverse. The basic method is library-independent:

  1. factor matrix M into XY where X and Y are appropriate factorizations (LU would be OK but for numerical stability I would think you would want to use QR or maybe SVD).

  2. solve I = MN = (XY)N for N with the prerequisite that M has been factored; the library should have a routine for this.

Jason S
A: 

I'm closing this since I'm not looking into it anymore for the company I was working for. I think both answers are correct but @Jason was the right path.

kenny