154k views
4 votes
write a function that takes any square matrix (n x n) and returns its lower triangular matrix. your goal is to create a function lowert riangularm atrix(matrix) to realize the task. for example, the lower triangular matrix of eqn (2) is given by eqn (3). matrix

User Colby
by
7.6k points

1 Answer

5 votes

Final answer:

To create a function that returns the lower triangular matrix of a given square matrix, you can iterate through each element of the given matrix and set the value to zero if the element's column index is greater than its row index.

Step-by-step explanation:

To create a function that returns the lower triangular matrix of a given square matrix, you can iterate through each element of the given matrix and set the value to zero if the element's column index is greater than its row index. Here's how the function can be implemented in Python:

def lower_triangular_matrix(matrix):
n = len(matrix)
lower_matrix = [[0] * n for _ in range(n)]
for i in range(n):
for j in range(i + 1):
lower_matrix[i][j] = matrix[i][j]
return lower_matrix

For example, if the input matrix is [[1, 2, 3], [4, 5, 6], [7, 8, 9]], the output will be [[1, 0, 0], [4, 5, 0], [7, 8, 9]].

User MAXE
by
9.3k points