求矩阵范数

import numpy as np

m = np.array([
    [2,-2,-3],
    [0, 5, 1],
    [0, 0, -7]
])

print(np.linalg.norm(m, ord=1))
print(np.linalg.norm(m, ord=2))
print(np.linalg.norm(m, ord=np.inf))

迭代法解线性方程组

def f(x):
    x1, x2, x3 = x[0], x[1], x[2]
    xx1 = (1/5) * x2 + (1/10) * x3 + (3/10)
    xx2 = (1/5) * x1 + (1/10) * x3 + (3/2)
    xx3 = (1/5) * x1 + (2/5) * x2 + 2
    return (xx1, xx2, xx3)

x = (0, 0, 0)

def d(a, b):
    return max(
        abs(a[0] - b[0]),
        abs(a[1] - b[1]),
        abs(a[2] - b[2])
    )

for _ in range(10):
    xx = f(x)
    print(xx, d(xx, x))
    x = xx
Last modification:May 14th, 2020 at 12:42 pm
 Support
如果觉得我的文章对你有用,请随意赞赏