Approximation of points by a polynomial of arbitrary power
approximate
-
x: list
— coordinates of points on the x-axisy: list
— coordinates of points on the x-axisp: int
— power of the polynomial
-
polynomial_coefficients: list
The obtained coefficients are from the smallest to the largest power.
Example:
If you get these coefficients:[2.0, 3.0, 4.0]
This means that the polynom will look like this:
2x^0 + 3x^1 + 4x^2
-
len(x) == len(y)
must be True.
Else you will get an error!
-
create_polynom
-
polynomial_coefficients: list
coefficients of the polynom.
Obtained from theapproximate
-
- A polynom.
Example:4x^2 + 3x^1 + 2
- A polynom.
-
from approximation import create_polynom, approximate
if __name__ == "__main__":
print("Some example cases:")
x = [1, 2, 3]
y = [2, 5, 10]
p = 2
print(f"\nCase 1:\nx = {x},\ny = {y},\np = {p}\nPolynom: {create_polynom( approximate(x, y, p) )}")
x = [-2, -1, 0, 1, 2]
y = [0, 5, 0, 10, 4]
p = 4
print(f"\nCase 2:\nx = {x},\ny = {y},\np = {p}\nPolynom: {create_polynom( approximate(x, y, p) )}")
x = [-3, -2, -1, 0, 1, 2]
y = [-10, 0, 5, 0, 10, 4]
p = 5
print(f"\nCase 3:\nx = {x},\ny = {y},\np = {p}\nPolynom: {create_polynom( approximate(x, y, p) )}")