by thomasahle · 3y ago · 0 comments
ax1^3 + bx1^2 + cx1 + d = y1
ax2^3 + bx2^2 + cx2 + d = y2
ax3^3 + bx3^2 + cx3 + d = y3
ax4^3 + bx4^2 + cx4 + d = y4
As a matrix: [x1^3 + x1^2 + x1 + 1] [a] = [y1]
[x2^3 + x2^2 + x2 + 1] [b] = [y2]
[x3^3 + x3^2 + x3 + 1] [c] = [y3]
[x4^3 + x4^2 + x4 + 1] [d] = [y4]
If the matrix is M, we just want to find M^(-1)y.I think hackers should know enough linear algebra to do that, without "having to go asking the maths gods".
[x1^3, x1^2, x1, 1] [a] = [y1]
[x2^3, x2^2, x2, 1] [b] = [y2]
[x3^3, x3^2, x3, 1] [c] = [y3]
[x4^3, x4^2, x4, 1] [d] = [y4]Also, OP was solving a degree four problem and wanted a closed form.
For better stability just use `x = np.linalg.solve(M, y)`, or whichever linear solver you expect to be fast.