pascal

Pascal matrix built from binomial coefficients.

Category: Mathematics > Elementary Math

Syntax

P = pascal(n)

Returns the symmetric n-by-n Pascal matrix.

P = pascal(n, 1)

Returns the lower-triangular Cholesky factor, with signs alternating down the columns.

P = pascal(n, 2)

Returns a transposed and permuted version of pascal(n, 1); for n = 3 it is a cube root of the identity.

Description

The symmetric matrix holds Pascal's triangle along its anti-diagonals. Its Cholesky factorization is the matrix pascal(n, 1), which is why pascal(n, 1)*pascal(n, 1)' reproduces pascal(n). Its determinant is always 1, and it becomes increasingly ill conditioned as n grows.

Input arguments

n
Order of the matrix.
k
Optional 0 (default), 1 or 2, selecting the variant.

Output arguments

P
Integer matrix. In the default form P(i, j) = nchoosek(i+j-2, j-1).

Example

Symmetric matrix and its Cholesky factor

P = pascal(4)
L = pascal(4, 1)
L * L'
Output
P = 4×4

     1     1     1     1
     1     2     3     4
     1     3     6    10
     1     4    10    20
L = 4×4

     1     0     0     0
     1    -1     0     0
     1    -2     1     0
     1    -3     3    -1
ans = 4×4

     1     1     1     1
     1     2     3     4
     1     3     6    10
     1     4    10    20

See also

nchoosek hilb magic chol gallery