MathPHP\LinearAlgebra\Matrix::columnInterchange PHP Method

columnInterchange() public method

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