Generates a row of Pascal's triangle in 2D
Pascal's triangle in 2D looks like this:
The rows are zero-indexed, therefore, the third row (index=2) would be
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| integer, | intent(in) | :: | N | Row number of pascal's 2D triange (0-indexed) |
||
| real(kind=wp), | intent(in) | :: | x | X-value used in triange |
||
| real(kind=wp), | intent(in) | :: | y | Y-Value used in triange |
Output row of triange
pure function pascal_row_2D(N, x, y) result(row)
!*
! Generates a row of Pascal's triangle in 2D
!
! Pascal's triangle in 2D looks like this:
! \[ [1] \]
! \[ [x,~ y] \]
! \[ [x^2,~ x y,~ y^2] \]
! \[ [x^3,~ x^2y,~ xy^2,~ y^3] \]
! \[ [x^4,~ x^3y,~ x^2y^2,~ xy^3, y^4] \]
! \[ \vdots \]
! \[ [x^N,~ x^{N-1}y,~ \cdots,~ xy^{N-1},~ y^N] \]
!
! The rows are zero-indexed, therefore, the third row (index=2)
! would be \[x^2, x\cdot y, y^2\]
integer, intent(in) :: N !! Row number of pascal's 2D triange (0-indexed)
real(wp), intent(in) :: x !! X-value used in triange
real(wp), intent(in) :: y !! Y-Value used in triange
real(wp), dimension(N+1) :: row !! Output row of triange
integer :: ii
! Produces the elements of an array: [x^N, x^(N-1)*y, x^(N-2)*y^2, ..., y^N]
row = [( x**(N-ii) * y**(ii), ii = 0, N )]
return
end function pascal_row_2D