MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / main

Function main

maths/numerical_analysis/newton_forward_interpolation.py:23–53  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

21
22
23def main() -> None:
24 n = int(input("enter the numbers of values: "))
25 y: list[list[float]] = []
26 for _ in range(n):
27 y.append([])
28 for i in range(n):
29 for j in range(n):
30 y[i].append(j)
31 y[i][j] = 0
32
33 print("enter the values of parameters in a list: ")
34 x = list(map(int, input().split()))
35
36 print("enter the values of corresponding parameters: ")
37 for i in range(n):
38 y[i][0] = float(input())
39
40 value = int(input("enter the value to interpolate: "))
41 u = (value - x[0]) / (x[1] - x[0])
42
43 # for calculating forward difference table
44
45 for i in range(1, n):
46 for j in range(n - i):
47 y[j][i] = y[j + 1][i - 1] - y[j][i - 1]
48
49 summ = y[0][0]
50 for i in range(1, n):
51 summ += (ucal(u, i) * y[0][i]) / math.factorial(i)
52
53 print(f"the value at {value} is {summ}")
54
55
56if __name__ == "__main__":

Callers 1

Calls 3

ucalFunction · 0.85
splitMethod · 0.80
appendMethod · 0.45

Tested by

no test coverage detected