fix tests

This commit is contained in:
Dennis Eichhorn 2023-10-22 15:21:12 +00:00
parent 7a086fea93
commit 8b3daf3c8d
2 changed files with 26 additions and 4 deletions

View File

@ -884,10 +884,16 @@ class Matrix implements \ArrayAccess, \Iterator
}
return $matrix;
} else {
// @todo: implement
throw new \Exception('Not yet implemented');
}
$eig = new EigenvalueDecomposition($this);
$d = $eig->getD();
for ($i = 0; $d->getM(); ++$i) {
$d->matrix[$i][$i] = \pow($d->matrix[$i][$i], $exponent);
}
return $eig->getV()->mult($d)->mult($eig->getV()->inverse());
}
/**

View File

@ -646,9 +646,25 @@ final class MatrixTest extends \PHPUnit\Framework\TestCase
[80.25, 96.75, 113.25],
[120.75, 146.25, 171.75],
],
$m->pow(2.5)->toArray(),
$m->pow(2)->toArray(),
0.1
);
$m = Matrix::fromArray([
[1, 1, 1],
[1, 2, 3],
[1, 3, 6],
]);
self::assertEqualsWithDelta(
[
[0.8901, 0.5882, 0.3684],
[0.5882, 1.2035, 1.3799],
[0.3684, 1.3799, 3.1167],
],
$m->pow(2 / 3)->toArray(),
0.01
);
}
public function testExp() : void