Construct a 2-D 10 10 ∗ matrix with the following constraints:
• The element at [0,0] should be 1
• The element at [0,9] should be 100
• The element at [9,0]should be 50
• The interval between elements in rows should be constant
• The interval between elements in columns should be constant
mat = [[0]*10 for i in range(10)]
x_00 = 1 # [0, 0]
x_09 = 100 # [0, 9]
x_90 = 50 # [9, 0]
x_99 = 100 # [9, 9]
for row in range(10):
mat[row][0] = x_00 + row*(x_90 - x_00) / 9
mat[row][9] = x_09 + row*(x_99 - x_09) / 9
for col in range(9):
mat[row][col] = mat[row][0] + col * (mat[row][9] - mat[row][0]) / 9
for row in range(10):
for col in range(10):
print("{:5.2f}".format(mat[row][col]), end= ' ')
print()
Comments
Leave a comment