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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started