1 year ago

#380773

test-img

Letting Lenin

Is there a way to transform a gauss-siedel method program into successive over relaxation?

This is what i have, I'm super new to this python coding.

Gauss-Seidel approx method

import numpy as np

def Gauss_Seidel(A, b, error_s):

        [m, n] = np.shape(A)
    
        U = np.triu(A, 1)
        Ld = np.tril(A)
    
        x = np.ones((m,1))
        error = np.ones((m,1))*100
        iter = 0
    
        while np.max(error) > error_s:
            iter += 1
            xn = np.dot(np.linalg.inv(Ld), (b - np.dot(U,x)))
            error = abs((xn-x)/xn)*100
            x = xn
    
        for i in range(m):
            print("x[%d] = %6.4f --- Error: %0.4f %%" % (i+1, x[i], error[i]))
        print("The method converged after %d iterations" % (iter))

tried changing this line but i feel like there is more that need to be done. xn = np.dot(np.linalg.inv(Ld), (b - np.dot(U,x)))

python

gaussian

0 Answers

Your Answer

Accepted video resources