Question: I have provided a Pythong'NumPy implementation of a Gauss-Seidel iteration solver in the course notes. Convert this script to the objectoriented class rnembertunction gauss_seidel_solve below.



I have provided a Pythong'NumPy implementation of a Gauss-Seidel iteration solver in the course notes. Convert this script to the objectoriented class rnembertunction gauss_seidel_solve below. Add a row swapping strategy such that the iteration will work if there is a 0 entry on the diagonal of the A matrix. I am provided 3 Matrix class denition that has been extended from the one you implemented in assignment'l2. This class is instantiated as the class attribute objects A and and allows for indexing operations similar to Python lists and NumPy arrays as well as the row operation functions Please use this class and it's member functions to implement your functions when appropriate. class IterativeSolver () : def _init__(self, A, b): self.n = A. shape[0] #Instantiate A as a #Matrix object and store it #as class attribute. self.A = Matrix(A) self.b = np. array (b, dtype=np. double) return def gauss_seidel_solve(self, tolerance=le-10, max_iterations=10000): X = np . zeros_like (self.b, dtype=np. double) return ximport numpy as np class Matrix(object) : def _init__(self, array): if not isinstance(array, (list, np. ndarray) ): raise TypeError (' Input matrix must be a Python list or NumPy ndarray. ' ) else: self. mat = np. array (array, dtype=np . double) def _str_(self) : return str (self.mat) def _call__(self): return self. mat def _getitem__(self, key): return self. mat [key ] def _setitem__(self, key, value): self . mat [key] = value def row_swap (self, i, j): temp_row = self.mat[j] . copy () self. mat[j] = self.mat[i] self . mat[i] = temp_row return def row_multiply (self, i, factor): self. mat[i] *= factor return def row_combine (self, i, j, factor): self . mat[i] -= factor * self.mat[j] return
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
