We already have a challenge for polynomial interpolation: given a list of points, output the coefficients of the polynomial that passes through them.
Hermite interpolation is a generalization of polynomial interpolation. Instead of just specifying the points that the polynomial passes through, we also specify the higher-order derivatives at those points. If we have \$n\$ points, and we specify the value and the first \$m-1\$ derivatives at each point, then we can uniquely determine a polynomial of degree less than \$mn\$.
For example, the following data uniquely determines the polynomial \$x^8+1\$:
\$x\$ | \$y=x^8+1\$ | \$y'=8x^7\$ | \$y''=56x^6\$ |
---|---|---|---|
0 | 1 | 0 | 0 |
1 | 2 | 8 | 56 |
2 | 257 | 1024 | 3584 |
Task
Given an \$m \times n\$ matrix \$\mathbf{A}=(a_{ij})_{1\leq i\leq m, \; 1\leq j\leq n}\$, find a polynomial \$p\$ of degree less than \$mn\$ such that \$p^{(i)}(j) = a_{i+1,j+1}\$ for all \$0 \leq i < m\$ and \$0 \leq j < n\$. Here \$p^{(i)}(j)\$ denotes the \$i\$th derivative of \$p\$ evaluated at \$j\$.
For example, if \$\mathbf{A}=\begin{bmatrix}1&0&0\\2&8&56\\257&1024&3584\end{bmatrix}\$, then \$p(x)=x^8+1\$.
You may take input and output in any convenient format.
You may transpose the input matrix if you wish. You may flatten it into a list. You may take \$m\$ or \$n\$ or both as additional inputs.
Here are some example formats for the output polynomial:
- a list of coefficients, in descending order, e.g. \$24 x^4 + 96 x^3 + 72 x^2 + 16 x + 1\$ is represented as
[24,96,72,16,1]
; - a list of coefficients, in ascending order, e.g. \$24 x^4 + 96 x^3 + 72 x^2 + 16 x + 1\$ is represented as
[1,16,72,96,24]
; - taking an additional input \$k\$ and outputting the coefficient of \$x^k\$;
- a built-in polynomial object.
When the degree of the polynomial is less than \$mn-1\$, you may pad the coefficient list with zeros.
When the coefficients are not integers, you may output them as rational numbers, floating-point numbers, or any other convenient format.
This is code-golf, so the shortest code in bytes in each language wins.
Test Cases
Here I output lists of coefficients in descending order.
[[1,0,0],[1,0,0]] -> [1]
[[1,2],[0,0]] -> [4,-7,2,1]
[[1,2],[3,4]] -> [2,-2,2,1]
[[0,0,1],[3,11,33]] -> [1,1/2,1,1/2,0,0]
[[1,2],[3,4],[5,6]] -> [3,-14,21,-10,2,1]
[[1,2,3],[4,5,6]] -> [-3/2,9/2,-7/2,3/2,2,1]
[[1,16],[209,544],[1473,2224]] -> [24,96,72,16,1]
[[0,0,0],[0,1,0],[0,0,0]] -> [-1,7,-18,20,-8,0,0,0]
[[1,0,0],[2,8,56],[257,1024,3584]] -> [1,0,0,0,0,0,0,0,1]
[[1,0,0],[0,0,0],[0,0,0]] -> [3/2,-207/16,713/16,-1233/16,1083/16,-99/4,0,0,1]