setMatrix([ [25, 15, -5], [15, 17, 0], [-5, 0, 11], ]); $cholesky = new CholeskyDecomposition($A); self::assertEqualsWithDelta( $A->toArray(), $cholesky->getL() ->mult($cholesky->getL()->transpose()) ->toArray(), 0.2 ); } public function testDecomposition() : void { $A = new Matrix(); $A->setMatrix([ [25, 15, -5], [15, 17, 0], [-5, 0, 11], ]); $cholesky = new CholeskyDecomposition($A); self::assertEqualsWithDelta([ [5, 0, 0], [3, 3, 0], [-1, 1, 3], ], $cholesky->getL()->toArray(), 0.2); self::assertTrue($cholesky->isSpd()); } public function testSolve() : void { $A = new Matrix(); $A->setMatrix([ [25, 15, -5], [15, 17, 0], [-5, 0, 11], ]); $cholesky = new CholeskyDecomposition($A); $vec = new Vector(); $vec->setMatrix([[40], [49], [28]]); self::assertEqualsWithDelta([[1], [2], [3]], $cholesky->solve($vec)->toArray(), 0.2); } public function testInvalidDimension() : void { self::expectException(\phpOMS\Math\Matrix\Exception\InvalidDimensionException::class); $A = new Matrix(); $A->setMatrix([ [25, 15, -5], [15, 17, 0], [-5, 0, 11], ]); $cholesky = new CholeskyDecomposition($A); $vec = new Vector(); $vec->setMatrix([[40], [49]]); $cholesky->solve($vec); } }