You matrix is not invertible which is why the first
answer comes out funny.  The matrix inverse routine
does not do checking for condition numbers, etc
before it calculates the inverse.  If you print the
determinant you'll see it is very small (i.e. floating
point zero within round-off).

The reason your cut and paste "check" worked
is because you only included the top several places
from the sprint of the numbers which is enough to
make the determinant farther from 0 and the matrix
then invertible.  It is not actually inverting the
same matrix....

--Chris

On Fri, Jun 10, 2011 at 5:54 AM, Stéphane Lévy <[email protected]> wrote:
> Hello,
> I have found unexpected, astonishing results using the PDL matrix inv()
> function by 2 different ways.
> In the first way I manipulate PDL objects all the way, in the second way I
> recreate objects by pasting values of the original PDL object into a new PDL
> object.
> First way gives unexpected, wrong result, second way leads to accurate
> result. I do not understand this and it worries me a bit as I am supposed to
> use intensively PDL matrix functions.
> Anybody can give me an explanation of this, and tell me what I should do
> differently when I manipulate objects?
> Here is what I did :
>
> # step 1A : creating a (2,2) matrix
> Perl> my $m = random(2,2)
> $PDL1 =
> [
> [0.65707276 0.12124598]
> [0.95303134 0.43850649]
> ]
> ;
>
> # step 1B : computing cov table of the matrix
> Perl> my $c = $m->cov_table()
> $PDL1 =
> [
> [0.071777584 0.068924048]
> [0.068924048 0.066183954]
> ]
> ;
>
> # step 1C : testing if the the matrix multiplied by its inverse is equal to
> identity matrix
> Perl> $c x inv($c)
> $PDL1 =
> [
> [ 1 0]
> [-0.125 1.125]
> ]
> ;
> # we observe that step 1C leads to unexpected result
>
> # step 2A : pasting the content of PDL obtained in step 1B to a new PDL
> object : the 2 PDL objects are supposedly perfectly identical
> Perl> $m = pdl([0.071777584,0.068924048],[0.068924048,0.066183954])
> $PDL1 =
> [
> [0.071777584 0.068924048]
> [0.068924048 0.066183954]
> ]
> ;
>
> # step 2B : same as step 1C, testing if the the matrix multiplied by its
> inverse is equal to identity matrix
> Perl> $m x $m->inv()
> $PDL1 =
> [
> [1 0]
> [0 1]
> ]
> ;
> # we observe that step 2B leads to expected result
>
> Thank you.
> Best regards.
> Stéphane
>
>
> _______________________________________________
> Perldl mailing list
> [email protected]
> http://mailman.jach.hawaii.edu/mailman/listinfo/perldl
>
>

_______________________________________________
Perldl mailing list
[email protected]
http://mailman.jach.hawaii.edu/mailman/listinfo/perldl

Reply via email to