Example #1
0
        /// <summary>
        /// Create an n x n Toeplitz matrix based on the specified first row and column.
        /// </summary>
        /// <param name="firstRow"></param>
        /// <param name="firstColumn"></param>
        /// <returns></returns>
        public static Matrix Toeplitz(Vector firstRow, Vector firstColumn)
        {
            if (firstRow.Size != firstColumn.Size) {
                throw new IncompatibleMatrixDimensionsException(firstRow, firstColumn);
            }
            if (firstRow[0] != firstColumn[0]) {
                throw new MatrixException("The first indices of the specified vectors don't match!");
            }

            Matrix newMat = new Matrix(firstRow.Size);
            for (int i = 0; i < firstRow.Size; i++) {
                newMat[firstRow.Size - i - 1, Vector.Arrange(firstRow.Size - i - 1, firstRow.Size)] = firstRow.SubMatrix(0, i + 1, 0, 1).ToColumnVector();
            }

            for (int i = 1; i < firstColumn.Size; i++) {
                newMat[i, Vector.Arrange(i)] = firstColumn.SubMatrix(1, i + 1, 0, 1).ToColumnVector();
            }

            return newMat;
        }