casualolz.blogg.se

Implementing gauss seidel 2d method python
Implementing gauss seidel 2d method python









implementing gauss seidel 2d method python

at the first while iteration, x1 entries contain garbage, so the first print output will have a correct entry of x1 and garbage for x1.So, if you don't zero out x1 before the for-loop: The print expression is inside the for-loop, while the entries of x1 are updated one by one. Notice, that in the following piece of code: x1 = np.zeros(n) However, I think I see the source of confusion. I am not entirely sure what are you trying to achieve and why do you want to AVOID zeroing out x1 if you care about what is being printed. Iter.=3 duration=0.156000 err=3.409068e-05Įven if I don't assing zeros to x1 in each cycle, the solution are computed correctly. Unwanted output if I comment x1 = np.zeros(n) at the beginning of while : begin while with k = 0 Wanted output: - As you can see x0 contains the x1 of of the previous while iteration begin while with k = 0 Print('Iter.=%d duration=%f err=%e' % (k,duration,err)) Print('Not converges in %d iterations' % Kmax) This is the code, you can see the wanted and unwanted output below: def GaussSeidel(A,b): The result seems to be correct, but when I comment the vector x1 at the beginning of the while, I obtain an unwanted result:įor example, before the assignment x0=x1, when k=1, x0 is equal to x1 instead x0 when k=1, would be equal to x1 when k=0.Ĭonsequently, the norm(x1-x0) is always 0, after the first while.

implementing gauss seidel 2d method python

In the following code for the Gauss Seidel method, I enter one given matrix A.











Implementing gauss seidel 2d method python