Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from itertools import zip_longest
- dot = [0, 1, 2, 3]
- f = [8, 9, 16, 43]
- rr = []
- res = [[8, 9, 16, 43]]
- raz = 0
- for i in range(len(f) - 1):
- rri = []
- if i == 0:
- raz += 1
- for x in range(len(f) - 1):
- rri.append((f[x + 1] - f[x]) / (dot[x + raz] - dot[x]))
- else:
- raz += 1
- for x in range(len(rr[i - 1]) - 1):
- rri.append((rr[i - 1][x + 1] - rr[i - 1][x]) / (dot[x + raz] - dot[x]))
- res.append(rri)
- rr.append(rri)
- for i, row in enumerate(zip_longest(*res, fillvalue="")):
- formatted_row = " - ".join(str(round(x, 3)) if isinstance(x, float) else str(x) for x in row)
- print(f"f{i}: {formatted_row} ")
- print()
- dots = [0, 0.5, 1, 1.5, 2, 2.5, 3]
- for x in range(len(dots)):
- ressum = res[0][0]
- product_term = 1.0
- for i in range(1, len(dot)):
- product_term *= (dots[x] - dot[i - 1])
- ressum += res[i][0] * product_term
- print(f"P({dots[x]}): {ressum}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement