Hi Fellow Monks and Monkettes
I have hit on a very frustrating problem. I have been working with PDL for a while now. I have been 'translating' matlab commands to PDL code, for something I have to do at work (and yes I know matlab can create a executable if one has the right add-on but I don't and in any case, it's not appropriate for my needs).
Anyway .. I am trying to do a matrix multiplication which worls fine in matab but not in PDL.
Matlab command is below
X = A x B x C x D
Where A is 35 columns by 71 rows, B is 7 columns by 35 rows, C is 35 columns by 35 rows and D is 7 columns by 35 rows. In matlab it works. In PDL it does not. I get the following error:
Error in inner:Wrong dims
Program code follows
use PDL; use PDL::Matrix; $file1 = $ARGV[0]; $file2 = $ARGV[1]; open(DATA1, "$file1") || die "Error: Unable to open $file1:$!\n"; open(DATA2, "$file2") || die "Error: Unable to open $file2:$!\n"; my $fileone; my $filetwo; while ( <DATA1> ) { chomp; #my @l = split /,\s+/; my @line1 = split(/,/); # for loop for($i = 0; $i < 35; $i++) { push @{$fileone->[$i]}, $line1[$i]; } } $fileone = PDL::Matrix->pdl($fileone); while ( <DATA2> ) { chomp; my @line2 = split (/,/); for($j = 0; $j < 35; $j++) { push @{$filetwo->[$j]}, $line2[$j]; } } $filetwo = PDL::Matrix->pdl($filetwo); $m = $fileone->transpose(); ($V, $S, $U) = svd($m); @valuesS = list $S; $SqS = stretcher($S); $Vs = $V->slice('0:7,0:34'); $Ut = $U->transpose(); $Ss = $SqS->slice('0:7,0:7'); $Us = $Ut->slice('0:70,0:7'); $A = $Us x $Ss x $Vs; ($Uf, $Sf, $Vf) = svd($sec); $B = $Vf->transpose(); @valuesSf = list $Sf; $SqSf = stretcher($Sf); $shortS = $SqSf->slice('0:6,0:6'); $invSf = $shortS->inv(); my $zeros = zeroes(28,7); $invSftransposed=transpose($invSf); $C = $invSftransposed->append($zeros); $C=transpose($C); $D = $Uf->slice('0:6,0:6'); # PDL coughs at the next command. $x = A x B x C x D;
Any help/suggestions much appreciated.

In reply to Why dies this work in matlab and not PDL? by Angharad

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.