python-插值多项式,其中系数是矩阵
python-Interpolate polynomial where coefficients are matrices
我有以下形式的多项式:
p(y) = A + By + Cy^2 ... + Dy^n
这里,每个系数A,B,..,D
都是矩阵(因此p(y)
也是一个矩阵)。假设我在 n+1
点插入多项式。我现在应该可以解决这个系统了。我正在尝试在 Numpy 中执行此操作。我现在有以下代码:
a = np.vander([0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0,1.1,1.2]) #polynomial degree is 12, a -> (12x12)
b = np.random.rand(12,60,60) #p(x) is a 60x60 matrix that I have evaluated at 12 points
x = np.linalg.solve(a,b)
我收到以下错误:
ValueError: solve: Input operand 1 has a mismatch in its core dimension 0, with gufunc signature (m,m),(m,n)->(m,n) (size 60 is different from 12)
如何在 Numpy 中解决此系统以获得 x
?有通用的数学技巧吗?
本质上,您只是在进行 3600 个 12d 多项式回归并将系数组成矩阵。例如,组件 p(y)[0,0]
就是:
p(y)[0, 0] = A[0, 0] + B[0, 0] * y + C[0, 0] * y**2 ... + D[0, 0] * y**n
问题是np.linalg.solve
只能取一维的系数。但是由于你的矩阵元素都是独立的(y
是标量),你可以 ravel
它们并且你可以用 (m,m),(m,n**2) -> (m,n**2)
的形式进行计算并重塑回矩阵。所以尝试:
a = np.vander([0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0,1.1,1.2]) #polynomial degree is 12, a -> (12x12)
b = np.random.rand(12,60,60) #p(x) is a 60x60 matrix that I have evaluated at 12 points
s = b.shape
x = np.linalg.solve(a, b.reshape(s[0], -1))
x = x.reshape(s)
我有以下形式的多项式:
p(y) = A + By + Cy^2 ... + Dy^n
这里,每个系数A,B,..,D
都是矩阵(因此p(y)
也是一个矩阵)。假设我在 n+1
点插入多项式。我现在应该可以解决这个系统了。我正在尝试在 Numpy 中执行此操作。我现在有以下代码:
a = np.vander([0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0,1.1,1.2]) #polynomial degree is 12, a -> (12x12)
b = np.random.rand(12,60,60) #p(x) is a 60x60 matrix that I have evaluated at 12 points
x = np.linalg.solve(a,b)
我收到以下错误:
ValueError: solve: Input operand 1 has a mismatch in its core dimension 0, with gufunc signature (m,m),(m,n)->(m,n) (size 60 is different from 12)
如何在 Numpy 中解决此系统以获得 x
?有通用的数学技巧吗?
本质上,您只是在进行 3600 个 12d 多项式回归并将系数组成矩阵。例如,组件 p(y)[0,0]
就是:
p(y)[0, 0] = A[0, 0] + B[0, 0] * y + C[0, 0] * y**2 ... + D[0, 0] * y**n
问题是np.linalg.solve
只能取一维的系数。但是由于你的矩阵元素都是独立的(y
是标量),你可以 ravel
它们并且你可以用 (m,m),(m,n**2) -> (m,n**2)
的形式进行计算并重塑回矩阵。所以尝试:
a = np.vander([0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0,1.1,1.2]) #polynomial degree is 12, a -> (12x12)
b = np.random.rand(12,60,60) #p(x) is a 60x60 matrix that I have evaluated at 12 points
s = b.shape
x = np.linalg.solve(a, b.reshape(s[0], -1))
x = x.reshape(s)