public function eig(bool $normalize = true) : array
    {
        if (!$this->isSquare()) {
            throw new RuntimeException('Cannot decompose a non'
                . ' square matrix.');
        }

        $jama = new JAMA($this->a);

        $decomp = $jama->eig();

        $eigenvalues = $decomp->getRealEigenvalues();
        $eigenvectors = $decomp->getV()->getArray();

        $eigenvectors = self::quick($eigenvectors)
            ->transpose();

        if ($normalize === true) {
            $norm = $eigenvectors->transpose()
                ->square()
                ->sum()
                ->sqrt()
                ->transpose();
        
            $eigenvectors = $eigenvectors->divide($norm);
        }

        return [$eigenvalues, $eigenvectors];
    }
public function eig(bool $normalize = true) : array
    {
        if (!$this->isSquare()) {
            throw new RuntimeException('Cannot decompose a non'
                . ' square matrix.');
        }

        $jama = new JAMA($this->a);

        $decomp = $jama->eig();

        $eigenvalues = $decomp->getRealEigenvalues();
        $eigenvectors = $decomp->getV()->getArray();

        $eigenvectors = self::quick($eigenvectors)
            ->transpose();

        if ($normalize === true) {
            $norm = $eigenvectors->transpose()
                ->square()
                ->sum()
                ->sqrt()
                ->transpose();
        
            $eigenvectors = $eigenvectors->divide($norm);
        }

        return [$eigenvalues, $eigenvectors];
    }
public function eig ( bool $ normalize = true ) : array { if ( ! $ this -> isSquare ( ) ) { throw new RuntimeException ( 'Cannot decompose a non' . ' square matrix.' ) ; } $ jama = new JAMA ( $ this -> a ) ; $ decomp = $ jama -> eig ( ) ; $ eigenvalues = $ decomp -> getRealEigenvalues ( ) ; $ eigenvectors = $ decomp -> getV ( ) -> getArray ( ) ; $ eigenvectors = self :: quick ( $ eigenvectors ) -> transpose ( ) ; if ( $ normalize === true ) { $ norm = $ eigenvectors -> transpose ( ) -> square ( ) -> sum ( ) -> sqrt ( ) -> transpose ( ) ; $ eigenvectors = $ eigenvectors -> divide ( $ norm ) ; } return [ $ eigenvalues , $ eigenvectors ] ; }
Compute the eigenvalues and eigenvectors of the matrix and return
them in a tuple.

@param bool $normalize
@throws \RuntimeException
@return array
Compute the eigenvalues and eigenvectors of the matrix and return them in a tuple .