Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I have a python code for LU decomposition. I need to interpret what each line of code does. def ludecomposition(A, n): # Create zero matrices

I have a python code for LU decomposition. I need to interpret what each line of code does.

def ludecomposition(A, n):

# Create zero matrices for L and U # n equals total number of rows/columns

lower = [[0 for x in range(n)] for y in range(n)]

upper = [[0 for x in range(n)] for y in range(n)]

for i in range(n): for k in range(i, n): sum = 0 for j in range(i): sum += (lower[i][j] * upper[j][k])

upper[i][k] = A[i][k] - sum

# Lower Triangular for k in range(i, n): if (i == k): # Set Diagonal to 1 lower[i][i] = 1 else:

# Summation of L(k, j) * U(j, i) sum = 0; for j in range(i): sum += (lower[k][j] * upper[j][i])

# Evaluating L(k, i) lower[k][i] = int((A[k][i] - sum) /upper[i][i])

# Display titles for matrix print("Lower Triangular\t\t\t\tUpper Triangular")

# Displaying the result : for i in range(n):

# Lower for j in range(n): print(lower[i][j], end = "\t") print("------------", end = "\t\t")

# Upper for j in range(n): print(upper[i][j], end = "\t") print("")

# Input Matrix A A = [[2, -1, 6], [-4, 5, -3], [8, 11, 67]]

ludecomposition(A, 3)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Visual C# And Databases

Authors: Philip Conrod, Lou Tylee

16th Edition

1951077083, 978-1951077082

More Books

Students also viewed these Databases questions