Skip to contents

stm_pascal() generates Pascal's Triangle up to the n-th row and returns the triangle matrix along with the coefficients in the last row.

Usage

stm_pascal(n)

Arguments

n

The number of rows to generate in Pascal's Triangle. Must be a positive integer.

Value

A list containing:

y

A matrix representing Pascal's Triangle.

coefs

A vector of the coefficients in the last row of the triangle.

Examples

stm_pascal(3)
#> $y
#>      [,1] [,2] [,3]
#> [1,]    1    1    1
#> [2,]    1    2    3
#> [3,]    1    3    6
#> 
#> $coefs
#> [1] 1 3 6 3 1
#> 
stm_pascal(5)
#> $y
#>      [,1] [,2] [,3] [,4] [,5]
#> [1,]    1    1    1    1    1
#> [2,]    1    2    3    4    5
#> [3,]    1    3    6   10   15
#> [4,]    1    4   10   20   35
#> [5,]    1    5   15   35   70
#> 
#> $coefs
#> [1]  1  5 15 35 70 35 15  5  1
#>