Inverse power method applied to a tridiagonal matrix in Python,inversetridiagonal,''' lam,x =
文章由Byrx.net分享于2019-03-23 08:03:56
Inverse power method applied to a tridiagonal matrix in Python,inversetridiagonal,''' lam,x =
''' lam,x = inversePower3(d,c,s,tol=1.0e-6). Inverse power method applied to a tridiagonal matrix [A] = [c\d\c]. Returns the eigenvalue closest to 's' and the corresponding eigenvector.'''from numpy import dot,zerosfrom LUdecomp3 import *from math import sqrtfrom random import randomdef inversePower3(d,c,s,tol=1.0e-6): n = len(d) e = c.copy() cc = c.copy() # Save original [c] dStar = d - s # Form [A*] = [A] - s[I] LUdecomp3(cc,dStar,e) # Decompose [A*] x = zeros(n) for i in range(n): # Seed [x] with random numbers x[i] = random() xMag = sqrt(dot(x,x)) # Normalize [x] x =x/xMag flag = 0 for i in range(30): # Begin iterations xOld = x.copy() # Save current [x] LUsolve3(cc,dStar,e,x) # Solve [A*][x] = [xOld] xMag = sqrt(dot(x,x)) # Normalize [x] x = x/xMag if dot(xOld,x) < 0.0: # Detect change in sign of [x] sign = -1.0 x = -x else: sign = 1.0 if sqrt(dot(xOld - x,xOld - x)) < tol: return s + sign/xMag,x print 'Inverse power method did not converge'
相关内容
- 把图片列表合成一个GIF动画图片,图片列表gif动画,[P
- 用Python写个翻译工具,Python写翻译工具,[Python]代码
- python中使用sharp模块的简单范例,pythonsharp,from shapes
- 输入地名获得当地天气预报,地名当地天气预报,weath
- python根据月份和日得到星座,python星座,#计算星座def
- python获取图片的颜色信息,,image = Imag
- python中使用sorted函数对列表进行排序,pythonsorted,#创建
- 使用python获取糗百图片,,from sgmllib
- python使用smtplib模块通过gmail发送邮件,pythonsmtplib,impo
- python编写的一个简单那的WSGI PDF server,pythonwsgi,# basic
评论关闭