Question
Numpy and Python. a) Implement back substitution in Python, using Numpy. Use simple numpy function, f.ex. numpy.dot. Solve for Rx = b, where R =
Numpy and Python.
a) Implement back substitution in Python, using Numpy. Use simple numpy function, f.ex. numpy.dot. Solve for Rx = b, where R = numpy.array([[1,4,1], [0,6,4], [0,0,2]]) is the upper triangle matrix and b = numpy.array([3,2,1]) is the lower triangle matrix.
Use the following code:
def backsub(R,b): """ back substitution input: n x n upper triangle matrix R (treated as a normal matrix) n-vector b output: The solution x for Rx=b """ n=R.shape[0] x=np.zeros(n) # enter code here # ... return x
b) Implement an algorithm that solves the linear square simultaneous equation Ax = b with QR decomposition and back substitution. Use the following code and the qr and backsub functions from a), as well as Numpy. Solve the simulataneous equation Ax = b, with A = numpy.array([1,2,-1],[-1,1,1],[1,-4,1]]) and b = numpy.array([1,2,3]) with your code.
Begin with this code:
def linsolve(A,b): """ Solves Ax=b""" # enter code here # ... return x
Algorithm 11.1 BACK SUBSTITUTION given an n x n upper triangular matrix R with nonzero diagonal entries, and an n-vector b. Fori,1Step 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