-1

I'm using BOOST library for inversing a matrix and it is giving me bad results like -1.#IND

I was wondering if anybody ran into this problem.

the code is like this:

void tryLib(){
    AG_Matrix AG_Matrix_1=AG_Matrix(4,4,3.0);
    AG_Matrix AG_Matrix_4=AG_Matrix_1.Inverse();
    std::cout<<AG_Matrix_4(1,1)<<'\n';
}

AG_Matrix is a type definition and the console output is this:

-1.#IND
Press any key to continue . . .

I modified the code and the results are good now, yet I'm not quite sure what the reason was. I will mention the reason here, when I discover it...The determinant was zero, that was the problem as answered below by Mr.Llama ...

Megidd
  • 7,089
  • 6
  • 65
  • 142
  • 1
    You should at least post a minimal program giving the same error along with your question... Without that, nobody can answer. – perror Aug 05 '14 at 15:12
  • 1
    Please include the code you're using to get the error. Without any code to look at, there's not much StackOverflow can do to help. Please see how to make a [Minimal, Complete, Verifiable Example](http://stackoverflow.com/help/mcve). – Mr. Llama Aug 05 '14 at 15:13

1 Answers1

1

A 4x4 matrix with all values equal to 3.0 is a singular matrix and has no inverse, hence the invalid floating point that's returned.
I would recommend checking the matrix's determinant before you run an invert on it.

Your problem isn't a code issue, it's a math issue.

Mr. Llama
  • 20,202
  • 2
  • 62
  • 115
  • Thanks, that was right. I should implement a conditional statement in the code so that the inverse would be calculated only if the determinant is nonzero. – Megidd Aug 05 '14 at 17:07