我试着取一个365x365矩阵的逆矩阵。有些值会变大到365**365,因此它们被转换为长数字。我不知道linalg.matrix_power()
函数是否可以处理长数字。我知道问题就来自于此(因为错误消息和我的程序对较小的矩阵工作得很好),但我不确定是否有办法解决这个问题。代码需要为NxN矩阵工作。在
我的代码是:
item=0
for i in xlist:
xtotal.append(arrayit.arrayit(xlist[item],len(xlist)))
item=item+1
print xtotal
xinverted=numpy.linalg.matrix_power(xtotal,-1)
coeff=numpy.dot(xinverted,ylist)
arrayit.arrayit
:
这个程序从一个列表(x的列表和y的列表)中获取x,y坐标并生成一个函数。 谢谢!在
你听说过拉格朗日插值法或牛顿插值法吗?这将避免整个范德蒙矩阵的构建。但不是系数中潜在的大数。在
一般来说,你不需要逆矩阵。你不需要计算它。你想要的是解一组线性方程组。在
解决系统
A*x=b
。在你(真的)可能想查一下伦格效应。等间距采样点插值是一个日益病态的任务。对于更大的单数阶多项式,可以得到非常有用的结果。在
你可以经常使用多项式回归,也就是说,用某个低阶的最佳多项式来近似你的数据集。在
您可以尝试使用库mpmath,它可以对任意精度的数字进行简单的矩阵代数和其他类似的问题。在
几个注意事项:它几乎肯定比使用numpy慢,而且,正如Lutzl在his answer to this question中指出的那样,这个问题很可能在数学上没有很好的定义。另外,你需要在开始之前决定你想要的精度。在
一些简单的示例代码
我怀疑你真正的问题是数学而不是软件,所以我怀疑这对你是否有效,但它总是有可能的!在
相关问题 更多 >
编程相关推荐