小编Tar*_*ras的帖子

连续过度松弛

这里我有一些 python 脚本,它使用 Gauss-Seidel 方法求解线性方程组:

\n\n
import numpy as np\n\nITERATION_LIMIT = 1000\n\n#system\nA = np.array([[15., -4., -3., 8.],\n          [-4., 10., -4., 2.],\n          [-3., -4., 10., 2.],\n          [8., 2., 2., 12.]\n          ])\n# vector b\nb = np.array([2., -12., -4., 6.])\n\nprint("System of equations:")\nfor i in range(A.shape[0]):\n    row = ["{0:3g}*x{1}".format(A[i, j], j + 1) for j in range(A.shape[1])]\n    print("[{0}] = [{1:3g}]".format(" + ".join(row), b[i]))\n\nx = np.zeros_like(b)\n\n\nfor it_count in range(1, ITERATION_LIMIT):\n    x_new = np.zeros_like(x)\n    print("Iteration {0}: {1}".format(it_count, x))\n    for i in range(A.shape[0]):\n        s1 = np.dot(A[i, :i], …
Run Code Online (Sandbox Code Playgroud)

python iteration numpy python-3.x

1
推荐指数
1
解决办法
1万
查看次数

标签 统计

iteration ×1

numpy ×1

python ×1

python-3.x ×1