octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Octave/C++ matrix Inv() comparison


From: Ed Meyer
Subject: Re: Octave/C++ matrix Inv() comparison
Date: Tue, 16 Jul 2013 21:26:44 -0700



On Thu, Jul 11, 2013 at 2:34 AM, ionone <address@hidden> wrote:
Also to do it simpler, here are the numbers in a 20x20 matrix in Octave and
in C++

the funny thing is that when i take the inverse in octave, ihave the exact
answer, but if i take the inverse with Lapack i have something totally
different...Not even close as before. Dunno...

R=[ 0.100197 0.100187 0.100155 0.100103 0.100030 0.099936 0.099822 0.099687
0.099531 0.099355 0.099158 0.098942 0.098705 0.098448 0.098171 0.097875
0.097559 0.097224 0.096870 0.096496;

0.100187 0.100197 0.100187 0.100155 0.100103 0.100030 0.099936 0.099822
0.099687 0.099531 0.099355 0.099158 0.098942 0.098705 0.098448 0.098171
0.097875 0.097559 0.097224 0.096870;

0.100155 0.100187 0.100197 0.100187 0.100155 0.100103 0.100030 0.099936
0.099822 0.099687 0.099531 0.099355 0.099158 0.098942 0.098705 0.098448
0.098171 0.097875 0.097559 0.097224;

0.100103 0.100155 0.100187 0.100197 0.100187 0.100155 0.100103 0.100030
0.099936 0.099822 0.099687 0.099531 0.099355 0.099158 0.098942 0.098705
0.098448 0.098171 0.097875 0.097559;

0.100030 0.100103 0.100155 0.100187 0.100197 0.100187 0.100155 0.100103
0.100030 0.099936 0.099822 0.099687 0.099531 0.099355 0.099158 0.098942
0.098705 0.098448 0.098171 0.097875;

0.099936 0.100030 0.100103 0.100155 0.100187 0.100197 0.100187 0.100155
0.100103 0.100030 0.099936 0.099822 0.099687 0.099531 0.099355 0.099158
0.098942 0.098705 0.098448 0.098171;

0.099822 0.099936 0.100030 0.100103 0.100155 0.100187 0.100197 0.100187
0.100155 0.100103 0.100030 0.099936 0.099822 0.099687 0.099531 0.099355
0.099158 0.098942 0.098705 0.098448;

0.099687 0.099822 0.099936 0.100030 0.100103 0.100155 0.100187 0.100197
0.100187 0.100155 0.100103 0.100030 0.099936 0.099822 0.099687 0.099531
0.099355 0.099158 0.098942 0.098705;

0.099531 0.099687 0.099822 0.099936 0.100030 0.100103 0.100155 0.100187
0.100197 0.100187 0.100155 0.100103 0.100030 0.099936 0.099822 0.099687
0.099531 0.099355 0.099158 0.098942;

0.099355 0.099531 0.099687 0.099822 0.099936 0.100030 0.100103 0.100155
0.100187 0.100197 0.100187 0.100155 0.100103 0.100030 0.099936 0.099822
0.099687 0.099531 0.099355 0.099158;

0.099158 0.099355 0.099531 0.099687 0.099822 0.099936 0.100030 0.100103
0.100155 0.100187 0.100197 0.100187 0.100155 0.100103 0.100030 0.099936
0.099822 0.099687 0.099531 0.099355;

0.098942 0.099158 0.099355 0.099531 0.099687 0.099822 0.099936 0.100030
0.100103 0.100155 0.100187 0.100197 0.100187 0.100155 0.100103 0.100030
0.099936 0.099822 0.099687 0.099531;

0.098705 0.098942 0.099158 0.099355 0.099531 0.099687 0.099822 0.099936
0.100030 0.100103 0.100155 0.100187 0.100197 0.100187 0.100155 0.100103
0.100030 0.099936 0.099822 0.099687;

0.098448 0.098705 0.098942 0.099158 0.099355 0.099531 0.099687 0.099822
0.099936 0.100030 0.100103 0.100155 0.100187 0.100197 0.100187 0.100155
0.100103 0.100030 0.099936 0.099822;

0.098171 0.098448 0.098705 0.098942 0.099158 0.099355 0.099531 0.099687
0.099822 0.099936 0.100030 0.100103 0.100155 0.100187 0.100197 0.100187
0.100155 0.100103 0.100030 0.099936;

0.097875 0.098171 0.098448 0.098705 0.098942 0.099158 0.099355 0.099531
0.099687 0.099822 0.099936 0.100030 0.100103 0.100155 0.100187 0.100197
0.100187 0.100155 0.100103 0.100030;

0.097559 0.097875 0.098171 0.098448 0.098705 0.098942 0.099158 0.099355
0.099531 0.099687 0.099822 0.099936 0.100030 0.100103 0.100155 0.100187
0.100197 0.100187 0.100155 0.100103;

0.097224 0.097559 0.097875 0.098171 0.098448 0.098705 0.098942 0.099158
0.099355 0.099531 0.099687 0.099822 0.099936 0.100030 0.100103 0.100155
0.100187 0.100197 0.100187 0.100155;

0.096870 0.097224 0.097559 0.097875 0.098171 0.098448 0.098705 0.098942
0.099158 0.099355 0.099531 0.099687 0.099822 0.099936 0.100030 0.100103
0.100155 0.100187 0.100197 0.100187;

0.096496 0.096870 0.097224 0.097559 0.097875 0.098171 0.098448 0.098705
0.098942 0.099158 0.099355 0.099531 0.099687 0.099822 0.099936 0.100030
0.100103 0.100155 0.100187 0.100197]


and here is the same in C++ (i'll save you some time this way)
double R21[20][20]={{0.100197 ,  0.100187 ,  0.100155  , 0.100103 ,
0.100030 ,  0.099936 ,  0.099822 , 0.099687 ,  0.099531 , 0.099355 ,
0.099158 ,  0.098942 ,  0.098705 ,  0.098448 , 0.098171  , 0.097875 ,
0.097559 ,  0.097224 ,  0.096870 , 0.096496},
   {0.100187 ,  0.100197 ,  0.100187  , 0.100155 ,  0.100103 , 0.100030 ,
0.099936 , 0.099822 ,  0.099687 ,  0.099531 , 0.099355 ,  0.099158 ,
0.098942 ,  0.098705 , 0.098448  , 0.098171 ,  0.097875 ,  0.097559 ,
0.097224 ,  0.096870},
   {0.100155 ,  0.100187 ,  0.100197  , 0.100187 ,  0.100155 , 0.100103 ,
0.100030 , 0.099936 ,  0.099822 ,  0.099687 , 0.099531 ,  0.099355 ,
0.099158 ,  0.098942 , 0.098705  , 0.098448 ,  0.098171 ,  0.097875 ,
0.097559 ,  0.097224},
   {0.100103 ,  0.100155 ,  0.100187  , 0.100197 ,  0.100187 , 0.100155 ,
0.100103 , 0.100030 ,  0.099936 ,  0.099822 , 0.099687 ,  0.099531 ,
0.099355 ,  0.099158 , 0.098942  , 0.098705 ,  0.098448 ,  0.098171 ,
0.097875 ,  0.097559},
   {0.100030 ,  0.100103 ,  0.100155  , 0.100187 ,  0.100197 , 0.100187 ,
0.100155 , 0.100103 ,  0.100030 ,  0.099936 , 0.099822 ,  0.099687 ,
0.099531 ,  0.099355 , 0.099158  , 0.098942 ,  0.098705 ,  0.098448 ,
0.098171 ,  0.097875},
   {0.099936 ,  0.100030 ,  0.100103  , 0.100155 ,  0.100187 , 0.100197 ,
0.100187 , 0.100155 ,  0.100103 ,  0.100030 , 0.099936 ,  0.099822 ,
0.099687 ,  0.099531 , 0.099355  , 0.099158 ,  0.098942 ,  0.098705 ,
0.098448 ,  0.098171},
   {0.099822 ,  0.099936 ,  0.100030  , 0.100103 ,  0.100155 , 0.100187 ,
0.100197 , 0.100187 ,  0.100155 ,  0.100103 , 0.100030 ,  0.099936 ,
0.099822 ,  0.099687 , 0.099531  , 0.099355 ,  0.099158 ,  0.098942 ,
0.098705 ,  0.098448},
   {0.099687 ,  0.099822 ,  0.099936  , 0.100030 ,  0.100103 , 0.100155 ,
0.100187 , 0.100197 ,  0.100187 ,  0.100155 , 0.100103 ,  0.100030 ,
0.099936 ,  0.099822 , 0.099687  , 0.099531 ,  0.099355 ,  0.099158 ,
0.098942 ,  0.098705},
   {0.099531 ,  0.099687 ,  0.099822  , 0.099936 ,  0.100030 , 0.100103 ,
0.100155 , 0.100187 ,  0.100197 ,  0.100187 , 0.100155 ,  0.100103 ,
0.100030 ,  0.099936 , 0.099822  , 0.099687 ,  0.099531 ,  0.099355 ,
0.099158 ,  0.098942},
   {0.099355 ,  0.099531 ,  0.099687  , 0.099822 ,  0.099936 , 0.100030 ,
0.100103 , 0.100155 ,  0.100187 ,  0.100197 , 0.100187 ,  0.100155 ,
0.100103 ,  0.100030 , 0.099936  , 0.099822 ,  0.099687 ,  0.099531 ,
0.099355 ,  0.099158},
   {0.099158 ,  0.099355 ,  0.099531  , 0.099687 ,  0.099822 , 0.099936 ,
0.100030 , 0.100103 ,  0.100155 ,  0.100187 , 0.100197 ,  0.100187 ,
0.100155 ,  0.100103 , 0.100030  , 0.099936 ,  0.099822 ,  0.099687 ,
0.099531 ,  0.099355},
   {0.098942 ,  0.099158 ,  0.099355  , 0.099531 ,  0.099687 , 0.099822 ,
0.099936 , 0.100030 ,  0.100103 ,  0.100155 , 0.100187 ,  0.100197 ,
0.100187 ,  0.100155 , 0.100103  , 0.100030 ,  0.099936 ,  0.099822 ,
0.099687 ,  0.099531},
   {0.098705 ,  0.098942 ,  0.099158  , 0.099355 ,  0.099531 , 0.099687 ,
0.099822 , 0.099936 ,  0.100030 ,  0.100103 , 0.100155 ,  0.100187 ,
0.100197 ,  0.100187 , 0.100155  , 0.100103 ,  0.100030 ,  0.099936 ,
0.099822 ,  0.099687},
   {0.098448 ,  0.098705 ,  0.098942  , 0.099158 ,  0.099355 , 0.099531 ,
0.099687 , 0.099822 ,  0.099936 ,  0.100030 , 0.100103 ,  0.100155 ,
0.100187 ,  0.100197 , 0.100187  , 0.100155 ,  0.100103 ,  0.100030 ,
0.099936 ,  0.099822},
   {0.098171 ,  0.098448 ,  0.098705  , 0.098942 ,  0.099158 , 0.099355 ,
0.099531 , 0.099687 ,  0.099822 ,  0.099936 , 0.100030 ,  0.100103 ,
0.100155 ,  0.100187 , 0.100197  , 0.100187 ,  0.100155 ,  0.100103 ,
0.100030 ,  0.099936},
   {0.097875 ,  0.098171 ,  0.098448  , 0.098705 ,  0.098942 , 0.099158 ,
0.099355 , 0.099531 ,  0.099687 ,  0.099822 , 0.099936 ,  0.100030 ,
0.100103 ,  0.100155 , 0.100187  , 0.100197 ,  0.100187 ,  0.100155 ,
0.100103 ,  0.100030},
   {0.097559 ,  0.097875 ,  0.098171  , 0.098448 ,  0.098705 , 0.098942 ,
0.099158 , 0.099355 ,  0.099531 ,  0.099687 , 0.099822 ,  0.099936 ,
0.100030 ,  0.100103 , 0.100155  , 0.100187 ,  0.100197 ,  0.100187 ,
0.100155 ,  0.100103},
   {0.097224 ,  0.097559 ,  0.097875  , 0.098171 ,  0.098448 , 0.098705 ,
0.098942 , 0.099158 ,  0.099355 ,  0.099531 , 0.099687 ,  0.099822 ,
0.099936 ,  0.100030 , 0.100103  , 0.100155 ,  0.100187 ,  0.100197 ,
0.100187 ,  0.100155},
   {0.096870 ,  0.097224 ,  0.097559  , 0.097875 ,  0.098171 , 0.098448 ,
0.098705 , 0.098942 ,  0.099158 ,  0.099355 , 0.099531 ,  0.099687 ,
0.099822 ,  0.099936 , 0.100030  , 0.100103 ,  0.100155 ,  0.100187 ,
0.100197 ,  0.100187},
   {0.096496 ,  0.096870 ,  0.097224  , 0.097559 ,  0.097875 , 0.098171 ,
0.098448 , 0.098705 ,  0.098942 ,  0.099158 , 0.099355 ,  0.099531 ,
0.099687 ,  0.099822 , 0.099936  , 0.100030 ,  0.100103 ,  0.100155 ,
0.100187 ,  0.100197}};



--
View this message in context: http://octave.1599824.n4.nabble.com/Octave-C-matrix-Inv-comparison-tp4655291p4655512.html
Sent from the Octave - Maintainers mailing list archive at Nabble.com.

Sorry for continuing this on the maintainer's list but I don't know how to move it to the help list.
Jeff are you aware of how data is stored in fortran and how it differs from C? the lapack routines
expect a matrix to be stored colum-major: (1,1), (2,1), (3,1), etc. Your C array is maybe stored
transposed (I don't know what else you do to R21 before calling lapack). This would explain
the differences you see. Also, have you multiplied the result by the original matrix to verify
it produces the identity?

--
Ed Meyer

reply via email to

[Prev in Thread] Current Thread [Next in Thread]