[PLUG] perl question, Math::Matrix stuff
Dave
dave at dhdo.org
Fri May 5 18:49:36 UTC 2006
Here's what I found after a bit of digging:
- Math Matrix is bad perl mojo, as it doesn't let you get at the innards well
if you want to.
- It stores each row and column in an array, internally, which you can access.
Example code:
use Math::Matrix;
my $a = new Math::Matrix( [1, 2, 3], [4, 5, 6], [7, 8, 9] );
foreach my $col ( 0..2 ) {
foreach my $row ( 0..2 ) {
print ${$a->[$col]}[$row];
}
}
Output:
123456789
You can probably get away with not using hardcoded numbers in the above
for(each) loops by using the $#array bit (last index of the array).
Overall, I rate this: "dirty hack"
On Friday 05 May 2006 10:53, Russell Senior wrote:
> Last night at the Lucky Lab, Eric Wilhelm helpfully suggested
> Math::Matrix for a little linear algebra problem I have. Works great,
> but I have one remaining problem. I want to concatenate the "solution
> vector" to another array so that I can print/manipulate it. I seem to
> be doing something ignorant and the solution vector is getting added
> to the array as an object. E.g.:
>
> $a = new Math::Matrix ([ 1, 0, 0 ]
> [ 0, 1, 0 ]
> [ 0, 0, 1 ]);
> $x = new Math::Matrix ([ 1, 2, 3 ]);
> $E = $a->concat($x->transpose);
> $s = $E->solve;
>
> @output = ($subject,$s->transpose);
> print OUTPUT join(",", at output);
>
> is resulting (annoyingly), as something like:
>
> 001, 1.0 2.0 3.0
>
> but:
>
> a) I want commas, dammit!
>
> and
>
> b) I actually want to reformat the values a bit too.
>
> The manual for Math::Matrix doesn't say how to convert from the
> supernifty Matrix object to a plain jane array that I want.
>
> I never had this problem in Awk.
>
> I need a giant box labelled "*2000 LBS OF CLUE*" dropped on my head.
--
-Dave
More information about the PLUG
mailing list