  C RUBY-ON-RAILS MYSQL ASP.NET DEVELOPMENT RUBY .NET LINUX SQL-SERVER REGEX WINDOWS ALGORITHM ECLIPSE VISUAL-STUDIO STRING SVN PERFORMANCE APACHE-FLEX UNIT-TESTING SECURITY LINQ UNIX MATH EMAIL OOP LANGUAGE-AGNOSTIC VB6 MSBUILD # Gauss Seidel (Specific equation solver) in C  » c » Gauss Seidel (Specific equation solver) in C

By : Deero
Date : November 22 2020, 10:33 AM
it fixes the issue sum should be reinitialized to 0 inside the for-loop before starting the next row and the equation is incorrect. The equation you are using from the python implementation assumes that a[i][i]*x[i] was added to make the full dot-product, they used numpy to get the dot product instead of looping so they had no opportunity to do i != j. Also I'm not sure the equation in that implementation is the Gauss Seidel method, it looks more like Successive Over Relaxation because of the w and (1 - w). Anyway, here is my modified solution. I check for convergence using the error, |Ax - b| < tol for all entries. The for-loop is split into two as a small optimization. a[i][i] * x[i] is added to sum to get the current value for (Ax)i in the error check. code :
``````int converged;
do {
converged = 1;
for (i = 0; i < 9; i++) {
sum = 0;
for (j = 0; j < i; j++) {
sum += a[i][j] * x[j];
}
for (j = i + 1; j < 9; j++) {
sum += a[i][j] * x[j];
}
x[i] += w * ((b[i] - sum) / a[i][i] - x[i]);
if (fabs(sum + a[i][i] * x[i] - b[i]) > tol) {
converged = 0;
}
}
} while (!converged);
``````
``````x = -0.007812
x = -0.015625
x = -0.007812
x = -0.015625
x = -0.046875
x = -0.015625
x = -0.007812
x = -0.015625
x = -0.007813

check = 0.000000
check = -0.000000
check = -0.000000
check = -0.000000
check = 2.000000
check = 0.000000
check = -0.000000
check = 0.000000
check = 0.000000
num=31
`````` ## Python library for Gauss-Seidel Iterative Solver?

By : user2943486
Date : March 29 2020, 07:55 AM
wish help you to fix your issue There is an example implementation where they go through various implementations here:
http://www.scipy.org/PerformancePython ## Gauss seidel method not working for specific input

By : Francisco Acuña Amay
Date : March 29 2020, 07:55 AM
I hope this helps you .
Though it can be applied to any matrix with non-zero elements on the diagonals, convergence is only guaranteed if the matrix is either diagonally dominant, or symmetric and positive definite.
code :
``````x=0.500006
x=0.333334
x=0.250001
`````` ## Improving Numpy speed for Gauss-Seidel (Jacobi) Solver

By : PrakashaShetty
Date : March 29 2020, 07:55 AM
it fixes the issue I've been able to reduce the running time in my laptop from 66 to 21 seconds by following this process:
code :
``````expr = "temp = cr*((1 - 1/(2*ri[1:nr,1:nz]))*v[0:nr-1,1:nz] + (1 + 1/(2*ri[1:nr,1:nz]))*v[2:nr+1,1:nz]) + cz*(v[1:nr,0:nz-1] + v[1:nr,2:nz+1]); v[1:nr,1:nz] = temp"
temp = np.empty((nr-1, nz-1))
...
while ...
weave.blitz(expr)
``````
``````from scipy import weave

# [...] Set up code till "# Gauss-Seidel solver"

tic = time.time()
max_v_diff = 1;
A = cr * (1 - 1/(2*ri[1:nr,1:nz]))
B = cr * (1 + 1/(2*ri[1:nr,1:nz]))
expr = "temp = A*v[0:nr-1,1:nz] + B*v[2:nr+1,1:nz] + cz*(v[1:nr,0:nz-1] + v[1:nr,2:nz+1]); v[1:nr,1:nz] = temp"
temp = np.empty((nr-1, nz-1))
while (max_v_diff > tol):
v_old = v.copy()
v[0,1:nz] = cr*2*v[1,1:nz] + cz*(v[0,0:nz-1] + v[0,2:nz+2])
weave.blitz(expr, check_size=0)
v[nr,1:nz] = cr*2*v[nr-1,1:nz] + cz*(v[nr,0:nz-1] + v[nr,2:nz+1])
# reapply grid potentials
v[31:,29:40] = 1000
v[19:,54:65] = -200
# check for convergence
v_diff = v - v_old
max_v_diff = np.absolute(v_diff).max()
toc = time.time() - tic
`````` ## Gauss-Seidel Solver for Python 2.7

By : Puspendra Chaurasiya
Date : March 29 2020, 07:55 AM
Hope this helps After a bit of searching around I found the solution was to use the numpy.linalg.solve command. The command uses the LAPACK gesv routine to solve the problem; however I am not sure what iterative technique this uses.
Here is the code to solve the problem if anyone is interested:
code :
``````a = np.array([[1,-3,1],[2,5,1],[-1,1,-2]])
b = np.array([10,4,-13])

x = np.linalg.solve(a, b)

print x

print np.allclose(np.dot(a, x), b)      # To check the solution is found
`````` ## Solving 1D Poisson Equation with Gauss Seidel Red Black

By : Santiago Galindo
Date : March 29 2020, 07:55 AM
Any of those help Watch out, I believe you are reading past the bounds of your V array during the black sweep:
code :
``````//black sweep
for(int j=2; j <= 10; j+=2)
{
V[j] = -0.5*(0.00001*Q[j]-V[j-1]-V[j+1]);
}
`````` 