Answer to Question #288551 in Python for Chetan

Question #288551

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

1
Expert's answer
2022-01-18T13:02:52-0500
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()

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS