• API
• FAQ
• Tools
• Archive
SHARE
TWEET

# lab3(CM) ver 1.0

allekco Nov 21st, 2019 101 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. import matplotlib.pyplot as plt
2.
3.
4. def Lagrange(x, lst_x=[], lst_y=[]):
5.     F = 0
6.     for k in range(6):
7.         mult = 1
8.         for i in range(6):
9.             if i != k:
10.                 mult = (x-lst_x[i])/(lst_x[k]-lst_x[i])*mult
11.         F += lst_y[k]*mult
12.     return(F)
13.
14.
15. lst_x = [1, 4, 8, 12, 16, 20]
16. lst_y = [5, 10, 10, 11, 10, 6]
17. lst_x_l = []
18. lst_y_l = []
19. x = 1       # начало отрезка
20. delta = 0.5
21. while x < 20:
22.     lst_x_l.append(x)
23.     lst_y_l.append(Lagrange(x, lst_x, lst_y))
24.     x += delta
25.
26. lst_x_l.append(20)      # концы отрезка хотим обязательно видеть на графике
27. lst_y_l.append(Lagrange(20, lst_x, lst_y))
28.
29. plt.plot(lst_x, lst_y, lst_x_l, lst_y_l)
30. plt.xticks(range(1, 22, 2))     # отметки на оси x от 1 до 21; шаг 2
31. plt.grid(linestyle='--', linewidth=0.5)
32. plt.title('Interpolation')
33. plt.xlabel('x')
34. plt.ylabel('f - исходная , F- полином Лагранжа')
35. plt.legend('fF', loc=4)
36. plt.show()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.
Not a member of Pastebin yet?