added lagrange polynom calculation
This commit is contained in:
parent
8adb0fcbe1
commit
61ad1fefef
|
@ -0,0 +1,24 @@
|
|||
|
||||
def lagrange_polynom(points, j):
|
||||
nom = ""
|
||||
dem = 1
|
||||
xj = points[j][0]
|
||||
for u in range(len(points)):
|
||||
if u == j:
|
||||
continue
|
||||
nom += f"(x - {points[u][0]})"
|
||||
dem *= xj - points[u][0]
|
||||
return (nom, dem)
|
||||
|
||||
def interpolate_lagrange(points):
|
||||
n = len(points)
|
||||
poly = ""
|
||||
for i in range(n):
|
||||
(lagrange, dem) = lagrange_polynom(points, i)
|
||||
poly += f" + {points[i][1]*dem}*{lagrange}"
|
||||
return poly
|
||||
|
||||
def test():
|
||||
points = [[1,2], [3,5], [4,-1]]
|
||||
print(f"polynom via lagrange: {interpolate_lagrange(points)}")
|
||||
|
2
main.py
2
main.py
|
@ -15,6 +15,7 @@
|
|||
# Copyright (c) Sven Vogel
|
||||
|
||||
import fixpoint_approximation
|
||||
import lagrange
|
||||
import linear_approximation
|
||||
import matrix
|
||||
import newton_polynom
|
||||
|
@ -30,3 +31,4 @@ if __name__ == '__main__':
|
|||
matrix.test()
|
||||
taylor_sine_approx.test()
|
||||
integral_approximation.test()
|
||||
lagrange.test()
|
||||
|
|
Loading…
Reference in New Issue