2024年Python最新Python实现Gauss-Seider迭代法(超全)

def matvec(A,v):

M,N = A.shape

if N != M:

print(“Matrix is not square”)

return -1

N1 = v.shape[0]

if N1 != M:

print("The dimension of matrix and vector is not reasonable ")

result = np.zeros((N1,1),dtype = np.float32)

for i in range(N):

for j in range(N):

result[i] += A[i,j]*v[j]

return result

def product(v1,v2):

result = 0

M,N = v1.shape[0],v2.shape[0]

if N != M:

print(“The dimension of vectors is not reasonable”)

exit(1)

for i in range(M):

result += v1[i]*v2[i]

return result

def vecnorm2(v1):

N = v1.shape[0]

result = 0

for i in range(N):

result += v1[i]*v1[i]

result = np.sqrt(result)

return result

def cgsolver(A,b,x0,maxit:int,tol=1.0e-8):

if tol < 0:

print(“argument tol is not good (negitive)”)

if maxit <= 0:

maxit

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值