我通过使用numpy在python中进行部分旋转制作了高斯消去代码。
import numpy as np
A = np.array([[3, -13, 9, 3], [-6, 4, 1, -18], [6, -2, 2, 4], [12, -8, 6, 10]])
b = np.array([-19, -34, 16, 26])
def GaussEliminationPP(A, b):
n = len(A)
l = np.arange(n)
s = np.zeros(n)
for k in range(n) :
amax = 0
for i in range(k, n) :
a = np.abs(A[l[i],k])
if a > amax :
amax = a
j = i
l[j], l[k] = l[k], l[j]
for i in range(k+1, n) :
xmult = A[l[i],k]/A[l[k],k]
A[l[i],k] = xmult
for j in range(k+1, n):
A[l[i],j] -= xmult*A[l[k],j]
b[l[i]] -= xmult*A[l[k],j]
print(A, b)
GaussEliminationPP(A, b)
但是,我发现它在解决方案中具有不同的价值。而且我不知道我哪里错了。有人能帮忙吗?在此先感谢:)