setMatrix($this->U); return $matrix; } public function getV() : Matrix { $matrix = new Matrix(); $matrix->setMatrix($this->V); return $matrix; } public function getS() : Matrix { $S = [[]]; for ($i = 0; $i < $this->n; ++$i) { for ($j = 0; $j < $this->n; ++$j) { $S[$i][$j] = 0.0; } $S[$i][$i] = $this->s[$i]; } $matrix = new Matrix(); $matrix->setMatrix($this->V); return $matrix; } public function getSingularValues() : Vector { $vector = new Vector(); $vector->setMatrix($this->S); return $vector; } public function norm2() : float { return $this->S[0]; } public function cond() : float { return $this->S[0] / $this->S[\min($this->m, $this->n) - 1]; } public function rank() : int { $eps = 0.00001; $tol = \max($this->m, $this->n) * $this->S[0] * $eps; $r = 0; $length = \count($this->S); for ($i = 0; $i < $length; ++$i) { if ($this->S[$i] > $tol) { ++$r; } } return $r; } }