赞
踩
>>> import numpy as np
>>> a = [1,20,300,4000]
>>> b = np.arr[a[n:]+a[:n] for n in range(4)]
>>> sol = np.linalg.solve(b[1:,1:],-b[1:,0])
>>> print "Using last N equations the solution is:", [1.0]+list(sol)
Using last N equations the solution is: [1.0, -0.11111111111111105, -0.11111111111111113, -1.2222222222222223]
>>> print "Substituting in first equation gives:", a[0]+sol.dot(a[1:]), "= 0"
Substituting in first equation gives: -4.44444444444 = 0
>>>
在这一点上,您的程序可以决定残差是太多还是解决方案足够好。在
如果解决方案足够好,也许你想用
^{pr2}$
对另一个元素的解的性质给出了一个重要的注记>>> print np.linspace.lstsq.__doc__
了解整个故事。在
关于效率,当你要解一个大的方程组(NxN,几乎…)时,你不介意你可以用一个简单的数值解来构建系数矩阵。在
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。