RowVector.php 970 Bytes
Newer Older
冯超鹏's avatar
冯超鹏 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
<?php
namespace MathPHP\LinearAlgebra;

/**
 * Row vector (row matrix)
 * 1 × n matrix consisting of a single row of n elements.
 *
 * x = [x₁ x₂ ⋯ xn]
 */
class RowVector extends Matrix
{
    /**
     * Allows the creation of a RowVector (1 × n Matrix) from an array
     * instead of an array of arrays.
     *
     * @param array $N 1-dimensional array of vector values
     */
    public function __construct(array $N)
    {
        $this->m = 1;
        $this->n = count($N);

        $A       = [$N];
        $this->A = $A;
    }

    /**
     * Transpose
     * The transpose of a row vector is a column vector
     *
     *                 [x₁]
     * [x₁ x₂ ⋯ xn]ᵀ = [x₂]
     *                 [⋮ ]
     *                 [xn]
     *
     * @return ColumnVector
     *
     * @throws \MathPHP\Exception\MatrixException
     */
    public function transpose(): ColumnVector
    {
        return new ColumnVector($this->getRow(0));
    }
}