Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
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