MathPHP\LinearAlgebra\Matrix::rowInterchange PHP Method

rowInterchange() public method

Row mᵢ changes to position mⱼ Row mⱼ changes to position mᵢ
public rowInterchange ( integer $mᵢ, integer $mⱼ ) : Matrix
$mᵢ integer Row to swap into row position mⱼ
$mⱼ integer Row to swap into row position mᵢ
return Matrix with rows mᵢ and mⱼ interchanged
    public function rowInterchange(int $mᵢ, int $mⱼ) : Matrix
    {
        if ($mᵢ >= $this->m || $mⱼ >= $this->m) {
            throw new Exception\MatrixException('Row to interchange does not exist');
        }
        $m = $this->m;
        $R = [];
        for ($i = 0; $i < $m; $i++) {
            switch ($i) {
                case $mᵢ:
                    $R[$i] = $this->A[$mⱼ];
                    break;
                case $mⱼ:
                    $R[$i] = $this->A[$mᵢ];
                    break;
                default:
                    $R[$i] = $this->A[$i];
            }
        }
        return MatrixFactory::create($R);
    }