W11 作业

9.1

import numpy as np
from scipy.linalg import toeplitz
def caculate_with_k(A,B,m,k):
	I = np.eye(m,m,0)
	return np.dot(A,B-k*I)
n = 200
m = 500
k = np.random.randn()
A = np.random.randn(n,m)
B = toeplitz(np.random.randn(1,m)
r=np.random.randn(1,m))
print(A+A)
print(np.dot(A,A.T))
print(np.dot(A.T,A))
print(np.dot(A,B))
print("k=",k)
print(caculate_with_k(A,B,m,k))

9.2

import numpy as np
from scipy.linalg import toeplitz
m = 500
B = toeplitz(np.random.randn(1,m), r=np.random.randn(1,m))
b = np.random.randn(m)
x = np.linalg.solve(B,b)
print(x)

9.3

import numpy as np
from scipy.linalg import toeplitz
n = 200
m = 500
A = np.random.randn(n,m)
B = toeplitz(np.random.randn(1,m), r=np.random.randn(1,m))
U,sigma,vt = np.linalg.svd(B)
print(np.linalg.norm(A,ord='fro'))
print(np.linalg.norm(B,ord=np.inf))
print(sigma.max())print(sigma.min())

9.5

import numpy as np
from scipy.linalg import toeplitz
n = np.random.randint(2,200)
p = np.random.rand()
print("n=",n)
print("p=",p)
C = np.random.binomial(1,p,(n,n))
e = np.linalg.eigvals(C)
print("largest singular value:",e.max())

你可能感兴趣的:(作业)