| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337 |
- <?php
- namespace MathPHP\LinearAlgebra;
- use MathPHP\Number\ObjectArithmetic;
- /**
- * @template T
- */
- class MatrixCatalog
- {
- /** @var Matrix<T> transpose */
- private $Aᵀ;
- /** @var Matrix<T> inverse */
- private $A⁻¹;
- /** @var Reduction\RowEchelonForm */
- private $REF;
- /** @var Reduction\ReducedRowEchelonForm */
- private $RREF;
- /** @var Decomposition\LU */
- private $LU;
- /** @var Decomposition\QR */
- private $QR;
- /** @var Decomposition\Cholesky */
- private $cholesky;
- /** @var Decomposition\Crout */
- private $crout;
- /** @var Decomposition\SVD */
- private $SVD;
- /** @var int|float|ObjectArithmetic determinant */
- private $det;
- /**************************************************************************
- * DERIVED MATRICES
- * - transpose
- * - inverse
- **************************************************************************/
- // TRANSPOSE
- /**
- * @param Matrix<T> $Aᵀ
- */
- public function addTranspose(Matrix $Aᵀ): void
- {
- $this->Aᵀ = $Aᵀ;
- }
- /**
- * @return bool
- */
- public function hasTranspose(): bool
- {
- // @phpstan-ignore-next-line
- return isset($this->Aᵀ);
- }
- /**
- * @return Matrix<T>
- */
- public function getTranspose(): Matrix
- {
- return $this->Aᵀ;
- }
- // INVERSE
- /**
- * @param Matrix<T> $A⁻¹
- */
- public function addInverse(Matrix $A⁻¹): void
- {
- $this->A⁻¹ = $A⁻¹;
- }
- /**
- * @return bool
- */
- public function hasInverse(): bool
- {
- // @phpstan-ignore-next-line
- return isset($this->A⁻¹);
- }
- /**
- * @return Matrix<T>
- */
- public function getInverse(): Matrix
- {
- return $this->A⁻¹;
- }
- /**************************************************************************
- * MATRIX REDUCTIONS
- * - ref (row echelon form)
- * - rref (reduced row echelon form)
- **************************************************************************/
- // ROW ECHELON FORM
- /**
- * @param Reduction\RowEchelonForm $REF
- */
- public function addRowEchelonForm(Reduction\RowEchelonForm $REF): void
- {
- $this->REF = $REF;
- }
- /**
- * @return bool
- */
- public function hasRowEchelonForm(): bool
- {
- // @phpstan-ignore-next-line
- return isset($this->REF);
- }
- /**
- * @return Reduction\RowEchelonForm
- */
- public function getRowEchelonForm(): Reduction\RowEchelonForm
- {
- return $this->REF;
- }
- // REDUCED ROW ECHELON FORM
- /**
- * @param Reduction\ReducedRowEchelonForm $RREF
- */
- public function addReducedRowEchelonForm(Reduction\ReducedRowEchelonForm $RREF): void
- {
- $this->RREF = $RREF;
- }
- /**
- * @return bool
- */
- public function hasReducedRowEchelonForm(): bool
- {
- // @phpstan-ignore-next-line
- return isset($this->RREF);
- }
- /**
- * @return Reduction\ReducedRowEchelonForm
- */
- public function getReducedRowEchelonForm(): Reduction\ReducedRowEchelonForm
- {
- return $this->RREF;
- }
- /**************************************************************************
- * MATRIX DECOMPOSITIONS
- * - LU decomposition
- * - QR decomposition
- * - Cholesky decomposition
- * - Crout decomposition
- * - SVD
- **************************************************************************/
- // LU DECOMPOSITION
- /**
- * @param Decomposition\LU $LU
- */
- public function addLuDecomposition(Decomposition\LU $LU): void
- {
- $this->LU = $LU;
- }
- /**
- * @return bool
- */
- public function hasLuDecomposition(): bool
- {
- // @phpstan-ignore-next-line
- return isset($this->LU);
- }
- /**
- * @return Decomposition\LU
- */
- public function getLuDecomposition(): Decomposition\LU
- {
- return $this->LU;
- }
- // QR DECOMPOSITION
- /**
- * @param Decomposition\QR $QR
- */
- public function addQrDecomposition(Decomposition\QR $QR): void
- {
- $this->QR = $QR;
- }
- /**
- * @return bool
- */
- public function hasQrDecomposition(): bool
- {
- // @phpstan-ignore-next-line
- return isset($this->QR);
- }
- /**
- * @return Decomposition\QR
- */
- public function getQrDecomposition(): Decomposition\QR
- {
- return $this->QR;
- }
- // CHOLESKY DECOMPOSITION
- /**
- * @param Decomposition\Cholesky $cholesky
- */
- public function addCholeskyDecomposition(Decomposition\Cholesky $cholesky): void
- {
- $this->cholesky = $cholesky;
- }
- /**
- * @return bool
- */
- public function hasCholeskyDecomposition(): bool
- {
- // @phpstan-ignore-next-line
- return isset($this->cholesky);
- }
- /**
- * @return Decomposition\Cholesky
- */
- public function getCholeskyDecomposition(): Decomposition\Cholesky
- {
- return $this->cholesky;
- }
- // CROUT DECOMPOSITION
- /**
- * @param Decomposition\Crout $crout
- */
- public function addCroutDecomposition(Decomposition\Crout $crout): void
- {
- $this->crout = $crout;
- }
- /**
- * @return bool
- */
- public function hasCroutDecomposition(): bool
- {
- // @phpstan-ignore-next-line
- return isset($this->crout);
- }
- /**
- * @return Decomposition\Crout
- */
- public function getCroutDecomposition(): Decomposition\Crout
- {
- return $this->crout;
- }
- // SVD
- /**
- * @param Decomposition\SVD $SVD
- */
- public function addSVD(Decomposition\SVD $SVD): void
- {
- $this->SVD = $SVD;
- }
- /**
- * @return bool
- */
- public function hasSVD(): bool
- {
- // @phpstan-ignore-next-line
- return isset($this->SVD);
- }
- /**
- * @return Decomposition\SVD
- */
- public function getSVD(): Decomposition\SVD
- {
- return $this->SVD;
- }
- /**************************************************************************
- * DERIVED DATA
- * - determinant
- **************************************************************************/
- // DETERMINANT
- /**
- * @param int|float|ObjectArithmetic $det
- */
- public function addDeterminant($det): void
- {
- $this->det = $det;
- }
- /**
- * @return bool
- */
- public function hasDeterminant(): bool
- {
- // @phpstan-ignore-next-line
- return isset($this->det);
- }
- /**
- * @return int|float|ObjectArithmetic
- */
- public function getDeterminant()
- {
- return $this->det;
- }
- }
|