![]() ''' x,numIter,omega = gaussSeidel(iterEqs,x,tol = 1.0e-9) Gauss-Seidel method for solving ('omega' is the relaxation factor).įrom numpy import dot from math import sqrt def gaussSeidel(iterEqs,x,tol = 1.0e-9): omega = 1.0 k = 10 p = 1įor i in range(1,501): xOld = x.copy() x = iterEqs(x,omega) dx = sqrt(dot(x-xOld,x-xOld)) if dx < tol: return x,i,omega # Compute of relaxation factor after k+p iterations if i = k: dx1 = dx if i = k + p: dx2 = dx omega = 2.0/(1.0 + sqrt(1.0 - (dx2/dx1)**(1. The function gaussSeidel returns the solution vector x, the number of iterations carried out, and the value of ffi>opt used. In Gauss Seidel method, we first arrange given system of linear equations in diagonally dominant form. The user must provide the function iterEqs that computes the improved x from the iterative formulas in Eq. This program implements Gauss Seidel Iteration Method for solving systems of linear equation in python programming language. The function gaussSeidel is an implementation of the Gauss-Seidel method with relaxation.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |