Question: Write the modified version of the function solve by back substitution that accepts a matrix u in row echelon form and a right-hand-side vector b

Write the modified version of the function solve by back substitution that accepts a matrix u in row echelon form and a right-hand-side vector b and returns as output:

- None, if the system has no solution (Hint: This can be determined simply by checking whether the right-hand-side vector has a non-zero entry in any of the all-zero rows of the matrix)

- A solution where all entries corresponding to free variables are 0 (Hint: All other values are then uniquely determined).

example:

>>> u = [[1, 1, 0, 1, 1],

... [0, 0, 1, 0, 1],

... [0, 0, 0, 0, 1],

... [0, 0, 0, 0, 0],

... [0, 0, 0, 0, 0]]

>>> b = [2, 2, 1, 0, 0]

>>> solve_by_back_substitution(u, b)

[1.0, 0.0, 1.0, 0.0, 1.0]

code to be modified:

def solve_by_back_sub(u,b):

n = len(b)

x = n*[0]

for i in range(n-1, -1, -1):

s = sum(x[j] * u[i][j] for j in range(n-1, i, -1))

x[i] = (b[i] - s)/u[i][i]

return x

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!