Question: Python program You are writing a program to solve the linear system Ax = b , where A is a square matrix, b is a

Python program

You are writing a program to solve the linear system Ax = b, where A is a square matrix, b is a column vector, and x is the solution vector. You decide to check the solution by computing the norm (Euclidean) of the vector A x - b. The main program is shown below, but the function for checking the solution is missing. You are asked to complete it by writing the missing function. Put ONLY the code for the function in your answer file.

#! /usr/bin/python3 import numpy as np from numpy import linalg as LA ############################################################## # In your answer file write the full code for the function # that computes |A x - b|, the norm of the difference between the # left side and right side of the equation. # Your function should return the value of the norm. # The function should go in the space below and work with the # calling program. # Please do not change the calling program or the import statements. ############################################################## # (Your code is intended to go in this space) ############################################################## def main(): # Read the matrix and vector from files A = np.loadtxt('A.txt') b = np.loadtxt('b.txt') # Solve the linear system x = LA.solve(A,b) # Call the function to compute |Ax - b| d = check(A,x,b) print("The solution to Ax = b is", x) print("The norm |Ax-b| is", d) ############################################################## main()

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 Databases Questions!