diff --git a/Math/Matrix/Matrix.php b/Math/Matrix/Matrix.php index 21c8907f7..402cbb4ae 100755 --- a/Math/Matrix/Matrix.php +++ b/Math/Matrix/Matrix.php @@ -917,15 +917,14 @@ class Matrix implements \ArrayAccess, \Iterator $matrix = $identity; $factorial = 1; - $pow = $matrix; + $pow = clone $matrix; for ($i = 1; $i <= $iterations; ++$i) { $factorial *= $i; $coeff = 1 / $factorial; - $term = $pow->mult($coeff); - $matrix = $matrix->add($term); - $pow = $pow->mult($matrix); // @todo: maybe wrong order? + $term = clone $pow->mult($this); + $matrix = $matrix->add($term->mult($coeff)); } return $matrix; diff --git a/Math/Topology/MetricsND.php b/Math/Topology/MetricsND.php index fd36db66f..aa9b0969f 100755 --- a/Math/Topology/MetricsND.php +++ b/Math/Topology/MetricsND.php @@ -111,8 +111,8 @@ final class MetricsND } $dotProduct = 0; - for ($i = 0; $i < $length; ++$i) { - $dotProduct += $a[$i] * $b[$i]; + foreach ($a as $id => $_) { + $dotProduct += $a[$id] * $b[$id]; } $sumOfSquares = 0;