Skip to content
Snippets Groups Projects
Commit 73426291 authored by Djokzer's avatar Djokzer
Browse files

Still don't work

parent 8d576ff9
No related branches found
No related tags found
1 merge request!10Resolve "Create Lagrange method"
# Created on 09/12/2021
from polynome import *
from inverse_mult import *
def get_possibilities(l: list):
pass
def lagrange_compute(l: list) -> polynome:
list_s = [0] * len(l)
list_p = [1] * 2 + [0] * (len(l)-2)
list_p = [0] * len(l)
sum_poly = polynome(list_s)
product_poly = polynome(list_p)
#product_poly = polynome(list_p)
first_time = True
for x_i, y_i in enumerate(l):
for x_j, y_j in enumerate(l):
if x_j != x_i:
product_poly = product_poly.mul(polynome([(y_i * (0-x_j)) /(x_i - x_j) , y_i / (x_i - x_j)]))
#product_poly.show()
list_p[0] = -x_j / (x_i - x_j)
list_p[1] = 1 / (x_i - x_j)
if first_time:
product_poly = polynome(list_p)
first_time = False
else:
product_poly = product_poly.mul(polynome(list_p))
product_poly.show()
first_time = True
sum_poly = sum_poly.add(product_poly)
#sum_poly.show()
product_poly = polynome(list_p)
sum_poly.show()
list_p = [0] * len(l)
return sum_poly
def check_nb_error(l: list, p: polynome) -> int:
......@@ -25,7 +34,7 @@ def check_nb_error(l: list, p: polynome) -> int:
if __name__ == '__main__':
list_ = [1, 2, 3]
print(list_)
#print(list_)
poly = lagrange_compute(list_)
poly.show()
#print(poly.evaluate(0))
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment