美文网首页
Gauss-Seidel Method

Gauss-Seidel Method

作者: 平平又无奇 | 来源:发表于2018-04-28 13:55 被阅读10次

原文地址1
原文地址2
YouTube

import numpy as np
from scipy.linalg import solve

def gauss(A, b, x, n):

    L = np.tril(A)
    U = A - L
    for i in range(n):
        x = np.dot(np.linalg.inv(L), b - np.dot(U, x))
        print str(i).zfill(3),
        print(x)
    return x

'''___MAIN___'''

A = np.array([[4.0, -2.0, 1.0], [1.0, -3.0, 2.0], [-1.0, 2.0, 6.0]])
b = [1.0, 2.0, 3.0]
x = [1, 1, 1]

n = 20

print gauss(A, b, x, n)
print solve(A, b)

相关文章

网友评论

      本文标题:Gauss-Seidel Method

      本文链接:https://www.haomeiwen.com/subject/nesrmxtx.html