olzfinda.blogg.se

Gauss seidel implmentation python
Gauss seidel implmentation python







The available linear algebra backend formats change from version to version, breaking old code. The particular details of matrix storage and matrix elements are considered an implementation detail that only developers should be concerned with. As far as I can tell this is a design decision, as they are trying to create an all-encompassing closed pipeline for discretizing and solving PDES. Otherwise, with this particular algorithm implementation it is safe to leave it out if you don't care about the output.FEniCS tends to hide the details about the actual matrices it builds, and prevent easy manipulation of them. So, if you want to see the "progress inside" without confusion on data that will be overwritten, you should zero it out. at the other while iterations x1 entries would contain previous (not yet overwritten) values.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):

gauss seidel implmentation python

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. In the following code for the Gauss Seidel method, I enter one given matrix A.









Gauss seidel implmentation python