将旋转添加到以下高斯消除代码

时间:2014-02-27 02:36:36

标签: python-3.x numpy pivot

以下程序使用高斯消除而无需旋转。我想知道如何将旋转添加到此代码中以考虑前导项为零的数组

from numpy import array,empty

A = array([[ 2, 1, 4, 1 ],
       [ 3, 4,-1,-1 ],
       [ 1, -4, 1, 5],
       [2,-2,1,3]],float)

v = array([ -4,3,9,7 ], float)
N = len(v)

for m in range (N):
    div = A[m,m]
    A[m,:] /= div
    v[m] /= div

for i in range(m+1,N):
    mult = A[i,m]
    A[i,:] -= mult*A[m,:]
    v[i] -= mult*v[m]

x = empty(N,float)
for m in range(N-1,-1,-1):
    x[m] = v[m]
    for i in range(m+1,N):
       x[m] -= A[m,i]*x[i]

我想要解决的新数组是

A = array([[ 0, 1, 4, 1 ],
       [ 3, 4,-1,-1 ],
       [ 1, -4, 1, 5],
       [2,-2,1,3]],float)

0 个答案:

没有答案