forum.alglib.net

ALGLIB forum
It is currently Tue Dec 10, 2024 10:52 am

All times are UTC


Forum rules


1. This forum can be used for discussion of both ALGLIB-related and general numerical analysis questions
2. This forum is English-only - postings in other languages will be removed.



Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Error in rmatrixinverse
PostPosted: Sun Mar 20, 2011 11:28 pm 
Offline

Joined: Sun Jun 06, 2010 5:03 am
Posts: 1
Hi alglib folks. First of all, thank you for making such a nice library. It is very useful!

I have run into an error in rmatrixinverse. Instead of returning the inverse of the input, it returns the negative of the inverse. When the returned inverse is multiplied with the original matrix, I get the negative of the identity matrix, not the identity matrix.

Please let me know if I am doing something incorrect. I appreciate your help.

I will provide C# test code to demonstrate.

Code:
// INITIALIZE VARIABLES
double[,] identity= new double[3, 3];
double[,] inverse = new double[3, 3];
double[,] original = new double[3, 3];
original[0, 0] = 1970.8937129336348;
original[0, 1] = 950.2643718955394;
original[0, 2] = 68.593866605156848;
original[1, 0] = -717.567202536722;
original[1, 1] = 1679.1060115738908;
original[1, 2] = 1237.0289481009058;
original[2, 0] = 0.31232455601872822;
original[2, 1] = -0.21461017714273767;
original[2, 2] = 0.92541657839832714;
for(int row_index = 0; row_index < 3; row_index++)
{
  for(int column_index = 0; column_index < 3; column_index++)
  {
     inverse[row_index, column_index] = original[row_index, column_index];
  }
}

// COMPUTE INVERSE
int success = 0;
alglib.matinv.matinvreport report = new alglib.matinv.matinvreport();
alglib.matinv.rmatrixinverse(ref inverse, 3, ref success, ref report);
if (success != 1)
{
  throw new Exception("Failure to solve for inverse.");
}

// CHECK RESULTS
ablas.rmatrixgemm(3,
        3,
        3,
        1.0,
        ref inverse,   // 3 x 3
        0,
        0,
        0,
        ref original,   // 3 x 3
        0,
        0,
        0,
        0,
        ref identity,  // 3 x 3
        0,
        0);

for(int row_index = 0; row_index < 3; row_index++)
{
  for(int column_index = 0; column_index < 3; column_index++)
  {
     if(row_index == column_index)
     {
       if(Math.Abs(identity[row_index, column_index] - 1) > Math.Pow(10,-6))
       {
            throw new Exception("Inverse multiplied by original does not give identity.");
       }
     }
     else
     {
       if(Math.Abs(identity[row_index, column_index]) > Math.Pow(10,-6))
       {
            throw new Exception("Inverse multiplied by original does not give identity.");
       }
     }
  }
}


Top
 Profile  
 
 Post subject: Re: Error in rmatrixinverse
PostPosted: Wed Mar 23, 2011 5:45 pm 
Offline
Site Admin

Joined: Fri May 07, 2010 7:06 am
Posts: 927
I've tried to reproduce this error. First, I was unable to compile your code with recent version of ALGLIB. Some arguments were passed with unnecessary ref's (don't know how you've managed to compile it). Second, after fixes, it calculated inverse successfully, with desired precision.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group