math4610

Routine Name: UpperTriangleMatrix

Author: David Merkley

Language: Python

Description/Purpose: Creates a matrix in upper triangular form in a stair pattern

Input: n of n x n matrix

Output: Matrix of definition above

Implementation/Code:

def UpperTriangle(n):
    return [[i + j - 1 if j >= i else 0 for j in range(1, n + 1)] for i in range(1, n + 1)]