def generate_degradation_matrix(p, h_max):
    """
    Generate an upper triangular degradation transition matrix.


    Parameters
    ----------
    p : float
        The probability of degrading by one unit at each time step.
    h_max : int
        The index of the failed state.


    Returns
    -------
    list of lists
        A ``(h_max + 1)`` :math:`\\times` ``(h_max + 1)`` degradation transition matrix.

    """
    degradation_matrix = []
    for h in range(h_max):
        transitions = [0] * (h_max + 1)
        transitions[h] = 1 - p
        transitions[h+1] = p
        degradation_matrix.append(transitions)
    degradation_matrix.append([0]*h_max + [1])
    return degradation_matrix