Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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.

image text in transcribedimage text in transcribedimage text in transcribed
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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions