logo
down
shadow

Gauss Seidel (Specific equation solver) in 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] = -0.007812 
x[1] = -0.015625 
x[2] = -0.007812 
x[3] = -0.015625 
x[4] = -0.046875 
x[5] = -0.015625 
x[6] = -0.007812 
x[7] = -0.015625 
x[8] = -0.007813 


check[0] = 0.000000
check[1] = -0.000000
check[2] = -0.000000
check[3] = -0.000000
check[4] = 2.000000
check[5] = 0.000000
check[6] = -0.000000
check[7] = 0.000000
check[8] = 0.000000
num=31


Share : facebook icon twitter icon
Python library for Gauss-Seidel Iterative Solver?

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

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]=0.500006
x[1]=0.333334
x[2]=0.250001
Improving Numpy speed for Gauss-Seidel (Jacobi) Solver

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 ...
    # internal updates
    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()
    # left boundary updates
    v[0,1:nz] = cr*2*v[1,1:nz] + cz*(v[0,0:nz-1] + v[0,2:nz+2])
    # internal updates
    weave.blitz(expr, check_size=0)
    # right boundary updates
    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

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

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]);
}
Related Posts Related Posts :
  • Program works but outputs trailing garbage values
  • Letting 2 pointer pointing to same address
  • Different ways to print the two-dimensional array's contents
  • C Programming : Confusion between operator precedence
  • C code inside a loop not being executed
  • C - Weird symbols
  • C - Get pointer adress to string
  • how to start a function using a Struct?
  • Trying to tweak sscanf() to ignore \n and \t
  • How to find the inverse of a Rectangular Matrix in C using GSL
  • sizeof() showing different output
  • How to select/read/copy values after specific character in a string
  • Jump from bootloader generates exception
  • Array dropping values, picks up garbage
  • Swig: Syntax error in input(3)
  • multiple definition and making sure function is correctly written
  • MD4 openssl core dumped
  • Undefined-Behavior at its best, is it -boundary break? -bad pointer arithmetic? Or just -ignore of aliasing?
  • Why am i getting problem3.c:20:23: error: expected expression before ‘int’?
  • Right Justified Zero filled String in C
  • C Function with parameter without type indicator still works?
  • How to transmit data from an interrupt handler to an user application?
  • Why do I get the error "bash: ./a.out: Permission denied" when I execute a C program in Linux mint 15
  • syntax of sigchld and its declaration
  • error using g_idle_add() in C++, same thing works in C
  • why if else or nested if else are called single statement in C
  • How do I interpret this printf in C
  • load the functions of a shell script without executing it
  • Is FilterSendNetBufferLists handler a must for an NDIS filter to use NdisFSendNetBufferLists?
  • How to write to flash memory using inline assembly?
  • More Return Statements vs. More Indentation
  • How to show an image on a PictureBox from resource?
  • Having malloced some memory,I could't calculator the proper size of the memories I malloced.I don't know why
  • What is the main difference between integer pointer and character pointer?
  • Why are some functions declared extern and header file not included in source in Git source code?
  • what is the use of fflush(stdin) in c programming
  • Is it safe to return file File descriptor locally allocated from another function In C
  • Changing undefined values of an array
  • What does an empty parameter list mean?
  • using strtol on a string literal causing segmentation fault
  • Same structure objects memory overlap?
  • C-Linux-Any way to pass command "history" to Linux shell?
  • Using #define in defining string size C
  • How to use thread pool and message queues in Multithreaded Matrix Multiplication?
  • Can't find how to select path to run a C program
  • Automatic variable in C not initialized but given fixed value within loop
  • main() function defined without return type gives warning
  • Output of following code with integer, float, char variable
  • why buffer memory allocation error in opencl
  • Why am I getting this error during run-time?
  • Strange behaviour of the pow function
  • task in increment , decrement , printf() , why these are evaluated in this manner in C
  • 28 extra bytes in bss
  • Waiting for multiple events without polling
  • Why are my variables reporting as "undeclared identifier" when compiling?
  • Correct AddNode function but somehing happens when I printf
  • When I traverse in the splay tree, then now which one is root?
  • Data type conversion in Postfix evaluation
  • No output in terminal (Head First C)
  • Data writes over after realloc
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org