in reply to Dot product of three matrices
Obviously the logic is the same, but using vectors is much clearer code-wise and mathematically.my @vector1 = ( 2, -4, 2 ); my @vector2 = ( 5, -3, -6);
return unless $ct1 && $ct1 == $ct2 && $ct2 == $ct3;
Another:my $sum = 0; foreach my $i ( 0 .. $#$x ){ $sum += $x->[$i] * $y->[$i] * $z->[$i]; } return $sum;
my $sum = 0; $sum += $x->[$_] * $y->[$_] * $z->[$_] for 0 .. $#$x; return $sum;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Dot product of three matrices (wheels)
by tye (Sage) on Aug 01, 2005 at 17:42 UTC |