【发布时间】:2020-03-04 16:24:09
【问题描述】:
当我计算 Vandermonde 时,我得到了正确的答案
这个矩阵的系数。但是,输出矩阵是相反的。
它应该是[6,-39,55,27] 而不是[27,55,-39,6]。
我的 Vandermonde 矩阵的输出被翻转,最终解决方案 c,被翻转了。
import numpy as np
from numpy import linalg as LA
x = np.array([[4],[2],[0],[-1]])
f = np.array([[7],[29],[27],[-73]])
def main():
A_matrix = VandermondeMatrix(x)
print(A_matrix)
c = LA.solve(A_matrix,f) #coefficients of Vandermonde Polynomial
print(c)
def VandermondeMatrix(x):
n = len(x)
A = np.zeros((n, n))
exponent = np.array(range(0,n))
for j in range(n):
A[j, :] = x[j]**exponent
return A
if __name__ == "__main__":
main()
【问题讨论】:
标签: python python-3.x numpy math matrix