Mod。克施密特python3

时间:2018-06-30 21:01:23

标签: python-3.x

我正在尝试编写一个以矩阵为参数的代码,并使用修改后的Gram Schmidt算法计算并打印QR因式分解。我需要使用for循环编写代码,而根本不使用NUMPY。在这一点上,我坚持计算q [i]。我是python 3编码的新手,将不胜感激。先感谢您。我的代码附在下面。

def twoNorm(vector):
    inputStatues = True
    for i in range(len(vector)):
        if((type(vector[i]) != int) and (type(vector[i]) != float) and (type(vector[i]) != complex)):
            inputStatus = False
            print("Invalid Input")
    if inputStatus == True:
        result = 0
        for i in range(len(vector)):
            result = result + (vector[i]**2)
        result = result**(1/2)
        return result
vector = [1, 0,1]
print(twoNorm(vector))

def QR(matrix):
    r[i][i] = twoNorm(vector)
    q[i] = 0
    for i in range(len(matrix)):
        q[i] = q[i] + vector[i] * (1/(twoNorm(vector))
    return q[i]
matrix = [[1, 2], [0, 1], [1, 0]]

0 个答案:

没有答案