Apology for this silly question. In the cubie function below (as from a school project), I am given the value for x and f(x) while coefficients a, b ,c and constant of d are unknown.
f(x)=ax^3+bx^2+cx+d
In such case, is there a way to find out a, b and c by using any python package? I found good amount of python tutorial for solving cubic function but they seem to mainly focus on solving x while a, b and c value are given.
Here is an approach via sympy, Python's symbolic math library.
As an example, we are trying to find the formula for the sum of the first
ntriangular numbers. The triangular numbers (formulan*(n+1)/2) are0, 1, 3, 6, 10, 15, 21, ..... The sums of the firstntriangular numbers are thus0, 1, 4, 10, 20, 35, 56, ....You can use more
x,fxpairs to check that a cubic formula suffices (this won't work with float values, as sympy needs exact symbolic equations).Also sympy's
interpolatecan be interesting. This calculates a polynomial through some given points. Such code could look like: