math4610

Routine Name: generateSquareRandomSymmetricDiagonallyDominant

Author: David Merkley

Language: Python

Description/Purpose: Generates a square matrix that is diagonallyDominant

Input: the size

Output: the matrix

Implementation/Code:

def generateSquareRandomSymmetricDiagonallyDominant(n):
    A = [[0]*n for i in range(n)]
    for i in range(n):
        A[i][i] = n
        for j in range(i + 1, n):
            A[i][j] = random.random()
        for j in range(i):
            A[i][j] = A[j][i]
    return A